Skip to content
Advertisement

NoSuchElementException: Failed to find a default value for layers in MultiLayerPerceptronClassifier

I am having a problem running a prediction using a saved MultiLayerPerceptronClassifier model.

# reading the saved model
# spark version: version 3.1.2, python3.6
from pyspark.ml import PipelineModel
from pyspark.ml import Pipeline
saved_model = "/home/user/Desktop/algorithms/mlpc_model_8979"
read_model = PipelineModel.load(saved_model)
# predictions using the read model
pred = read_model.transform(df)

It throws error:

Py4JJavaError: An error occurred while calling o98.transform.
: java.util.NoSuchElementException: Failed to find a default value for layers

The original mlpc in the pipeline had layers defined:

mlpc = MultilayerPerceptronClassifier(layers= [200, 30, 10],
                                       seed=1234,
                                       featuresCol="features",
                                       labelCols="label")

My attempts to solve it: If I run the pipeline model and do predictions without first saving the model. I works with no error. But saving and re-using the model throws this error. Any help on how to solve this “Failed to find a default value for layers” error?

Advertisement

Answer

After a lot of search I discovered a very strange solution.
Had to remove the space before the list = [] in the layers definition.

                                             |
                                             |
                                             v 
mlpc = MultilayerPerceptronClassifier(layers=[200, 30, 10],
                                       seed=1234,
                                       featuresCol="features",
                                       labelCols="label")
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement