stoxchai-nse-predictor / test_inference.py
thoutam's picture
Upload test_inference.py with huggingface_hub
a6f32f6 verified
#!/usr/bin/env python3
"""
Test script for Hugging Face compatible models
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from inference import StoxChaiStockPredictor
def test_models():
"""Test all models with sample data"""
print("๐Ÿงช Testing Hugging Face Models")
print("=" * 50)
try:
# Initialize predictor
predictor = StoxChaiStockPredictor()
# Check available models
available_models = predictor.get_available_models()
print(f"โœ… Found {len(available_models)} models: {', '.join(available_models)}")
# Sample features (16 features in order)
sample_features = [
100.0, # OpnPric
105.0, # HghPric
98.0, # LwPric
102.0, # LastPric
100.0, # PrvsClsgPric
7.0, # Price_Range
2.0, # Price_Change
2.0, # Price_Change_Pct
1.5, # Volume_Price_Ratio
101.0, # SMA_5
100.5, # SMA_20
0.01, # Price_Momentum
1000.0, # Volume_MA
1.2, # Volume_Ratio
1200.0, # TtlTradgVol
120000.0 # TtlTrfVal
]
print(f"\n๐Ÿ“Š Testing with sample features:")
feature_names = predictor.get_feature_names()
for i, (name, value) in enumerate(zip(feature_names, sample_features)):
print(f" {i+1:2d}. {name:20s}: {value:8.2f}")
# Test individual models
print(f"\n๐ŸŽฏ Testing individual models:")
for model_name in available_models:
try:
pred = predictor.predict(sample_features, model_name, lookback_days=5)
print(f" โœ… {model_name:15s}: โ‚น{pred:8.2f}")
except Exception as e:
print(f" โŒ {model_name:15s}: Error - {e}")
# Test ensemble prediction
print(f"\n๐Ÿ”ฎ Testing ensemble prediction:")
all_preds = predictor.predict_all_models(sample_features, lookback_days=5)
successful_predictions = []
for model, pred in all_preds.items():
if pred is not None and model != 'ensemble':
successful_predictions.append(pred)
print(f" โœ… {model:15s}: โ‚น{pred:8.2f}")
if 'ensemble' in all_preds and all_preds['ensemble'] is not None:
print(f" ๐ŸŽฏ Ensemble: โ‚น{all_preds['ensemble']:8.2f}")
# Show model info
print(f"\n๐Ÿ“‹ Model Information:")
model_info = predictor.get_model_info()
for model_name, info in model_info.items():
print(f" {model_name:15s}: {info['type']} with {info['features']} features")
print(f"\n๐ŸŽ‰ All tests completed successfully!")
return True
except Exception as e:
print(f"โŒ Test failed: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
success = test_models()
sys.exit(0 if success else 1)