Skip to content
Advertisement

Python OOP using sklearn API

I want to learn more advanced OOP methods and create a class using sklearn APIs, my idea is to integrate feature selection methods. I want to be able to call a feature selection method by name, and next fit and transform data.

JavaScript

I am not sure, what I am doing wrong but currently, I have the following error that I am not able to solve:


JavaScript

4 sklearn_fs.fit(X=train_data) 5 sklearn_fs.transform(X=train_data)

JavaScript

Advertisement

Answer

You never call _init_sklearn_method_object (nor _check_sklearn_methods), so the instance attribute method remains None from the parent class’s __init__.

Separately, FeatureSelection.fit won’t ever be run in what you’ve shown (maybe you intend to use the parent class directly at some point though?). And SklearnFeatureSelection.fit confusingly calls the skl method’s fit_transform rather than just fit, and doesn’t return anything.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement