4

I am using a OneVsRestClassifier on MLPClassifier. I am using this for classifying text data where X is set of questions in pd.DataFrame and Y is multi-label and multi-class strings. Please see below the code snippets

text_clf = Pipeline([('scale',StandardScaler(with_mean=False)),('clf',OneVsRestClassifier(MLPClassifier(learning_rate = 'adaptive', solver = 'lbfgs',random_state=9000)))])
parameters = {'clf__alpha':[10.0 ** ~ np.arange(1, 7).any()],'clf__hidden_layer_sizes': [(100,),(50,)],'clf__max_iter': [1000,500],'clf__activation':('relu','tanh')}
grid = GridSearchCV(text_clf, parameters, cv=3, n_jobs=-1, scoring= 'accuracy') 
with parallel_backend('threading'):
    grid.fit(X,Y)

I am getting the following error

ValueError: Invalid parameter activation for estimator OneVsRestClassifier(estimator=MLPClassifier(activation='relu', alpha=0.0001, batch_size='auto', beta_1=0.9,
   beta_2=0.999, early_stopping=False, epsilon=1e-08,
   hidden_layer_sizes=(100,), learning_rate='adaptive',
   learning_rate_init=0.001, max_iter=200, momentum=0.9,
   n_iter_no_change=10, nesterovs_momentum=True, power_t=0.5,
   random_state=9000, shuffle=True, solver='lbfgs', tol=0.0001,
   validation_fraction=0.1, verbose=False, warm_start=False),
      n_jobs=None). Check the list of available parameters with `estimator.get_params().keys()`.

As per my understanding MLPClassifier supports Multi Label classification. Is it indicating that parameters need to be re-examined? If so, then can any body please give any clue on where to make changes in parameters?

Any help would really be appreciated.

1 Answer 1

3

Your MLPClassifier is nested into OneVsRestClassifier as its estimator.

In other words, parameters should specify that all of alpha, hidden_layer_sizes, ... are meant for nested estimator not OneVsRestClassifier.

Changing your parameters like following should do the job:

parameters = {'clf__estimator__alpha':[10.0 ** ~ np.arange(1,7).any()],
    'clf__estimator__hidden_layer_sizes': [(100,),(50,)],
    'clf__estimator__max_iter': [1000,500],
    'clf__estimator__activation':('relu','tanh')}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks C.Kim. However, it is giving an user warning as UserWarning: Label not 42 is present in all training examples. str(classes[c])). Any clue why such warning is coming?
@pythondumb From the look of it, it seems like there is a problem with x for grid.fit. Perhaps stackoverflow.com/questions/42821315/… can help you out :)
Thanks a ton!! let me use Labelencoder and see how this work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.