Predicting stock prices with the three regression algorithms
Here are the steps to predict the stock price:
- Earlier, we generated features based on data from 1988 to 2019, and we will now continue with constructing the training set with data from 1988 to 2018 and the testing set with data from 2019:
>>> data_raw = pd.read_csv('19880101_20191231.csv', index_col='Date') >>> data = generate_features(data_raw) >>> start_train = '1988-01-01' >>> end_train = '2018-12-31' >>> start_test = '2019-01-01' >>> end_test = '2019-12-31' >>> data_train = data.loc[start_train:end_train] >>> X_train = data_train.drop('close', axis=1).values >>> y_train = data_train['close'].values >>> print(X_train.shape) (7558, 37) >>> print(y_train.shape) (7558,)
All fields in the
dataframe
data except...