6

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.

Rohan Nadagouda
  • 462
  • 7
  • 18
user3394040
  • 947
  • 13
  • 22

1 Answers1

9

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.

Most Wanted
  • 6,254
  • 5
  • 53
  • 70
elyase
  • 39,479
  • 12
  • 112
  • 119
  • For RBM what type of vectorizer would match nicely in order to do unsupervised learning as a previous step for text classification?. – tumbleweed Jan 28 '15 at 19:40
  • 1
    In theory a linear classifier, because the RBM should have extracted the non-linearities, but I don't think this this question can be answered in general. Is very data dependent. – elyase Jan 28 '15 at 23:03
  • Can I use this code to fill missing values? Does it require any modifications? – Vikas NS Jul 18 '18 at 21:14