3

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 ?

Amin
  • 138
  • 1
  • 8

3 Answers3

1

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?

runcoderun
  • 531
  • 6
  • 11
  • is there any way to use something like `sample_weight` for `MLPclassifier` like the one used in `Decisiontreeclassifier` ? – Amin Nov 10 '18 at 22:32
  • I don't think so - not unless one of the suggested work-arounds in the link I gave works. You might consider using Keras instead, as shown here: https://towardsdatascience.com/hyper-parameters-in-action-part-ii-weight-initializers-35aee1a28404. – runcoderun Nov 10 '18 at 23:09
  • Also, you might be able to get something useful out of this conversation about adding a pre-training functionality from scikit's Github page: https://github.com/scikit-learn/scikit-learn/pull/3281 – runcoderun Nov 10 '18 at 23:17
0

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

hmad
  • 159
  • 8
0

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
avchauzov
  • 1,007
  • 1
  • 8
  • 13