Scale the data before learning to normalize the output

This commit is contained in:
2026-02-18 18:33:21 -08:00
parent a81e3a992d
commit 7a4fc2cda4
7 changed files with 240 additions and 212 deletions
+13 -2
View File
@@ -1,5 +1,6 @@
import os
import json
import joblib
import numpy as np
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
import yfinance as yf
@@ -31,11 +32,21 @@ def Predict():
# Verify it loaded correctly
reconstructed_model.summary()
# Load the scalers
feature_scaler = joblib.load(os.path.join(DATA_DIR, "feature_scaler.pkl"))
target_scaler = joblib.load(os.path.join(DATA_DIR, "target_scaler.pkl"))
# Scale the data
scaled_data = feature_scaler.transform(df)
# Predict
predictions = reconstructed_model.predict(df)
scaled_predictions = reconstructed_model.predict(scaled_data)
# Use the loaded target scaler to get back to % change
actual_prediction = target_scaler.inverse_transform(scaled_predictions)
# 'predictions' will be a 2D array, flatten it if you want a simple list
flat_predictions = predictions.flatten().tolist()
flat_predictions = actual_prediction.flatten().tolist()
print(f"Predicted Target_Close: {flat_predictions}")