Sir, Please Help
I make this code from following tutorial on youtube
It supposed to predict price on stock or forex market.
I write the code from the tutorial, but somehow after finish with the video, i click run and no price pop up on my pycharm console on the botom
I really want to visualize it and print out the prediction price number
How can i do that?
Sorry for any misspeling, english is not my first language
bellow the code i write
I make this code from following tutorial on youtube
It supposed to predict price on stock or forex market.
I write the code from the tutorial, but somehow after finish with the video, i click run and no price pop up on my pycharm console on the botom
I really want to visualize it and print out the prediction price number
How can i do that?
Sorry for any misspeling, english is not my first language
bellow the code i write
from IPython.core.debugger import set_trace import pandas as pd import numpy as np import os import matplotlib.pyplot as plt import time plt.style.use(style="seaborn") df = pd.read_csv("LTCUSDHour.csv") df = df [["Close"]].copy() #print(df.head() df["Target"] = df.Close.shift(-1) df.dropna(inplace=True) #print(df.head()) # Train Test Split def train_test_split(data, perc): data = data.values n = int(len(data) * (1 - perc)) return data [:n], data [n:] train, test = train_test_split(df, 0.2) X = train[:, :-1] Y = train[:, -1] from xgboost import XGBRegressor model = XGBRegressor(objective=r"reg:squarederror", n_estimators=1000) model.fit(X, Y) test[0] val = np.array(test[0, 0]).reshape(1, -1) pred = model.predict(val) #to Predict def xgb_predict(train, val): train = np.array(train) X, Y = train[:, :-1], train[:, -1] model = XGBRegressor(objective=r"reg:squarederror", n_estimators=1000) model.fit(X, Y) val = np.array(val).reshape(1, -1) pred = model.predict(val) return pred[0] xgb_predict(train, test[0, 0]) from sklearn.metrics import mean_squared_error def validate(data, perc): predictions = [] train, test = train_test_split(data, perc) history = [x for x in train] for i in range(len(test)): test_X, test_Y = test[i, :-1], test[i, -1] pred = xgb_predict(history, test_X[0]) predictions.append(pred) history.append(test[i]) error = mean_squared_error(test[:, -1], predictions, squared=False) return error, test[:, -1], predictions time rmse, Y, pred = validate(df, 0.2) print(rmse)
buran write Jan-17-2021, 01:28 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.