• 逻辑回归流预测
    • 功能介绍
    • 算法参数
    • 脚本示例
      • 运行脚本
      • 运行结果

    逻辑回归流预测

    功能介绍

    逻辑回归预测组件,读取数据和模型,对数据流进行预测

    算法参数

    名称 中文名称 描述 类型 是否必须? 默认值
    vectorCol 向量列名 向量列对应的列名,默认值是null String null
    predictionCol 预测结果列名 预测结果列名 String
    predictionDetailCol 预测详细信息列名 预测详细信息列名 String
    reservedCols 算法保留列名 算法保留列 String[] null

    脚本示例

    运行脚本

    1. import numpy as np
    2. import pandas as pd
    3. data = np.array([
    4. [2, 1, 1],
    5. [3, 2, 1],
    6. [4, 3, 2],
    7. [2, 4, 1],
    8. [2, 2, 1],
    9. [4, 3, 2],
    10. [1, 2, 1],
    11. [5, 3, 2]])
    12. df = pd.DataFrame({"f0": data[:, 0],
    13. "f1": data[:, 1],
    14. "label": data[:, 2]})
    15. streamData = dataframeToOperator(df, schemaStr='f0 int, f1 int, label int', op_type='stream')
    16. batchData = dataframeToOperator(df, schemaStr='f0 int, f1 int, label int', op_type='batch')
    17. dataTest = streamData
    18. colnames = ["f0","f1"]
    19. lr = LogisticRegressionTrainBatchOp().setFeatureCols(colnames).setLabelCol("label")
    20. model = batchData.link(lr)
    21. predictor = LogisticRegressionPredictStreamOp(model).setPredictionCol("pred")
    22. predictor.linkFrom(dataTest).print()
    23. StreamOperator.execute()

    运行结果

    f0 f1 label pred
    2 1 1 1
    3 2 1 1
    4 3 2 2
    2 4 1 1
    2 2 1 1
    4 3 2 2
    1 2 1 1
    5 3 2 2