Description
Train a regression model with L1-regularization.
Parameters
Name |
Description |
Type |
Required? |
Default Value |
optimMethod |
optimization method |
String |
|
null |
lambda |
punish factor. |
Double |
✓ |
|
withIntercept |
Whether has intercept or not, default is true |
Boolean |
|
true |
maxIter |
Maximum iterations, The default value is 100 |
Integer |
|
100 |
epsilon |
Convergence tolerance for iterative algorithms (>= 0), The default value is 1.0e-06 |
Double |
|
1.0E-6 |
featureCols |
Names of the feature columns used for training in the input table |
String[] |
|
null |
labelCol |
Name of the label column in the input table |
String |
✓ |
|
weightCol |
Name of the column indicating weight |
String |
|
null |
vectorCol |
Name of a vector column |
String |
|
null |
standardization |
Whether standardize training data or not, default is true |
Boolean |
|
true |
Script Example
Script
data = np.array([
[2, 1, 1],
[3, 2, 1],
[4, 3, 2],
[2, 4, 1],
[2, 2, 1],
[4, 3, 2],
[1, 2, 1],
[5, 3, 3]])
df = pd.DataFrame({"f0": data[:, 0],
"f1": data[:, 1],
"label": data[:, 2]})
batchData = dataframeToOperator(df, schemaStr='f0 int, f1 int, label int', op_type='batch')
colnames = ["f0","f1"]
lasso = LassoRegTrainBatchOp().setLambda(0.1).setFeatureCols(colnames).setLabelCol("label")
model = batchData.link(lasso)
predictor = LassoRegPredictBatchOp().setPredictionCol("pred")
predictor.linkFrom(model, batchData).print()
Result
f0 |
f1 |
label |
pred |
2 |
1 |
1 |
0.830304 |
3 |
2 |
1 |
1.377312 |
4 |
3 |
2 |
1.924320 |
2 |
4 |
1 |
1.159119 |
2 |
2 |
1 |
0.939909 |
4 |
3 |
2 |
1.924320 |
1 |
2 |
1 |
0.502506 |
5 |
3 |
3 |
2.361724 |