【问题标题】:yellowbrick.model_selection does not work for Regression but works for ClassificationYellowbrick.model_selection 不适用于回归,但适用于分类
【发布时间】:2021-05-24 05:07:57
【问题描述】:

我有一个具有 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()

【问题讨论】:

    标签: python random-forest yellowbrick


    【解决方案1】:

    我用 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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-09
      • 2015-11-03
      • 1970-01-01
      • 1970-01-01
      • 2020-07-29
      • 2021-06-18
      • 2019-02-28
      • 2018-12-06
      相关资源
      最近更新 更多