2017-07-20 6 views
2

私はLinearRegressionで処理されるDataFrameを持っています。私はそれを行う場合は、直接、下記のように、私は、モデルの詳細を表示することができます。私は(下記の簡略化した例のように)パイプラインの内側にそれを使用する場合、MLパイプラインの基礎となるモデルのパラメータにアクセスするには?

val lr = new LinearRegression() 
val lrModel = lr.fit(df) 

lrModel: org.apache.spark.ml.regression.LinearRegressionModel = linReg_b22a7bb88404 

println(s"Coefficients: ${lrModel.coefficients} Intercept: ${lrModel.intercept}") 
Coefficients: [0.9705748115939526] Intercept: 0.31041486689532866 

しかし

val pipeline = new Pipeline().setStages(Array(lr)) 
val lrModel = pipeline.fit(df) 

私は次のエラーを取得します。

scala> lrModel 
res9: org.apache.spark.ml.PipelineModel = pipeline_99ca9cba48f8 

scala> println(s"Coefficients: ${lrModel.coefficients} Intercept: ${lrModel.intercept}") 
<console>:68: error: value coefficients is not a member of org.apache.spark.ml.PipelineModel 
     println(s"Coefficients: ${lrModel.coefficients} Intercept: ${lrModel.intercept}") 
             ^
<console>:68: error: value intercept is not a member of org.apache.spark.ml.PipelineModel 
     println(s"Coefficients: ${lrModel.coefficients} Intercept: ${lrModel.intercept}") 

私は(それがあるため、パイプラインの、私は別のクラスを持って明らかです)、それが何を意味するかを理解し、本当の基礎となるモデルを取得する方法がわかりません。

答えて

2

LinearRegressionModelLinearRegressionに対応するとまったく同じインデックスでstages内部にあるべきです。

import org.apache.spark.ml.regressio‌​n.LinearRegressionMo‌​del 
lrModel.stages(0).asInstanceOf[LinearRegressionMo‌​del] 
関連する問題