### AttributeError: ‘PipelineModel’ 对象没有属性 ‘fitMultiple’

我在尝试使用 pyspark、CrossValidator 和 BinaryClassificationEvaluator 调优随机森林模型时遇到了一个错误。这是我的代码。

from pyspark.ml.evaluation import BinaryClassificationEvaluatorfrom pyspark.ml.classification import RandomForestClassifierfrom pyspark.ml.feature import VectorAssemblerfrom pyspark.ml import Pipeline# Create a spark RandomForestClassifier using all default parameters.# Create a training, and testing dftraining_df, testing_df = raw_data_df.randomSplit([0.6, 0.4])# build a pipeline for analysisva = VectorAssembler().setInputCols(training_df.columns[0:110:]).setOutputCol('features')# featuresCol="features"rf = RandomForestClassifier(labelCol="quality")# Train the model and calculate the AUC using a BinaryClassificationEvaluatorrf_pipeline = Pipeline(stages=[va, rf]).fit(training_df)bce = BinaryClassificationEvaluator(labelCol="quality")# Check AUC before tuningbce.evaluate(rf_pipeline.transform(testing_df))from pyspark.ml.tuning import CrossValidator, ParamGridBuilderparamGrid = ParamGridBuilder().build()crossValidator = CrossValidator(estimator=rf_pipeline,                           estimatorParamMaps=paramGrid,                           evaluator=bce,                           numFolds=3)model = crossValidator.fit(training_df)

它抛出了这个错误:

AttributeError: 'PipelineModel' object has no attribute 'fitMultiple'

我该如何解决这个问题?


回答:

CrossValidator 的 estimator 需要一个 Pipeline 对象,而不是 Pipeline 模型。

请参考这个例子 – https://github.com/apache/spark/blob/master/examples/src/main/python/ml/cross_validator.py

你的代码应按以下方式修改

  1. 创建一个 pipeline
rf_pipe = Pipeline(stages=[va, rf])
  1. 在 crossvalidator 中使用该 pipeline 作为 estimator
crossValidator = CrossValidator(estimator=rf_pipe,                           estimatorParamMaps=paramGrid,                           evaluator=bce,                           numFolds=3)

总体来说 –

....# Train the model and calculate the AUC using a BinaryClassificationEvaluatorrf_pipe = Pipeline(stages=[va, rf])rf_pipeline = rf_pipe.fit(training_df)...crossValidator = CrossValidator(estimator=**rf_pipe**,                           estimatorParamMaps=paramGrid,                           evaluator=bce,                           numFolds=3)model = crossValidator.fit(training_df)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注