我正在尝试根据本教程的指导为Python sklearn管道创建自定义转换器:http ://danielhnyk.cz/creating-your-own-estimator-scikit-learn/
现在,我的自定义类/变压器看起来像这样:
class SelectBestPercFeats(BaseEstimator, TransformerMixin):
def __init__(self, model=RandomForestRegressor(), percent=0.8,
random_state=52):
self.model = model
self.percent = percent
self.random_state = random_state
def fit(self, X, y, **fit_params):
"""
Find features with best predictive power for the model, and
have cumulative importance value less than self.percent
"""
# Check parameters
if not isinstance(self.percent, float):
print("SelectBestPercFeats.percent is not a float, it should be...")
elif not isinstance(self.random_state, int):
print("SelectBestPercFeats.random_state is not a int, it should be...")
# If checks are good proceed with …Run Code Online (Sandbox Code Playgroud)