Description

Linear svm predict batch operator. this operator predict data’s label with linear model.

Parameters

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

Script Example

Script

  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. input = dataframeToOperator(df, schemaStr='f0 int, f1 int, label int', op_type='batch')
  16. dataTest = input
  17. colnames = ["f0","f1"]
  18. svm = LinearSvmTrainBatchOp().setFeatureCols(colnames).setLabelCol("label")
  19. model = input.link(svm)
  20. predictor = LinearSvmPredictBatchOp().setPredictionCol("pred")
  21. predictor.linkFrom(model, dataTest).print()

Result

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