0

我有一个具有 spotify 数据功能的数据框 df 。当我使用 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()
4

1 回答 1

0

我用 spotify 数据集重复了上述实验,但是我能够将 RandomForestRegressor 与 Yellowbrick 的 FeatureImportances Visualizer 一起使用(见下图)。我建议您将 Yellowbrick 更新到 2 月 9 日最近发布的最新版本。pip install -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()

在此处输入图像描述

于 2021-02-23T12:49:22.767 回答