-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] ?

Ashish Choudhary
  • 181
  • 1
  • 2
  • 11

1 Answers1

0

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]
Jonas Adler
  • 10,365
  • 5
  • 46
  • 73