bukosabino / btctrading

Time Series Forecast with Bitcoin value, to detect upward/down trends with Machine Learning Algorithms
MIT License
155 stars 46 forks source link

Predict Next Row #7

Closed slavakurilyak closed 6 years ago

slavakurilyak commented 7 years ago

I'm trying to predict the next row in the dataframe. Please correct me if I'm wrong.

# Predict Next Row

last_row = df.tail(1)

predict_next_row = xgb.DMatrix(last_row[cols])

prediction = model.predict(predict_next_row)

prediction_value = prediction.tolist()[0]

if prediction_value == 1.0:
    print("Prediction: UP")
elif prediction_value == 2.0:
    print("Prediction: DOWN")
else: # 0.0
    print("Prediction: KEEP")
bukosabino commented 7 years ago

No. You need add a new row after you read csv file to predict the future. Something like this:

# Add next row
last_timestamp = df['Timestamp'].iloc[-1]
if settings.PERIOD == 'Hourly':
    next_timestamp = last_timestamp + 3600
df_next = pd.DataFrame([next_timestamp], columns=['Timestamp'])
df = df.append(df_next, ignore_index=True)
df.iloc[-1] = df.iloc[-1].fillna(1)

Then you can use split_df() with settings.NTESTS = 1.

You can check a new notebook 'XGBoost_next_row'.