pythonscikit-learnrbm

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.


Solution

  • 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.