aigamedev / scikit-neuralnetwork

Deep neural networks without the learning cliff! Classifiers and regressors compatible with scikit-learn.
BSD 3-Clause "New" or "Revised" License
1.2k stars 221 forks source link

AssertionError: Mismatch between dataset size and units in output layer #201

Open sameh-habboubi opened 8 years ago

sameh-habboubi commented 8 years ago

I want to do a NN classification, I have 5 classes, so in the output layer , I have units=5 ibut I am getting this error: Mismatch between dataset size and units in output layer, I reshaped my y_train and applied "Sigmoid" function to the output layer according to the documentation:

If you want to do multi-label classification, simply fit using a y array of integers that has multiple dimensions, e.g. shape (N, 3) for three different classes. Then, make sure the last layer is Sigmoid instead.

y_train shape is : (2115, 5) X_train shape is : (2115, 343) This is the code:

import sknn.mlp as mlp
from sknn.mlp import Classifier
ip_layer = mlp.Layer('Sigmoid', units=1)
hidden_layer = mlp.Layer('Tanh', units=100)
op_layer = mlp.Layer('Sigmoid', units=5)

nn = Classifier(
    [ip_layer, hidden_layer, op_layer],
    n_iter=10000
)
nn.fit(X_train, y_train)
alexjc commented 8 years ago

It may be easier if you just leave out the number of output units. Can you paste the full error and tracebak?

sameh-habboubi commented 8 years ago

Thanks for answering Here is the full error:

AssertionError Traceback (most recent call last)

in () 2 clf=Classifier(([Layer("Sigmoid", units=100), 3 Layer("Sigmoid", units=5)]), learning_rate=0.1,n_iter=100) ----> 4 clf.fit(X_train, y_train) c:\users\sameh\scikit-neuralnetwork\sknn\mlp.py in fit(self, X, y, w) 395 396 # Now train based on a problem transformed into regression. --> 397 return super(Classifier, self)._fit(X, yp, w) 398 399 def partial_fit(self, X, y, classes=None): c:\users\sameh\scikit-neuralnetwork\sknn\mlp.py in _fit(self, X, y, w) 211 212 if not self.is_initialized: --> 213 X, y = self._initialize(X, y, w) 214 215 log.info("Training on dataset of {:,} samples with {} total size.".format(data_shape[0], data_size)) c:\users\sameh\scikit-neuralnetwork\sknn\mlp.py in _initialize(self, X, y, w) 36 assert not self.is_initialized,\ 37 "This neural network has already been initialized." ---> 38 self._create_specs(X, y) 39 40 backend.setup() c:\users\sameh\scikit-neuralnetwork\sknn\mlp.py in _create_specs(self, X, y) 63 else: 64 assert y is None or self.layers[-1].units == y.shape[1],\ ---> 65 "Mismatch between dataset size and units in output layer." 66 67 # Then compute the number of units in each layer for initialization. AssertionError: Mismatch between dataset size and units in output layer.