1from sklearn.preprocessing import LabelBinarizer
2
3class LabelBinarizerPipelineFriendly(LabelBinarizer):
4 def fit(self, X, y=None):
5 """this would allow us to fit the model based on the X input."""
6 super(LabelBinarizerPipelineFriendly,self).fit(X)
7 def transform(self, X, y=None):
8 return super(LabelBinarizerPipelineFriendly, self).transform(X)
9 def fit_transform(self, X, y=None):
10 return super(LabelBinarizerPipelineFriendly, self).fit(X).transform(X)
1>>> from sklearn import preprocessing
2>>> lb = preprocessing.LabelBinarizer()
3>>> lb.fit([1, 2, 6, 4, 2])
4LabelBinarizer()
5>>> lb.classes_
6array([1, 2, 4, 6])
7>>> lb.transform([1, 6])
8array([[1, 0, 0, 0],
9 [0, 0, 0, 1]])