Spaces:
No application file
No application file
stock model
Browse files- model_card.yaml +81 -0
- stock_forecasting.pkl +0 -0
model_card.yaml
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
model_name: "Stock Price Predictor (XGBoost)"
|
| 3 |
+
version: "1.0"
|
| 4 |
+
model_type: "XGBoost Regressor"
|
| 5 |
+
description: |
|
| 6 |
+
This model predicts future stock prices based on historical data.
|
| 7 |
+
It is trained on Google stock price data (2020-2025) and forecasts
|
| 8 |
+
the Adjusted Closing Price (`Adj Close`).
|
| 9 |
+
|
| 10 |
+
The model uses various stock indicators (Open, Close, High, Low, Volume)
|
| 11 |
+
and time-based features (Year, Day, Month, Weekday) with cyclic encoding.
|
| 12 |
+
|
| 13 |
+
**Ideal Use Case**: Time-series forecasting for stock prices.
|
| 14 |
+
|
| 15 |
+
license: "MIT"
|
| 16 |
+
dataset:
|
| 17 |
+
name: "Stock Price Data (2020-2025)"
|
| 18 |
+
source: "Kaggle - https://www.kaggle.com/datasets/mzohaibzeeshan/google-stock-price-data-2020-2025-googl"
|
| 19 |
+
|
| 20 |
+
architecture:
|
| 21 |
+
framework: "XGBoost"
|
| 22 |
+
encoding: "Sin-Cos Encoding for Month/Weekday, One-Hot Encoding for categorical data"
|
| 23 |
+
|
| 24 |
+
metrics:
|
| 25 |
+
MAE: 0.212
|
| 26 |
+
RMSE: 0.357
|
| 27 |
+
R2_Score: 0.9998
|
| 28 |
+
|
| 29 |
+
deployment:
|
| 30 |
+
- huggingface: "https://huggingface.co/your_username/google-stock-predictor"
|
| 31 |
+
- github: "https://github.com/your_username/google-stock-predictor"
|
| 32 |
+
- api: "FastAPI/Gradio"
|
| 33 |
+
|
| 34 |
+
usage:
|
| 35 |
+
installation: |
|
| 36 |
+
# Install dependencies
|
| 37 |
+
pip install xgboost pandas numpy joblib transformers torch
|
| 38 |
+
load_model_torch: |
|
| 39 |
+
import joblib
|
| 40 |
+
import torch
|
| 41 |
+
|
| 42 |
+
model = joblib.load("xgboost_stock_model.pkl")
|
| 43 |
+
|
| 44 |
+
def predict_stock_price(features):
|
| 45 |
+
features = torch.tensor(features, dtype=torch.float32)
|
| 46 |
+
prediction = model.predict(features.numpy().reshape(1, -1))
|
| 47 |
+
return prediction[0]
|
| 48 |
+
|
| 49 |
+
sample_input = [200.5, 201.2, 199.8, 200.0, 1500000, 2025, 1, 0.0, 1.0, 0.5, 0.866]
|
| 50 |
+
predicted_price = predict_stock_price(sample_input)
|
| 51 |
+
print(f"📈 Predicted Stock Price: {predicted_price}")
|
| 52 |
+
load_model_transformers: |
|
| 53 |
+
from transformers import PreTrainedModel, PretrainedConfig
|
| 54 |
+
import joblib
|
| 55 |
+
import torch
|
| 56 |
+
|
| 57 |
+
model = joblib.load("xgboost_stock_model.pkl")
|
| 58 |
+
|
| 59 |
+
class StockPricePredictorConfig(PretrainedConfig):
|
| 60 |
+
model_type = "xgboost_stock_predictor"
|
| 61 |
+
|
| 62 |
+
class StockPricePredictor(PreTrainedModel):
|
| 63 |
+
config_class = StockPricePredictorConfig
|
| 64 |
+
|
| 65 |
+
def __init__(self, config):
|
| 66 |
+
super().__init__(config)
|
| 67 |
+
self.model = model
|
| 68 |
+
|
| 69 |
+
def forward(self, input_features):
|
| 70 |
+
input_features = input_features.numpy().reshape(1, -1)
|
| 71 |
+
prediction = self.model.predict(input_features)
|
| 72 |
+
return torch.tensor(prediction, dtype=torch.float32)
|
| 73 |
+
|
| 74 |
+
config = StockPricePredictorConfig()
|
| 75 |
+
predictor = StockPricePredictor(config)
|
| 76 |
+
|
| 77 |
+
sample_input = torch.tensor([[200.5, 201.2, 199.8, 200.0, 1500000, 2025, 1, 0.0, 1.0, 0.5, 0.866]], dtype=torch.float32)
|
| 78 |
+
predicted_price = predictor.forward(sample_input)
|
| 79 |
+
print(f"📈 Predicted Stock Price (Transformers): {predicted_price.item()}")
|
| 80 |
+
|
| 81 |
+
---
|
stock_forecasting.pkl
ADDED
|
Binary file (274 kB). View file
|
|
|