A snippet of regression code of a stock price data-
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]
What is the meaning of X=X[:-forecast_out+1] ?
A snippet of regression code of a stock price data-
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]
What is the meaning of X=X[:-forecast_out+1] ?
This is a case of slice indexing, and also uses negative indices. It means that the last forecast_out + 1
elements of X
are discared. For example,
>>> my_list = [1, 2, 3, 4, 5]
>>> my_list[:-2]
[1, 2, 3]