forked from scikit-learn-contrib/sklearn-pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request scikit-learn-contrib#177 from ragrawal/astransformer
ActAsTransformer
- Loading branch information
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from sklearn.base import BaseEstimator, TransformerMixin | ||
import numpy as np | ||
|
||
|
||
class ActAsTransformer(BaseEstimator, TransformerMixin): | ||
""" | ||
Use this class to convert a random function into a | ||
transformer. | ||
""" | ||
|
||
def __init__(self, func): | ||
self.__func = func | ||
|
||
def fit(self, x, y=None): | ||
return self | ||
|
||
def transform(self, x): | ||
return np.vectorize(self.__func)(x) | ||
|
||
def __call__(self, *args, **kwargs): | ||
return self.__func(*args, **kwargs) |
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