✅ Classification Model (Logistic Regression)
- Predicts: UP (1) or DOWN (0)
- Output: Binary class
- File:
data/model_YYYYMMDD_HHMMSS.pkl - Test Accuracy: ~56%
✅ Regression Model (Lasso/Ridge/Random Forest/etc.)
- Predicts: Actual return percentage
- Output: Continuous value (e.g., +2.5%, -1.3%)
- File:
data/regression_model_YYYYMMDD_HHMMSS.pkl - Test RMSE: ~2.5% error
python main.py train --use-real-dataThis trains logistic regression and identifies important features.
# Use top 15 features from logistic regression
python train_regression.py --top-features 15
# Or try different amounts
python train_regression.py --top-features 10 # Fewer features
python train_regression.py --top-features 20 # More featuresThe script automatically trains and compares:
- Linear Regression - Simple baseline
- Ridge Regression - L2 regularization (prevents overfitting)
- Lasso Regression - L1 regularization (feature selection)
- Random Forest - Ensemble of decision trees
- Gradient Boosting - Boosted trees
Best model is automatically selected and saved.
RMSE (Root Mean Squared Error): 0.0251 = 2.51%
- Average prediction error
- Lower is better
- Your model's predictions are off by ~2.5% on average
MAE (Mean Absolute Error): 0.0200 = 2.00%
- Typical error (less sensitive to outliers)
- Lower is better
- Typical prediction is off by ~2%
R² (R-squared): -0.0308 = -3.1%
- How much variance the model explains
- Range: -∞ to 1.0 (1.0 = perfect)
- Negative = model worse than just predicting the mean
- Your model needs improvement!
Your model is essentially predicting ~0.30% return for everything, which is just the average. This means:
- Features aren't predictive enough
- Model is too simple
- Need more/better features OR different approach
python train_regression.py --top-features 30Edit src/features/build_features.py and add:
- Volume indicators (OBV, VWAP)
- More technical indicators
- Market sentiment (VIX, put/call ratio)
- Sector performance
- Macro indicators (interest rates, unemployment)
The script already tests multiple models. Random Forest and Gradient Boosting can capture non-linear patterns.
Edit train_regression.py to tune:
Ridge(alpha=...)- Try 0.1, 1.0, 10.0RandomForest(n_estimators=..., max_depth=...)- More trees, deeper treesGradientBoosting(learning_rate=..., n_estimators=...)
Instead of raw features, create:
- Feature ratios (e.g., close / sma_50)
- Feature differences (e.g., rsi - rsi_lag_1)
- Interaction terms (e.g., sentiment * volatility)
import pickle
import pandas as pd
# Load
with open('data/regression_model_20251201_195918.pkl', 'rb') as f:
model_data = pickle.load(f)
# Components
model = model_data['model'] # Trained Lasso
scaler = model_data['scaler'] # StandardScaler
features = model_data['feature_names'] # List of 15 features
metrics = model_data['metrics'] # RMSE, MAE, R²# Prepare new data with same 15 features
new_data = pd.DataFrame({
'bb_upper': [200.5],
'bb_lower': [195.2],
'close': [197.8],
# ... all 15 features
})
# Scale and predict
scaled_data = scaler.transform(new_data[features])
predicted_return = model.predict(scaled_data)
print(f"Predicted 5-day return: {predicted_return[0]:.2%}")
# Example: "Predicted 5-day return: +2.34%"data/
├── model_*.pkl # Classification models (UP/DOWN)
├── regression_model_*.pkl # Regression models (price prediction)
├── processed/modeling_dataset.csv # Combined dataset
└── model_weights.csv # Feature importance from logistic regression
- ✅ You have the framework working
⚠️ Model performance needs improvement (R² negative)- 🔄 Try these in order:
- Add more features (--top-features 30)
- Engineer better features (ratios, interactions)
- Tune hyperparameters
- Try neural networks (advanced)
# 1. Collect data
python collect_real_data.py --ticker QQQ --start 2015-01-01 --end 2024-12-31
# 2. Train classification for feature selection
python main.py train --use-real-data
# 3. Check feature importance
python view_model_weights.py
# 4. Train regression with top features
python train_regression.py --top-features 20
# 5. Compare different feature counts
python train_regression.py --top-features 10
python train_regression.py --top-features 30
# 6. Pick best model and use for predictions| Model Type | Output | Metric | Performance |
|---|---|---|---|
| Logistic Regression | UP/DOWN (0/1) | Accuracy | 55.7% |
| Lasso Regression | Return % | RMSE | 2.51% |
| Lasso Regression | Return % | R² | -3.1% (needs improvement) |
The classification model works okay (better than random 50%), but the regression model needs tuning or better features!