Amin
Amin

Reputation: 138

Initialize weights in sklearn.neural_network

I want to initialize weights in a MLPclassifier, but when i use sample_weight in .fit() method, it says that TypeError: fit() got an unexpected keyword argument 'sample_weight'

import sklearn.neural_network as SKNN

mlp_classifier = SKNN.MLPClassifier((10,), learning_rate="invscaling",solver="lbfgs")

fit_model = mlp_classifier.fit(train_data,train_target,  sample_weight = weight)

i also read What does `sample_weight` do to the way a `DecisionTreeClassifier` works in sklearn?, it said that you should use sample_weight in the .fit() method.

is there any way to use sample_weight for MLPclassifier like the one used in Decisiontreeclassifier ?

Upvotes: 3

Views: 3586

Answers (3)

andrewchauzov
andrewchauzov

Reputation: 1009

There are no sample weights in sklearn NN yet. But you can as the start:

  1. find it in Keras: https://keras.io/models/sequential/
  2. write the NN in numpy and implement sample_weight by yourself

Upvotes: 0

runcoderun
runcoderun

Reputation: 531

That is because MLPClassifier unlike DecisionTreeClassifier doesn't have a fit() method with a sample_weight parameter.

See the documentation.

Maybe some of the answers to this similar question can help: How to set initial weights in MLPClassifier?

Upvotes: 1

hmad
hmad

Reputation: 176

according to sklearn.neural_network.MLPClassifier.fit the fit method does not have an argument named sample_weight

Upvotes: 0

Related Questions