- 功能介绍
- 参数说明
- 脚本示例
- 脚本代码
- 脚本运行结果
功能介绍
基于StringIndexer模型,将一列整数映射为字符串。
参数说明
| 名称 | 中文名称 | 描述 | 类型 | 是否必须? | 默认值 | |
|---|---|---|---|---|---|---|
| modelName | 模型名字 | 模型名字 | String | ✓ | ||
| selectedCol | 选中的列名 | 计算列对应的列名 | String | ✓ | ||
| reservedCols | 算法保留列名 | 算法保留列 | String[] | null | ||
| outputCol | 输出结果列 | 输出结果列列名,可选,默认null | String | null |
脚本示例
脚本代码
data = np.array([["football"],["football"],["football"],["basketball"],["basketball"],["tennis"],])df_data = pd.DataFrame({"f0": data[:, 0],})data = dataframeToOperator(df_data, schemaStr='f0 string', op_type="batch")stringIndexer = StringIndexerTrainBatchOp() \.setModelName("string_indexer_model") \.setSelectedCol("f0") \.setStringOrderType("frequency_asc")model = stringIndexer.linkFrom(data)string2int = StringIndexerPredictBatchOp() \.setSelectedCol("f0").setOutputCol("f0_indexed")indexed = string2int.linkFrom(model, data)predictor = IndexToStringPredictBatchOp().setSelectedCol("f0_indexed").setOutputCol("f0_indxed_unindexed");predictor.linkFrom(model, indexed).print()
脚本运行结果
f0|f0_indexed|f0_indxed_unindexed--|----------|-------------------football|2|footballfootball|2|footballfootball|2|footballbasketball|1|basketballbasketball|1|basketballtennis|0|tennis
