Description

Ftrl predictor receive two stream : model stream and data stream. It using updated model by model stream real-time, and using the newest model predict data stream.

Parameters

Name Description Type Required? Default Value
vectorCol Name of a vector column String null
reservedCols Names of the columns to be retained in the output table String[] null
predictionCol Column name of prediction. String
predictionDetailCol Column name of prediction result, it will include detailed info. String

Script Example

Script

  1. data = np.array([
  2. [2, 1, 1],
  3. [3, 2, 1],
  4. [4, 3, 2],
  5. [2, 4, 1],
  6. [2, 2, 1],
  7. [4, 3, 2],
  8. [1, 2, 1],
  9. [5, 3, 2]])
  10. df = pd.DataFrame({"f0": data[:, 0],
  11. "f1": data[:, 1],
  12. "label": data[:, 2]})
  13. batchData = dataframeToOperator(df, schemaStr='f0 int, f1 int, label int', op_type='batch')
  14. streamData = dataframeToOperator(df, schemaStr='f0 int, f1 int, label int', op_type='stream')
  15. model = LogisticRegressionTrainBatchOp() \
  16. .setFeatureCols(["f0", "f1"]) \
  17. .setLabelCol("label") \
  18. .setMaxIter(5).linkFrom(batchData);
  19. models = FtrlTrainStreamOp(model) \
  20. .setFeatureCols(["f0", "f1"]) \
  21. .setLabelCol("label") \
  22. .setTimeInterval(1) \
  23. .setAlpha(0.1) \
  24. .setBeta(0.1) \
  25. .setL1(0.1) \
  26. .setL2(0.1).setVectorSize(2).setWithIntercept(True) \
  27. .linkFrom(streamData);
  28. FtrlPredictStreamOp(model) \
  29. .setPredictionCol("pred") \
  30. .setReservedCols(["label"]) \
  31. .setPredictionDetailCol("details") \
  32. .linkFrom(models, streamData).print()
  33. StreamOperator.execute()

Result

  1. label pred details
  2. 1 1 {"1":"0.9999917437501057","2":"8.2562498943117...
  3. 1 1 {"1":"0.965917838185468","2":"0.03408216181453...
  4. 2 2 {"1":"0.00658782416074899","2":"0.993412175839...
  5. 1 1 {"1":"0.9810760570397847","2":"0.0189239429602...
  6. 1 1 {"1":"0.9998904582473768","2":"1.0954175262323...
  7. 2 2 {"1":"0.00658782416074899","2":"0.993412175839...
  8. 1 1 {"1":"0.9999996598523875","2":"3.4014761252088...
  9. 2 2 {"1":"2.0589409516880153E-5","2":"0.9999794105...

```