user3394040
user3394040

Reputation: 977

Prediction for RBM in scikit

I would like to use RBM in scikit. I can define and train a RBM like many other classifiers.

from sklearn.neural_network import BernoulliRBM
clf = BernoulliRBM(random_state=0, verbose=True)
clf.fit(X_train, y_train)

But I can't seem to find a function that makes me a prediction. I am looking for an equivalent for one of the following in scikit.

y_score = clf.decision_function(X_test)
y_score = clf.predict(X_test)

Neither functions are present in BernoulliRBM.

Upvotes: 7

Views: 3799

Answers (1)

elyase
elyase

Reputation: 40973

The BernoulliRBM is an unsupervised method so you won't be able to do clf.fit(X_train, y_train) but rather clf.fit(X_train). It is mostly used for non-linear feature extraction that can be feed to a classifier. It would look like this:

logistic = linear_model.LogisticRegression()
rbm = BernoulliRBM(random_state=0, verbose=True)

classifier = Pipeline(steps=[('rbm', rbm), ('logistic', logistic)])

So the features extracted by rbm are passed to the LogisticRegression model. Take a look here for a full example.

Upvotes: 10

Related Questions