Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Had an error while testing MLPClassifier #1

Open
jspeed-meyers opened this issue Feb 21, 2020 · 3 comments
Open

Had an error while testing MLPClassifier #1

jspeed-meyers opened this issue Feb 21, 2020 · 3 comments

Comments

@jspeed-meyers
Copy link

Great package! Thank you for creating this. I was testing out the MLPClassifier() model with this package--see the complete code below--and was getting an AttributeError: 'list' object has no attribute 'ndim' when I used the package as is. I added some code below to convert the model coefficient elements into numpy arrays and it seemed to work. Am I missing something? Was this an error with the package or was it an error in how I was using the package? Either way, thank you again. Note: I was using Python 3.7.4.

import numpy as np
import sklearn_json as skljson
from sklearn.neural_network import MLPClassifier
from sklearn import datasets

# Load data
df = datasets.load_iris()
X = df.data 
y = df.target 

# Instantiate and fit model
model_fit = MLPClassifier(solver='lbfgs', alpha=1e-5,
	hidden_layer_sizes=(15,), random_state=1).fit(X, y)
file_name = "model.json"

# Convert model to json
skljson.to_json(model_fit, file_name)

# Convert json back to model
deserialized_model = skljson.from_json(file_name)

## THE MISSING PIECE: THE LISTS INSIDE COEFS_ NEED
## TO BE CONVERTED TO ARRAYS
for i, x in enumerate(deserialized_model.coefs_):
	deserialized_model.coefs_[i] = np.array(x)

# This prediction should run if the code really works
deserialized_model.predict(X)
@mathieujofis
Copy link
Contributor

Hey thanks for the kind words and I'm glad you enjoy it.

Do the tests pass for you? If so, then it's probably not your fault and just something I missed. Feel free to make a PR with an updated MLP classifier test.

@jspeed-meyers
Copy link
Author

Thanks for consulting on this matter. There are three failing tests when I run pytest on the current codebase with my machine: test_mlp, test_svm, and test_svr. I am using Python 3.7.4, numpy 1.18.1, and scikit-learn 0.22. Perhaps this is an issue particular to one of these package versions.

@mathieujofis
Copy link
Contributor

Yes, it is likely the new scikit-learn version, as this was developed with 0.21.3. I'm not as active with this project right now and should update the readme to reflect as such. I welcome contributions, however!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants