Spaces:
Sleeping

MrBro123 commited on
Commit
7c500bc
·
verified ·
1 Parent(s): e384e9d

Delete model_engine.py

Browse files
Files changed (1) hide show
  1. model_engine.py +0 -38
model_engine.py DELETED
@@ -1,38 +0,0 @@
1
- import numpy as np
2
- from sklearn.linear_model import LogisticRegression
3
- from sklearn.preprocessing import StandardScaler
4
-
5
- class TradingModel:
6
- def __init__(self):
7
- self.scaler = StandardScaler()
8
- self.model = LogisticRegression(random_state=42, max_iter=1000)
9
-
10
- def train(self, X_train, y_train):
11
- # Flatten 3D sequences into 2D for scikit-learn
12
- n_samples, window_size, n_features = X_train.shape
13
- X_flat = X_train.reshape(n_samples, window_size * n_features)
14
-
15
- # Scale features
16
- X_scaled = self.scaler.fit_transform(X_flat)
17
-
18
- # Train model
19
- self.model.fit(X_scaled, y_train)
20
-
21
- def predict(self, X):
22
- # Flatten and scale
23
- n_samples, window_size, n_features = X.shape
24
- X_flat = X.reshape(n_samples, window_size * n_features)
25
- X_scaled = self.scaler.transform(X_flat)
26
-
27
- # Return probability of positive class
28
- return self.model.predict_proba(X_scaled)[:, 1]
29
-
30
- def train_and_get_prediction(X_train, y_train, X_latest):
31
- """
32
- Utility function to quickly train on historical data and predict next movement.
33
- """
34
- tm = TradingModel()
35
- tm.train(X_train, y_train)
36
-
37
- pred = tm.predict(X_latest)
38
- return pred[0]