Prediction for RBM in scikit
Asked Answered
S

1

7

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.

Smaragdine answered 24/1, 2015 at 2:9 Comment(0)
F
10

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.

Febrifacient answered 24/1, 2015 at 2:36 Comment(3)
For RBM what type of vectorizer would match nicely in order to do unsupervised learning as a previous step for text classification?.Putout
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.Febrifacient
Can I use this code to fill missing values? Does it require any modifications?Pentomic

© 2022 - 2024 — McMap. All rights reserved.