I tried to use DBN function imported from nolearn package, and here is my code:
from nolearn.dbn import DBN
import numpy as np
from sklearn import cross_validation
fileName = 'data.csv'
fileName_1 = 'label.csv'
data = np.genfromtxt(fileName, dtype=float, delimiter = ',')
label = np.genfromtxt(fileName_1, dtype=int, delimiter = ',')
clf = DBN(
[data, 300, 10],
learn_rates=0.3,
learn_rate_decays=0.9,
epochs=10,
verbose=1,
)
clf.fit(data,label)
score = cross_validation.cross_val_score(clf, data, label,scoring='f1', cv=10)
print score
Since my data has the shape(1231, 229) and label with the shape(1231,13), the label sets looks like ([0 0 1 0 1 0 1 0 0 0 1 1 0] ...,[....]), when I ran my code, I got the this error message: bad input shape (1231,13). I wonder two problem might happened here:
- DBN does not support multi-label classification
- my label is not suitable to be used in DBN fit function.
As mentioned by Francisco Vargas,
nolearn.dbn
is deprecated and you should usenolearn.lasagne
instead (if you can).If you want to do multi-label classification in lasagne, then you should set your
regression
parameter toTrue
, define a validation score and a custom loss.Here's an example:
Fit calls BuildDBN which can be found here here an important thing to note is that dbn has been deprecated and you can only find it old_commits. Anyways if you are looking for extra info its probably good to check those two from what I can see in your snippet is that the first parameter of
DBN
namely[data, 300, 10]
should be[data.shape[1], 300, 10]
based on the documentation and the source code. Hope this helps.