- QuantileDiscretizer批预测
- 功能介绍
- 参数说明
- 脚本示例
- 脚本代码
- 脚本结果
QuantileDiscretizer批预测
功能介绍
分位点离散可以计算选定列的分位点,然后使用这些分位点进行离散化。生成选中列对应的q-quantile,其中可以所有列指定一个,也可以每一列对应一个
参数说明
| 名称 | 中文名称 | 描述 | 类型 | 是否必须? | 默认值 | |
|---|---|---|---|---|---|---|
| selectedCols | 选择的列名 | 计算列对应的列名列表 | String[] | ✓ | ||
| reservedCols | 算法保留列名 | 算法保留列 | String[] | null | ||
| outputCols | 输出结果列列名数组 | 输出结果列列名数组,可选,默认null | String[] | null |
脚本示例
脚本代码
import numpy as npimport pandas as pdfrom pyalink.alink import *def exampleData():return np.array([["a", 1, 1, 2.0, True],["c", 1, 2, -3.0, True],["a", 2, 2, 2.0, False],["c", 0, 0, 0.0, False]])def sourceFrame():data = exampleData()return pd.DataFrame({"f_string": data[:, 0],"f_long": data[:, 1],"f_int": data[:, 2],"f_double": data[:, 3],"f_boolean": data[:, 4]})def batchSource():return dataframeToOperator(sourceFrame(),schemaStr='''f_string string,f_long long,f_int int,f_double double,f_boolean boolean''',op_type='batch')def streamSource():return dataframeToOperator(sourceFrame(),schemaStr='''f_string string,f_long long,f_int int,f_double double,f_boolean boolean''',op_type='stream')trainOp = (QuantileDiscretizerTrainBatchOp().setSelectedCols(['f_double']).setNumBuckets(8))predictBatchOp = (QuantileDiscretizerPredictBatchOp().setSelectedCols(['f_double']))(predictBatchOp.linkFrom(batchSource().link(trainOp),batchSource()).print())predictStreamOp = (QuantileDiscretizerPredictStreamOp(batchSource().link(trainOp)).setSelectedCols(['f_double']))(predictStreamOp.linkFrom(streamSource()).print())StreamOperator.execute()
脚本结果
f_string f_long f_int f_double f_boolean0 a 1 1 2 True1 c 1 2 0 True2 a 2 2 2 False3 c 0 0 1 False
