Использование sklearn.base.is_classifier
и / или is_regressor
:
from sklearn.base import is_classifier, is_regressor
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor
from sklearn.ensemble import RandomForestClassifier
models = [LinearRegression(), RandomForestClassifier(), RandomForestRegressor()]
for m in models:
print(m.__class__.__name__, is_classifier(m), is_regressor(m))
Выход:
# model_name is_classifier is_regressor
LinearRegression False True
RandomForestClassifier True False
RandomForestRegressor False True