LassoModel

pyspark.mllib.regression。 LassoModel ( 权重:pyspark.mllib.linalg.Vector,拦截:浮动 )

从最小二乘线性回归模型推导出符合一个l1惩罚项。

例子

> > >pyspark.mllib.linalg进口SparseVector> > >pyspark.mllib.regression进口LabeledPoint> > >数据=(LabeledPoint(0.0,(0.0]),LabeledPoint(1.0,(1.0]),LabeledPoint(3.0,(2.0]),LabeledPoint(2.0,(3.0])]> > >lrm=LassoWithSGD火车(sc并行化(数据),迭代=10,initialWeights=np数组([1.0)))> > >腹肌(lrm预测(np数组([0.0)))- - - - - -0)<0.5真正的> > >腹肌(lrm预测(np数组([1.0)))- - - - - -1)<0.5真正的> > >腹肌(lrm预测(SparseVector(1,{0:1.0}))- - - - - -1)<0.5真正的> > >腹肌(lrm预测(sc并行化([[1.0]]))收集()(0]- - - - - -1)<0.5真正的> > >进口操作系统,tempfile> > >路径=tempfilemkdtemp()> > >lrm保存(sc,路径)> > >sameModel=LassoModel负载(sc,路径)> > >腹肌(sameModel预测(np数组([0.0)))- - - - - -0)<0.5真正的> > >腹肌(sameModel预测(np数组([1.0)))- - - - - -1)<0.5真正的> > >腹肌(sameModel预测(SparseVector(1,{0:1.0}))- - - - - -1)<0.5真正的> > >shutil进口rmtree> > >试一试:rmtree(路径)除了BaseException:通过> > >数据=(LabeledPoint(0.0,SparseVector(1,{0:0.0})),LabeledPoint(1.0,SparseVector(1,{0:1.0})),LabeledPoint(3.0,SparseVector(1,{0:2.0})),LabeledPoint(2.0,SparseVector(1,{0:3.0}))]> > >lrm=LinearRegressionWithSGD火车(sc并行化(数据),迭代=10,initialWeights=np数组([1.0)))> > >腹肌(lrm预测(np数组([0.0)))- - - - - -0)<0.5真正的> > >腹肌(lrm预测(SparseVector(1,{0:1.0}))- - - - - -1)<0.5真正的> > >lrm=LassoWithSGD火车(sc并行化(数据),迭代=10,一步=1.0,regParam=0.01,miniBatchFraction=1.0,initialWeights=np数组([1.0]),拦截=真正的,validateData=真正的)> > >腹肌(lrm预测(np数组([0.0)))- - - - - -0)<0.5真正的> > >腹肌(lrm预测(SparseVector(1,{0:1.0}))- - - - - -1)<0.5真正的

方法

负载(sc路径)

加载LassoModel。

预测(x)

预测因变量的值给定的向量或一个向量的抽样,其中包含独立变量的值。

保存(sc路径)

节省LassoModel。

属性

拦截

截距计算模型。

权重

权重计算为每个特性。

方法的文档

classmethod 负载 ( sc:pyspark.context.SparkContext,路径:str )pyspark.mllib.regression.LassoModel

加载LassoModel。

预测 ( x:联盟(VectorLike,pyspark.rdd.RDD(VectorLike]] )→联盟(浮动,pyspark.rdd.RDD(浮动] ]

预测因变量的值给定的向量或一个向量的抽样,其中包含独立变量的值。

保存 ( sc:pyspark.context.SparkContext,路径:str )→没有

节省LassoModel。

属性的文档

拦截

截距计算模型。

权重

权重计算为每个特性。