Description

Ftrl algorithm receive train data streams, using the training samples to update model element by element, and output model after every time interval.

Parameters

Name Description Type Required? Default Value
labelCol Name of the label column in the input table String
vectorCol Name of a vector column String null
vectorSize vector size of embedding Integer
featureCols Names of the feature columns used for training in the input table String[] null
withIntercept Whether has intercept or not, default is true Boolean true
timeInterval time interval Integer 1800
l1 the L1-regularized parameter. Double 0.0
l2 the L2-regularized parameter. Double 0.0
alpha alpha Double 0.1
beta beta Double 1.0

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...