| |
| """ |
| 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: |
| |
| predictor = StoxChaiStockPredictor() |
| |
| |
| available_models = predictor.get_available_models() |
| print(f"โ
Found {len(available_models)} models: {', '.join(available_models)}") |
| |
| |
| sample_features = [ |
| 100.0, |
| 105.0, |
| 98.0, |
| 102.0, |
| 100.0, |
| 7.0, |
| 2.0, |
| 2.0, |
| 1.5, |
| 101.0, |
| 100.5, |
| 0.01, |
| 1000.0, |
| 1.2, |
| 1200.0, |
| 120000.0 |
| ] |
| |
| 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}") |
| |
| |
| 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}") |
| |
| |
| 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}") |
| |
| |
| 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) |
|
|