训练和测试拆分后的数据索引

时间:2018-12-05 18:04:26

标签: python matplotlib data-science train-test-split

伙计们,我是数据科学和Python的新手。我正在研究回归问题。我的问题是,当我试图绘制目标变量的测试部分时,会得到奇怪的绘图类型

from sklearn.model_selection import train_test_split
train_input, test_input, train_target, test_target = 
train_test_split(features, target, test_size = 0.25, random_state = 42)
# Remove the labels from the dataset
plt.xlim(0,100)
plt.plot(test_target , 'g');

enter image description here

是因为附在test_target上的随机索引吗??

我怎么能得到像这样的连续曲线enter image description here

1 个答案:

答案 0 :(得分:0)

如果数据索引有问题,请使用:

df_train = df_train.reset_index()

如果要重置并将其设置为df的另一列,请说“ A”,然后执行:

df_train = df_train.reset_index().set_index('A')
相关问题