我正在尝试使用 ElasticNet 和随机森林执行多输出回归,如下所示:
from sklearn.ensemble import RandomForestRegressor
from sklearn.multioutput import MultiOutputRegressor
from sklearn.linear_model import ElasticNet
X_train, X_test, y_train, y_test = train_test_split(X_features, y, test_size=0.30,random_state=0)
Run Code Online (Sandbox Code Playgroud)
弹性网
l1_range=np.arange(0.1,1.05,0.1).tolist()
regr_Enet=ElasticNetCV(cv=5,copy_X=True,n_alphas=100,l1_ratio=l1_range,selection='cyclic',normalize=False,verbose =2,n_jobs=1)
regr_multi_Enet= MultiOutputRegressor(regr_Enet)##ElasticNetCV
regr_multi_Enet.fit(X_train, y_train)
Run Code Online (Sandbox Code Playgroud)
随机森林
max_depth = 20
number_of_trees=100
regr_multi_RF=MultiOutputRegressor(RandomForestRegressor(n_estimators=number_of_trees,max_depth=max_depth,random_state=0,n_jobs=1,verbose=1))
regr_multi_RF.fit(X_train, y_train)
y_multirf = regr_multi_RF.predict(X_test)
Run Code Online (Sandbox Code Playgroud)
一切都很顺利,但是我还没有找到一种方法来获得模型的系数 (coef_) 或最重要的特征 (feature_importances_)。当我写:
regr_multi_Enet.coef_
regr_multi_RF.feature_importances_
Run Code Online (Sandbox Code Playgroud)
它显示以下错误:
AttributeError: 'MultiOutputRegressor' object has no attribute 'feature_importances_'
AttributeError: 'MultiOutputRegressor' object has no attribute 'coef_'
Run Code Online (Sandbox Code Playgroud)
我已阅读有关 MultiOutputRegressor 的文档,但找不到提取系数的方法。有谁知道如何找回它们?