Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the number of output nodes in scikit-learn's MLPClassifier

I'm currently experimenting with scikit-learn's neural net capabilites. Is there are way to set the number of output nodes in its MLPClassifier? I know you can set the number of hidden layers by passing it as parameters like:

clf = MLPClassifier(hidden_layer_sizes=(100,)

Thanks

like image 430
Oliver Atienza Avatar asked Dec 03 '16 01:12

Oliver Atienza


People also ask

What is Max ITER in MLPClassifier?

max_iter: It denotes the number of epochs. activation: The activation function for the hidden layers. solver: This parameter specifies the algorithm for weight optimization across the nodes.

What is hidden layer size MLPClassifier?

3.3 MLPClassifier hidden_layer_sizes : With this parameter we can specify the number of layers and the number of nodes we want to have in the Neural Network Classifier. Each element in the tuple represents the number of nodes at the ith position, where i is the index of the tuple.

What is Max_iter in MLP?

max_iterint, default=200. Maximum number of iterations. The solver iterates until convergence (determined by 'tol') or this number of iterations. For stochastic solvers ('sgd', 'adam'), note that this determines the number of epochs (how many times each data point will be used), not the number of gradient steps.


1 Answers

The number of output nodes is dependent on the size of your labels.

An example of the User Guide for Neural Networks:

>>> from sklearn.neural_network import MLPClassifier
>>> X = [[0., 0.], [1., 1.]]
>>> y = [[0, 1], [1, 1]]
>>> clf = MLPClassifier(solver='lbfgs', alpha=1e-5,
...                     hidden_layer_sizes=(15,), random_state=1)
>>> clf.fit(X, y)                         
>>> clf.predict([[1., 2.]])
array([[1, 1]])
like image 69
Deb Avatar answered Sep 20 '22 20:09

Deb