我有一个数据帧df,它具有spotify数据功能。当我使用RandomForestClassifier运行模型时,我得到了特征重要图,但当我运行RandomForestRegressor时,我只得到了一个与受欢迎程度相反的条形图。有人能帮帮忙吗?
from yellowbrick.model_selection import FeatureImportances
# Load the classification data set
X = df[features]
y = df.popularity
train_X, test_X, train_y, test_y = train_test_split(X,y, test_size= 0.1, random_state=38)
model = RandomForestClassifier(n_estimators=10)
# model = RandomForestRegressor(n_estimators=10)
viz = FeatureImportances(model)
viz.fit(X, y)
viz.show()发布于 2021-02-23 20:49:23
我用spotify数据集重复了上面的实验,但是我能够将RandomForestRegressor与Yellowbrick的FeatureImportances Visualizer一起使用(见下图)。我建议您将yellowbrick更新到最近于2月9日发布的最新版本。pip安装-U yellowbrick
from yellowbrick.model_selection import FeatureImportances
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
# Load spotify Data Set
df = pd.read_csv('data.csv.zip')
df = df[['acousticness', 'danceability', 'duration_ms', 'energy',
'explicit', 'instrumentalness', 'liveness', 'loudness',
'popularity','speechiness', 'tempo']]
X = df.drop('popularity', axis=1)
y = df.popularity
train_X, test_X, train_y, test_y = train_test_split(X,y, test_size= 0.1, random_state=38)
#model = RandomForestClassifier(n_estimators=10)
model = RandomForestRegressor(n_estimators=10)
viz = FeatureImportances(model)
viz.fit(X, y)
viz.show()

https://stackoverflow.com/questions/66307543
复制相似问题