在Spark版本3.0.0中加载和应用MultilayerPerceptronClassifier时出现问题/错误

时间:2020-07-08 08:40:44

标签: pyspark apache-spark-mllib apache-spark-ml spark3

IllegalArgumentException:MultilayerPerceptronClassifier _...参数求解器给出了无效的自动值

我相信我在我测试过的Spark 3.0.0,Scala 2.1.2中加载MultilayerPerceptronClassificationModel时发现了一个错误,该错误至少在Spark 2.4.3,Scala 2.11中不存在。

我正在databricks群集上使用pyspark并“从pyspark.ml.classification import MultilayerPerceptronClassificationModel”导入库

运行模型时= MultilayerPerceptronClassificationModel。(“负载”),然后进行建模。转换(df),出现以下错误:IllegalArgumentException:MultilayerPerceptronClassifier_8055d1368e78参数求解器给出了无效的自动值。

通过运行spark文档http://spark.apache.org/docs/latest/ml-classification-regression.html#multilayer-perceptron-classifier

上给出的示例,可以轻松地复制此问题。

然后添加保存模型,装入模型和转换语句,如下所示:

from pyspark.ml.classification import MultilayerPerceptronClassifier
from pyspark.ml.evaluation import MulticlassClassificationEvaluator

# Load training data
data = spark.read.format("libsvm")\
    .load("data/mllib/sample_multiclass_classification_data.txt")

# Split the data into train and test
splits = data.randomSplit([0.6, 0.4], 1234)
train = splits[0]
test = splits[1]

# specify layers for the neural network:
# input layer of size 4 (features), two intermediate of size 5 and 4
# and output of size 3 (classes)
layers = [4, 5, 4, 3]

# create the trainer and set its parameters
trainer = MultilayerPerceptronClassifier(maxIter=100, layers=layers, blockSize=128, seed=1234)

# train the model
model = trainer.fit(train)

# compute accuracy on the test set
result = model.transform(test)
predictionAndLabels = result.select("prediction", "label")
evaluator = MulticlassClassificationEvaluator(metricName="accuracy")
print("Test set accuracy = " + str(evaluator.evaluate(predictionAndLabels)))

from pyspark.ml.classification import MultilayerPerceptronClassifier, MultilayerPerceptronClassificationModel
model.save(Save_location)
model2. MultilayerPerceptronClassificationModel.load(Save_location)

result_from_loaded = model2.transform(test)

1 个答案:

答案 0 :(得分:0)

已确认Bug吉拉已打开:: https://issues.apache.org/jira/browse/SPARK-32232

相关问题