Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scikit learn 受限玻尔兹曼机器:如何预测类标签?_Scikit Learn - Fatal编程技术网

Scikit learn 受限玻尔兹曼机器:如何预测类标签?

Scikit learn 受限玻尔兹曼机器:如何预测类标签?,scikit-learn,Scikit Learn,因此,我在SKLearn网站上阅读了受限Boltzmann机器的示例,在该示例成功后,我想与BernoulliRBM进行更多的交流,以更好地了解RBM的工作原理。我试着做一些简单的课堂预测: # Adapted from sample digits recognition client on Scikit-Learn site. import numpy as np from sklearn import linear_model, datasets from sklearn.cross_va

因此,我在SKLearn网站上阅读了受限Boltzmann机器的示例,在该示例成功后,我想与BernoulliRBM进行更多的交流,以更好地了解RBM的工作原理。我试着做一些简单的课堂预测:

# Adapted from sample digits recognition client on Scikit-Learn site.

import numpy as np
from sklearn import linear_model, datasets
from sklearn.cross_validation import train_test_split
from sklearn.neural_network import BernoulliRBM
from sklearn.pipeline import Pipeline
from sklearn.lda import LDA

# import some data to play with
iris = datasets.load_iris()
X = iris.data[:, :2]  # we only take the first two features.
Y = iris.target
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2,     random_state=10)

# Models we will use
rbm = BernoulliRBM(random_state=0, verbose=True)
logistic = linear_model.LogisticRegression()
classifier = Pipeline(steps=[('rbm', rbm), ('logistic', logistic)])
lda = LDA(n_components=3)

#########################################################################

# Training RBM-Logistic Pipeline
logistic.fit(X_train, Y_train)
classifier.fit(X_train, Y_train)

#########################################################################

# Get predictions
print "The RBM model:"
print "Predict: ", classifier.predict(X_test)
print "Real:    ", Y_test

print

print "Linear Discriminant Analysis: "
lda.fit(X_train, Y_train)
print "Predict: ", lda.predict(X_test)
print "Real:    ", Y_test    
这是输出:

Iteration 0, pseudo-likelihood = 0.00, time = 0.02s
Iteration 1, pseudo-likelihood = 0.00, time = 0.02s
Iteration 2, pseudo-likelihood = 0.00, time = 0.02s
Iteration 3, pseudo-likelihood = 0.00, time = 0.02s
Iteration 4, pseudo-likelihood = 0.00, time = 0.02s
Iteration 5, pseudo-likelihood = 0.00, time = 0.02s
Iteration 6, pseudo-likelihood = 0.00, time = 0.02s
Iteration 7, pseudo-likelihood = 0.00, time = 0.01s
Iteration 8, pseudo-likelihood = 0.00, time = 0.01s
Iteration 9, pseudo-likelihood = 0.00, time = 0.02s
The RBM model:
Predict:  [2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2]
Real:     [1 2 0 1 0 1 1 1 0 1 1 2 1 0 0 2 1 0 0 0 2 2 2 0 1 0 1 1 1 2]

Linear Discriminant Analysis:
Predict:  [2 2 0 1 0 1 2 1 0 1 1 1 1 0 0 2 1 0 0 0 2 2 2 0 1 0 1 1 2 2]
Real:     [1 2 0 1 0 1 1 1 0 1 1 2 1 0 0 2 1 0 0 0 2 2 2 0 1 0 1 1 1 2]

为什么RBM预测测试数据中的每个标签为2,即使LDA证明它显然不正确?如何让Pipelinerbm、logistic预测类别标签?如果你能向神经网络新手解释这一点,我将非常感激。

对于伯努利RBM,你应该使用二进制特征。试试sklearn.preprocessing.Binarizer.@convariance,你能发布你所做的改变吗?