I'm doing some predictive modeling and would like to benchmark different kinds of regressors in scikit-learn
, just to see what's out there and how they perform on a given prediction task.
I got inspired to do this by this kaggle kernel in which the author essentially manually imports a bunch of classifiers (about 10) and benchmarks them.
I'm having trouble finding a comprehensive list of imports for the regressors in sklearn
so I'm trying to automatize the import
statements to automatically return me a list of classes that I can use.
I tried to dynamically import the classes:
from importlib import import_module
import sklearn
def all_regressors():
regressors=[]
for module in sklearn.__all__:
try:
regressors.extend([cls for cls in import_module(f'sklearn.{module}').__all__ if 'Regress' in cls ])
except:
pass
regressors.append(sklearn.svm.SVR)
return regressors
print(all_regressors())
But i only get back the names as strings, rather than the classes:
['RandomForestRegressor', 'ExtraTreesRegressor', 'BaggingRegressor',
'GradientBoostingRegressor', 'AdaBoostRegressor',
'GaussianProcessRegressor', 'IsotonicRegression', 'ARDRegression',
'HuberRegressor', 'LinearRegression', 'LogisticRegression',
'LogisticRegressionCV', 'PassiveAggressiveRegressor',
'RandomizedLogisticRegression', 'SGDRegressor', 'TheilSenRegressor',
'RANSACRegressor', 'MultiOutputRegressor', 'KNeighborsRegressor',
'RadiusNeighborsRegressor', 'MLPRegressor', 'DecisionTreeRegressor',
'ExtraTreeRegressor', <class 'sklearn.svm.classes.SVR'>]
How can I get the actual classes?