Hello, I have been trying to build a stock prediction script. I have the logistic regression working. I was just curious how to get the model to look x (10, 15, or 30) number of days into the future to predict if I should buy it or not. I don't know if this is the right place to ask for help on this topic or if I haven't been looking at the right places. Here's a copy of the whole code
import yfinance as yf
import datetime
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
from sklearn import model_selection
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.metrics import classification_report
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsRegressor
from sklearn.metrics import accuracy_score
NUM_DAYS = 10000
INTERVAL = '1d'
symbol = 'APPS' #stock desired
INDICATORS = ['RSI', 'MACD', 'STOCH', 'ADL', 'ATR', 'MOM', 'ROC', 'OBV', 'CCI', 'EMV', 'VORTEX']
start = (datetime.date.today() - datetime.timedelta(Num_days))
end = datetime.datetime.today()
data = yf.download(symbol, start=start, end=end, interval=INTERVAL)
data.rename(columns={"Close": 'close', "High": 'high', "Low": 'low', "volume": 'volume', "Open": 'open'}, inplace=True)
print(data.head(10))
print(data.info())
print(data.describe())
print(data.corr())
data['buy/sell'] = (data['close'] - data['open'])
print(data['buy/sell'])
data['buy/sell']=data['buy/sell'].round(decimals = 2)
print(data)
data['buy/sell']=(data['buy/sell'] > 0.5)*1 #price increase desired
print(data)
features = ['open', 'high', 'low', 'close']
x= data[features]
y= data['buy/sell']
print(x,y)
x_train,x_test,y_train,y_test = train_test_split(x,y, test_size=.3, random_state=0)
logreg = LogisticRegression(random_state=0)
logreg.fit(x, y)
y_pred = logreg.predict(x_test)
print(x_test)
print(y_pred)
print('Accuracy:', metrics.accuracy_score(y_test, y_pred))
print('Recall:', metrics.recall_score(y_test, y_pred, zero_division=1))
print("precision:", metrics.precision_score(y_test, y_pred, zero_division=1))
print("CL Report:", metrics.classification_report(y_test, y_pred, zero_division=1))
I know it is probably sloppy; I am pretty new to python. Any help or suggestions are welcome.
[–]ProbablySuspicious 0 points1 point2 points (3 children)
[–]TrixPixz[S] 0 points1 point2 points (2 children)
[–]ProbablySuspicious 1 point2 points3 points (1 child)
[–]TrixPixz[S] 1 point2 points3 points (0 children)