【问题标题】:how do i plot training results in python我如何在 python 中绘制训练结果
【发布时间】:2020-07-01 16:19:08
【问题描述】:

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

现在我想为我的训练数据提供完全相同的图表。我如何生成这个?

【问题讨论】:

  • 使用训练数据训练模型并使用训练数据进行测试并绘制图形:)
  • @ZestyDragon 你能举个例子吗?

标签: python pandas matplotlib


【解决方案1】:

示例:使用随机森林

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

【讨论】:

    猜你喜欢
    • 2021-08-06
    • 1970-01-01
    • 2020-09-10
    • 1970-01-01
    • 2020-11-01
    • 2019-09-07
    • 2023-04-08
    • 2015-07-19
    • 1970-01-01
    相关资源
    最近更新 更多