Created
November 9, 2019 05:20
-
-
Save tianhuil/40fb1e9cea78364f60a2edbd025c370c to your computer and use it in GitHub Desktop.
Turns classifier's `predict_proba` into a transform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.base import BaseEstimator, TransformerMixin | |
class ClassifierTransform(BaseEstimator, TransformerMixin): | |
def __init__(self, clf): | |
self.clf = clf | |
def fit(self, X, y=None): | |
self.clf.fit(X, y) | |
return self | |
def transform(self, X): | |
return self.clf.predict_proba(X) | |
def classifier_transform(clf): | |
return ClassifierTransform(clf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment