numpy - Cant fit scikit-neuralnetwork classifier because of tuple index out of range -


i trying classifier working. extension scikit learn dependencies theano.

my goal fit neural network list of years , teach know if leap year or not (later increase range). run in error if want test example.

my code looks this:

leapyear.py

import numpy np import calendar  sknn.mlp import classifier, layer sklearn.cross_validation import train_test_split  # create years in range years = np.arange(1970, 2001) pre_is_leap = []  # test if year leapyear x in years:     pre_is_leap.append(calendar.isleap(x))  # convert true, false list 0,1 list is_leap = np.array(pre_is_leap, dtype=bool).astype(int)  # split years_train, years_test, is_leap_train, is_leap_test = train_test_split(years, is_leap, test_size=0.33, random_state=42)  # test output print(len(years_train)) print(len(is_leap_train)) print(years_train) print(is_leap_train)  #neural network nn = classifier(     layers=[         layer("maxout", units=100, pieces=2),         layer("softmax")],     learning_rate=0.001,     n_iter=25)  # fit  nn.fit(years_train, is_leap_train) #nn.fit(np.array(years_train), np.array(is_leap_train)) 

requirements.txt

numpy==1.9.2 pyyaml==3.11 scikit-learn==0.16.1 scikit-neuralnetwork==0.3 scipy==0.16.0 theano==0.7.0 

my output error:

20 20 [1986 1975 1983 1981 1992 1971 1972 1995 1973 1991 1996 1988 2000 1990 1977  1980 1984 1998 1989 1976] [0 0 0 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 0 1] /home/devnull/master/scikit/env/lib/python3.4/site-packages/sklearn/utils/validation.py:498: userwarning: minmaxscaler assumes floating point values input, got int64   "got %s" % (estimator, x.dtype)) /home/devnull/master/scikit/env/lib/python3.4/site-packages/sklearn/preprocessing/data.py:256: deprecationwarning: implicitly casting between incompatible kinds. in future numpy release, raise error. use casting="unsafe" if intentional.   x *= self.scale_ /home/devnull/master/scikit/env/lib/python3.4/site-packages/sklearn/preprocessing/data.py:257: deprecationwarning: implicitly casting between incompatible kinds. in future numpy release, raise error. use casting="unsafe" if intentional.   x += self.min_ traceback (most recent call last):   file "/home/devnull/master/scikit/leapyear.py", line 47, in <module>     pipeline.fit(years_train, is_leap_train)   file "/home/devnull/master/scikit/env/lib/python3.4/site-packages/sklearn/pipeline.py", line 141, in fit     self.steps[-1][-1].fit(xt, y, **fit_params)   file "/home/devnull/master/scikit/env/lib/python3.4/site-packages/sknn/mlp.py", line 283, in fit     return super(classifier, self)._fit(x, yp)   file "/home/devnull/master/scikit/env/lib/python3.4/site-packages/sknn/mlp.py", line 127, in _fit     x, y = self._initialize(x, y)   file "/home/devnull/master/scikit/env/lib/python3.4/site-packages/sknn/mlp.py", line 37, in _initialize     self._create_specs(x, y)   file "/home/devnull/master/scikit/env/lib/python3.4/site-packages/sknn/mlp.py", line 67, in _create_specs     self.unit_counts = [numpy.product(x.shape[1:]) if self.is_convolution else x.shape[1]] indexerror: tuple index out of range 

i looked sources of mlp.py, dont know how fix it. has changed can fit network?

update not question related: wanted add, need convert year binary representation, after neural network work.

the problem classifier requires data presented 2 dimensional numpy array, first axis being samples , second axis being features.

in case have 1 "feature" (the year) need turn years data nx1 2d numpy array. can achieved adding following line before data split statement:

years = np.array([[year] year in years]) 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -