我正在尝试使用带有RBM和MLPclassifier的管道,我的输入数据将首先通过rbm,将进行降维(从513个功能到100个功能(节点)),我设法写代码似乎是正确的,但我最后得到了这个错误
UndefinedMetricWarning: Precision and F-score are ill-defined and being set
to 0.0 in labels with no predicted samples.
'precision', 'predicted', average, warn_for)
precision recall f1-score support
0 0.00 0.00 0.00 25
1 0.00 0.00 0.00 28
2 0.00 0.00 0.00 28
3 0.00 0.00 0.00 34
4 0.00 0.00 0.00 25
avg / total 0.00 0.00 0.00 140
这是我的代码
X_train, X_test, Y_train, Y_test = train_test_split(X,
Y,test_size=0.2,random_state=0)
mlp=MLPClassifier(hidden_layer_sizes=100,activation="tanh",max_iter=200)
rbm = BernoulliRBM(random_state=0, verbose=True)
classifier = Pipeline(steps=[('rbm', rbm), ('mlpclassifier', mlp)])
rbm.learning_rate = 0.06
rbm.n_iter = 20
rbm.n_components = 100
classifier.fit(X_train, Y_train)
print("MLP using RBM features:\n%s\n" % (
metrics.classification_report(
Y_test,
classifier.predict(X_test))))
答案 0 :(得分:0)
感谢您的回答Kumar,我试图从测试集中取一个样本,然后进行预测
print('the real label', Y_train[0])
print('the prediction', classifier.predict(X_train[0].reshape(1,-1)))
这就是我得到的输出
the real label [1 0 0 0 0]
the prediction [[0 0 0 0 0]]
在我看来,分类器(管道)没有经过培训!