Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Question to sklearn modules

Hey,

I've been playing around with sklearn.
While I am able to use some classes as the Decision Tree

from sklearn.tree import DecisionTreeRegressor (possible to import)

it's not possible to import other's eg. the neural network classifier:

from sklearn.neural_network import MLPClassifier

InputRejected:
Importing MLPClassifier from sklearn.neural_network raised an ImportError. No modules or attributes with a similar name were found.

Trying to copy the class's source code also failed because inheritance seems to be disabled in quantopian (InputRejected:
Insecure built-in function 'super'
).

I do understand that it comes from security concers as described in similar posts but i still have the follwing questions:

  • Am I doing anything wrong?
  • How can I see the limitations of actually supported libraries as sklearn?
  • Is there another possibility to use machine learning methods (classifiers/regressors) except sklearn that i could use instead?

Best Regards.

10 responses

Hi Leo,

It could be because of the scikit-learn version.
In order to use the "MLPClassifier", you need the scikit-learn version 0.18.

Chris

Hi Chris,

It looks like Quantopian currently provides version 0.18. That should be correct.

I actually was successful in importing the "MLPClassifier" but with a different syntax (See notebook).
So to me it looks like an understanding problem of python but i still dont know why it works with the DecisionTreeClassifier.

Can you shortly explain why

1)

import sklearn.neural_network  
ANN = sklearn.neural_network.MLPClassifier(solver='lbfgs', alpha=1e-5,hidden_layer_sizes=(5, 2), random_state=1)  

works
but

2)

from sklearn.neural_network import MLPClassifier  
clf = MLPClassifier(solver='lbfgs', alpha=1e-5,hidden_layer_sizes=(5, 2), random_state=1)  

does not work although it works with the Class "DecisionTreeClassifier" of sklearn.tree both ways?

Regards

You are right Leo, it's not a version issue here.
It must be an issue from Quantopian side because it works well on Jupyter Notebook with the same verison.

I am sorry but I could not help you more here, but maybe someone from Quantopian could help.

Regards,
Chris

Hey Chris,

thanks.

Yes I would appriciate if Quantopian Support or anyone with similar problems could help here.
I also have these problems with other classes from sklearn.

Regards

Hi!
trying

import sklearn.neural_network  
ANN = sklearn.neural_network.MLPClassifier(solver='lbfgs', alpha=1e-5,hidden_layer_sizes=(5, 2), random_state=1)  

yields

SecurityViolation: 0002 Security Violation(s): Insecure attribute access "sklearn.neural_network.MLPClassifier" on line 2

for me. This is from a research notebook. Do you get the same?

@Konsta Tiihonen, Yes I am getting the same error

There is a similar issue with sklearn.kernel_ridge. I could be wrong but I though this was included in the version of sklearn that Quantopian provides. In this case, at least implementing kernel ridge regression is a 2 liner in Python with Numpy, the same isn't true for MLPClassifier :(

It seem's we've been dropped down to sklearn 0.16.1

Any fix yet?

This is highly annoying.

Getting the same issue. ANNs are a key algorithm that Quantopian users should be able to rely on. Still no comment from Quantopian support.