python - 我如何在 python 中绘制训练结果
问题描述
我对python相当陌生,我正在尝试在图表中绘制训练集结果和测试集结果
此图显示了比较 y_test 和 y_predicted 的结果。我用下面的代码来绘制这个
fig, ax = plt.subplots(figsize=(10,5))
ax.plot(range(len(y_test)), y_test, '-b',label='Actual')
ax.plot(range(len(y_pred)), y_pred, 'r', label='Predicted')
plt.show()
现在我想为我的训练数据提供完全相同的图表。我如何生成这个?
解决方案
示例:使用随机森林
clf = RandomForestClassifier(max_depth=5,random_state=0)
clf.fit(train_x,train_y)
pred_random = clf.predict(test_x)
pred_random2 = clf.predict(train_x)
用于绘制测试图
plt.figure(figsize=(6, 10))
ax1 = sns.distplot(test_y, hist=False, color="r", label="Actual Value")
sns.distplot(pred_random, hist=False, color="b", label="Fitted Values" , ax=ax1)
plt.title('DIST PLOT Random Forest')
plt.xlabel('')
plt.ylabel('')
plt.show()
plt.close()
用于绘制火车图
plt.figure(figsize=(6, 10))
ax1 = sns.distplot(train_y, hist=False, color="r", label="Actual Value")
sns.distplot(pred_random2, hist=False, color="b", label="Fitted Values" , ax=ax1)
plt.title('DIST PLOT Random Forest')
plt.xlabel('')
plt.ylabel('')
plt.show()
plt.close()
推荐阅读
- java - Java链表添加方法
- go - 无法在golang中将函数声明为主函数之外的变量
- java - Java - 方法继承的问题覆盖
- javascript - 将 javascript 元素背景图像设置为等于下载 url
- c# - 如何将此 json 转换为字符串并获取“id”属性的值
- mysql - Spring Boot 应用程序与 Docker mysql 服务器用户连接
- php - PHP无法从数据库中获取更大的数据
- visual-studio-code - VS代码在鼠标不在时模糊
- c# - 启用 VPN 后,外部 IP 地址不会改变
- sql - 从 SQL 表中选择标记为 X 或 Y 的记录,但不选择同时具有 X 和 Y 的记录