2016-09-08 7 views
1

Kaggle에서 찾은 하우징 데이터 세트를 사용하여 PySpark에서 매우 단순한 LinearRegression을 수행하려고합니다. 컬럼이 많지만 가능한 한 간단하게 (사실상)이 컬럼을 두 개 유지합니다 (모두 시작한 후), 아직 모델 훈련을받지 못한 행운은 없습니다. 내가지고있어 오류가Spark LinearRegression 오류의 원인을 알아낼 수 없습니다.

standard_scaler = StandardScaler(inputCol='features', 
            outputCol='scaled') 
    lr = LinearRegression(featuresCol=standard_scaler.getOutputCol(), labelCol='price', weightCol=None, 
          maxIter=100, tol=1e-4) 
    pipeline = Pipeline(stages=[standard_scaler, lr]) 
    grid = (ParamGridBuilder() 
      .baseOn({lr.labelCol: 'price'}) 
      .addGrid(lr.regParam, [0.1, 1.0]) 
      .addGrid(lr.elasticNetParam, elastic_net_params or [0.0, 1.0]) 
      .build()) 
    ev = RegressionEvaluator(metricName="rmse", labelCol='price') 
    cv = CrossValidator(estimator=pipeline, 
         estimatorParamMaps=grid, 
         evaluator=ev, 
         numFolds=5) 
    model = cv.fit(data).bestModel 

:

2016-09-07 17:12:08,804 root INFO [Row(price=78000.0, sqft_living=780.0, sqft_lot=16344.0, features=DenseVector([780.0, 16344.0])), Row(price=80000.0, sqft_living=430.0, sqft_lot=5050.0, features=DenseVector([430.0, 5050.0])), Row(price=81000.0, sqft_living=730.0, sqft_lot=9975.0, features=DenseVector([730.0, 9975.0])), Row(price=82000.0, sqft_living=860.0, sqft_lot=10426.0, features=DenseVector([860.0, 10426.0])), Row(price=84000.0, sqft_living=700.0, sqft_lot=20130.0, features=DenseVector([700.0, 20130.0])), Row(price=85000.0, sqft_living=830.0, sqft_lot=9000.0, features=DenseVector([830.0, 9000.0])), Row(price=85000.0, sqft_living=910.0, sqft_lot=9753.0, features=DenseVector([910.0, 9753.0])), Row(price=86500.0, sqft_living=840.0, sqft_lot=9480.0, features=DenseVector([840.0, 9480.0])), Row(price=89000.0, sqft_living=900.0, sqft_lot=4750.0, features=DenseVector([900.0, 4750.0])), Row(price=89950.0, sqft_living=570.0, sqft_lot=4080.0, features=DenseVector([570.0, 4080.0]))] 

나는 모델을 학습하려면 다음 코드를 사용하고 다음은 회귀 단계를 진행하기 전에 같은 데이터 프레임 모습입니다

2016-09-07 17:12:08,805 root INFO Training regression model... 
2016-09-07 17:12:09,530 root ERROR An error occurred while calling o60.fit. 
: java.lang.NullPointerException 
    at org.apache.spark.ml.regression.LinearRegression.train(LinearRegression.scala:164) 
    at org.apache.spark.ml.regression.LinearRegression.train(LinearRegression.scala:70) 
    at org.apache.spark.ml.Predictor.fit(Predictor.scala:90) 
    at org.apache.spark.ml.Predictor.fit(Predictor.scala:71) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:237) 
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) 
    at py4j.Gateway.invoke(Gateway.java:280) 
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:128) 
    at py4j.commands.CallCommand.execute(CallCommand.java:79) 
    at py4j.GatewayConnection.run(GatewayConnection.java:211) 
    at java.lang.Thread.run(Thread.java:745) 

의견이 있으십니까?

답변

1

이 경우 Pipeline을 사용할 수 없습니다. 당신이 호출 할 때 pipeline.fit는 (대략)

standard_scaler_model = standard_scaler.fit(dataframe) 
lr_model = lr.fit(dataframe) 

로 변환하지만 실제로는 오류가

standard_scaler_model = standard_scaler.fit(dataframe) 
dataframe = standard_scaler_model.transform(dataframe) 
lr_model = lr.fit(dataframe) 

필요가 있기 때문에 lr.fit 출력을 찾을 수 없습니다 (즉, 변환의 결과) 당신의 StandardScaler의 모델.

+0

여기서 오류는 StandardScaler 때문이 아닙니다. 그게 나를 위해 잘 작동합니다 (분명히 당신의 경험이 다릅니다). 오류는 '무게'열로 밝혀졌습니다. 나에게 오류를 일으킨'weightCol = None'을 지정하려고했을 때. 나는 weight (부동 소수점이어야한다!)로 1.0으로 weightCol을 생성함으로써 그것을 고쳤다. –

관련 문제