YAML Configuration System
Relevant source files
The following files were used as context for generating this wiki page:
The AlphaPy YAML Configuration System is the central mechanism for defining model parameters, data handling instructions, feature engineering pipelines, and specific domain workflows (MarketFlow and SportFlow). By utilizing YAML files, the framework allows users to declare complex machine learning specifications without modifying the underlying Python code.
The system is organized into specialized configuration files, primarily model.yml, algos.yml, market.yml, and sport.yml. These files are parsed into dictionary-based "specs" objects that drive the execution of the Model class and various processing pipelines.
Sources: alphapy/model.py:155-163, alphapy/market_flow.py:92-101, alphapy/sport_flow.py:171-180
Core Configuration Components
Model Configuration (model.yml)
The model.yml file is the primary configuration entry point. It is parsed by the get_model_config function to populate the model's technical specifications.
The diagram shows how model.yml is parsed into distinct functional categories within the specs dictionary.
Key sections defined in model.yml include:
- Project: Defines the working directory, file extensions (e.g., .csv), and submission file settings.
- Data: Configures feature selection, target variables, shuffling, and sampling methods (e.g.,
under_random). - Features: Controls complex transformations like PCA, Clustering, Scaling, and Interaction terms.
- Model: Specifies the algorithms to use (e.g., Random Forest 'RF', XGBoost 'XGB'), cross-validation folds, and scoring functions (e.g.,
roc_auc).
Sources: alphapy/model.py:155-265, alphapy/examples/Trading Model/config/model.yml:1-55
Algorithm Configuration (algos.yml)
The algos.yml file defines the specific hyperparameters and grid search spaces for individual machine learning algorithms. The get_algos_config function reads this file to initialize Estimator objects.
| Parameter Type | Description |
|---|---|
model_type | Defines if the algo is for classification, regression, or clustering. |
params | Static hyperparameters passed directly to the estimator constructor. |
grid | A dictionary of hyperparameter ranges used for hyper_grid_search. |
layers/compiler | Specific settings for Keras-based deep learning models. |
Sources: alphapy/estimators.py:170-220, alphapy/estimators.py:307-320
Domain-Specific Configurations
MarketFlow (market.yml)
MarketFlow extends the core configuration to handle financial time-series data. It introduces concepts like data fractals and forecast periods.
This flow represents the parsing of market-specific parameters for financial analysis.
Market-specific parameters include:
data_fractal: The time interval of data (e.g., '1d', '5m').lag_period: The number of periods to lag features.forecast_period: The forward-looking window for the target variable.target_group: The collection of symbols to be analyzed.
Sources: alphapy/market_flow.py:92-150, alphapy/market_flow.py:228-240
SportFlow (sport.yml)
SportFlow manages configurations for sports betting and game outcome predictions. It handles seasonal data and team-based statistics.
| Option | Description |
|---|---|
league | The identifier for the sports league (e.g., NCAAB). |
seasons | A list of seasons to include in the model training. |
rolling_window | The window size for calculating rolling team statistics. |
random_scoring | Boolean flag for testing the pipeline with random scores. |
Sources: alphapy/sport_flow.py:171-210, alphapy/sport_flow.py:530-545
Configuration Data Flow
The configuration system follows a strict hierarchical loading process. During initialization, the Model class is instantiated with a specs dictionary derived from these YAML files.
The sequence illustrates the synchronous loading and validation of configurations before the Model object is created.
Validation and Type Mapping
The parser validates configuration strings against internal AlphaPy Enums to ensure technical accuracy:
- Encoders: Mapped from strings like 'onehot' or 'target' to
Encodersenum values. - Scalers: Mapped from 'standard' or 'minmax' to
Scalersenum values. - ModelType: Mapped from 'classification' or 'regression' to
ModelTypeenum values.
Sources: alphapy/model.py:186-220, alphapy/globals.py:93-195
Implementation Details
Configuration Parsing Logic
The get_model_config function in alphapy/model.py serves as the primary engine for reading and flattening the nested YAML structure into a flat specs dictionary used throughout the pipeline.
# alphapy/model.py:173-181
full_path = SSEP.join([PSEP, 'config', 'model.yml'])
with open(full_path, 'r') as ymlfile:
cfg = yaml.load(ymlfile, Loader=yaml.FullLoader)
# Store configuration parameters in dictionary
specs = {}
specs['directory'] = cfg['project']['directory']
specs['extension'] = cfg['project']['file_extension']
Sources: alphapy/model.py:173-185
External Package Integration
The configuration system also detects and configures optional machine learning libraries based on the algorithms list in model.yml and the available environment. If XGB, LGB, or CATB are specified, the system attempts to load xgboost, lightgbm, or catboost respectively.
Sources: alphapy/estimators.py:136-168
Summary
The AlphaPy YAML Configuration System provides a robust, declarative interface for machine learning workflows. By separating model logic from parameter definition, it enables rapid experimentation across diverse domains such as finance and sports. The use of strict validation against internal Enums ensures that configuration errors are caught during the initial parsing phase, prior to data processing or model training.
Sources: alphapy/model.py:155-163, alphapy/market_flow.py:92-100