小编DSo*_*thy的帖子

Seaborn 标题错误 - AttributeError: 'FacetGrid' 对象没有属性 'set_title

我首先使用以下代码创建了一个线图:

plot = sns.lineplot(data=tips,
             x="sex",
             y="tip",
             ci=50,
             hue="day",
             palette="Accent")
plot.set_title("Value of Tips Given to Waiters, by Days of the Week and Sex", fontsize=24, pad=30, fontdict={"weight": "bold"})
plot.legend("")
Run Code Online (Sandbox Code Playgroud)

我意识到它实际上是我需要的猫图,因此我将代码修改为以下内容:

plot = sns.catplot (data=tips,
             x="day",
             y="tip",
             kind='bar',
             ci=50,
             hue="sex",
             palette="Accent")
plot.set_title("Value of Tips Given to Waiters, by Days of the Week and Sex", fontsize=24, pad=30, fontdict={"weight": "bold"})
plot.legend("")
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下标题错误消息:'AttributeError:'FacetGrid' object has no attribute 'set_title''。

为什么我的标题不适用于猫图?

python seaborn

5
推荐指数
1
解决办法
7005
查看次数

使用逻辑回归时sklearn重要特征错误

以下代码使用随机森林模型为我提供一个显示特征重要性的图表:

from sklearn.feature_selection import SelectFromModel
import matplotlib

clf = RandomForestClassifier()
clf = clf.fit(X_train,y_train)
clf.feature_importances_  
model = SelectFromModel(clf, prefit=True)
test_X_new = model.transform(X_test)

matplotlib.rc('figure', figsize=[5,5])
plt.style.use('ggplot')

feat_importances = pd.Series(clf.feature_importances_, index=X_test.columns)
feat_importances.nlargest(20).plot(kind='barh',title = 'Feature Importance')
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

然而,我需要对逻辑回归模型做同样的事情。以下代码会产生错误:

from sklearn.feature_selection import SelectFromModel
import matplotlib

clf = LogisticRegression()
clf = clf.fit(X_train,y_train)
clf.feature_importances_  
model = SelectFromModel(clf, prefit=True)
test_X_new = model.transform(X_test)

matplotlib.rc('figure', figsize=[5,5])
plt.style.use('ggplot')

feat_importances = pd.Series(clf.feature_importances_, index=X_test.columns)
feat_importances.nlargest(20).plot(kind='barh',title = 'Feature Importance')
Run Code Online (Sandbox Code Playgroud)

我明白了

AttributeError: 'LogisticRegression' object has no attribute 'feature_importances_'
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我哪里出错了吗?

python classification scikit-learn

4
推荐指数
1
解决办法
6487
查看次数

标签 统计

python ×2

classification ×1

scikit-learn ×1

seaborn ×1