首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >yellowbrick.model_selection不适用于回归,但适用于分类

yellowbrick.model_selection不适用于回归,但适用于分类
EN

Stack Overflow用户
提问于 2021-02-22 05:53:49
回答 1查看 61关注 0票数 0

我有一个数据帧df,它具有spotify数据功能。当我使用RandomForestClassifier运行模型时,我得到了特征重要图,但当我运行RandomForestRegressor时,我只得到了一个与受欢迎程度相反的条形图。有人能帮帮忙吗?

代码语言:javascript
复制
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()
EN

回答 1

Stack Overflow用户

发布于 2021-02-23 20:49:23

我用spotify数据集重复了上面的实验,但是我能够将RandomForestRegressor与Yellowbrick的FeatureImportances Visualizer一起使用(见下图)。我建议您将yellowbrick更新到最近于2月9日发布的最新版本。pip安装-U yellowbrick

代码语言:javascript
复制
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()

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66307543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档