【问题标题】:plotting train_test_split while maintining their indices在维护索引的同时绘制 train_test_split
【发布时间】:2018-02-13 22:21:31
【问题描述】:

我正在尝试在维护索引的同时绘制 train_test _split,这是我的代码。

#df.insert(0, 'x', range(0, 0 + len(df)))

X_train, X_test, y_train, y_test = train_test_split(x, y,
                                             test_size = .1)

regressor = RandomForestClassifier()

regressor.fit(X_train, y_train)

y_pred = regressor.predict(X_test)

plt.plot(X_train,y_pred_train,'bo')


plt.show()

似乎 y_pred 正在针对不正确的 x_axis 值进行绘图,因为数据中间存在巨大差距并且有些重叠

如何使 y_predy_pred_train 对应的 x_value 位于数据框中的原始位置。

【问题讨论】:

  • X_test代替df[x]怎么样?
  • 请分享一些您的数据样本
  • 然后分享生成这些的代码
  • @VivekKumar 检查新更新

标签: python matlab plot machine-learning scikit-learn


【解决方案1】:

您需要在图中包含索引。通常 y 将表示为每个点的颜色。这是怎么做的

plt.scatter(X_test.index,X_test.values,c=y_predict_test)
plt.show()

这是一个随机的例子

黄色的点属于0类,紫色的点属于1类

【讨论】:

  • 这里的 c 代表什么? @sgDysregulation
  • c 代表颜色,它基本上根据 y 中的值为每个点分配颜色
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-05-07
  • 2011-04-15
  • 1970-01-01
  • 1970-01-01
  • 2020-05-23
  • 2020-07-14
相关资源
最近更新 更多