股票价格数据的回归代码片段-
forecast_col='Adj. Close'
forecast_out=int(math.ceil(0.01*len(df)))
df['label']=df[forecast_col].shift(-forecast_out)
X=X[:-forecast_out+1]
X=X[:-forecast_out+1] 是什么意思?
这是切片索引的情况,也使用负索引。这意味着X
的最后forecast_out + 1
元素被丢弃。例如
>>> my_list = [1, 2, 3, 4, 5]
>>> my_list[:-2]
[1, 2, 3]