Kaggle Example Setup
Relevant source files
The following files were used as context for generating this wiki page:
The Kaggle Example Setup within AlphaPy provides a standardized configuration template for participating in machine learning competitions, specifically illustrated through a Titanic-style classification problem. It leverages the core AlphaPy pipeline to automate feature engineering, model selection, and the generation of submission files.
The setup utilizes a model.yml configuration file to define project metadata, data handling procedures, feature transformations, and ensemble modeling strategies. By integrating multiple algorithms such as CatBoost, Keras, LightGBM, and XGBoost, the setup demonstrates AlphaPy's ability to handle complex classification tasks with automated grid searching and recursive feature elimination.
Sources: alphapy/examples/Kaggle/config/model.yml:1-74, alphapy/model.py:108-164
Pipeline Architecture and Data Flow
The Kaggle example follows the standard AlphaPy training pipeline. It begins by loading data according to the specifications in model.yml, applying transformations, and then iterating through a list of specified algorithms to find the best performing model.
The diagram above shows the sequential flow from configuration to the final output of submission files and diagnostic plots.
Sources: alphapy/main.py:75-224, alphapy/model.py:1015-1052
Project Configuration
The model.yml for the Kaggle example defines how the system interacts with the dataset and where outputs are stored.
Project and Data Specifications
| Parameter | Value | Description |
|---|---|---|
directory | . | Current working directory for project files |
file_extension | csv | Format of input and output data files |
submission_file | gender_submission | Template file name for Kaggle submissions |
target | Survived | The column to be predicted |
split | 0.4 | Proportion of data used for testing |
Sources: alphapy/examples/Kaggle/config/model.yml:1-19
Model and Algorithm Settings
The Kaggle setup is configured as a classification type project using a multi-algorithm approach.
- Algorithms: The setup employs a suite of high-performance gradient boosting and neural network libraries:
CATB(CatBoost),KERASC(Keras Classifier),LGB(LightGBM), andXGB(XGBoost). - Scoring: Optimization is driven by the
roc_auc(Area Under the Receiver Operating Characteristic Curve) metric. - Feature Selection: Uses Recursive Feature Elimination (
rfe) with a step of 3. - Grid Search: Iterative random search is enabled with 50 iterations to optimize hyperparameters.
Sources: alphapy/examples/Kaggle/config/model.yml:21-43, alphapy/estimators.py:151-177
Feature Engineering and Transformations
The Kaggle example utilizes AlphaPy's automated feature engineering capabilities to enhance the raw dataset.
Transformation Suite
The setup enables several advanced feature generation techniques:
- Clustering: Automatically generates cluster-based features with increments of 3 (from 3 to 30 clusters).
- Encoding: Uses
targetencoding for categorical variables with a rounding precision of 2. - Factors: Identifies specific columns like
Embarkedas categorical factors. - Scaling: Applies
standardscaling to features to normalize the input for algorithms like Keras. - N-Grams: Text features are processed using 2-grams (bigrams).
Sources: alphapy/examples/Kaggle/config/model.yml:45-74, alphapy/model.py:228-285
Results and Output Generation
Upon completion of the pipeline, the Kaggle setup produces several artifacts in the output and plots directories.
Submission File Logic
If submission_file is defined in the config, the system reads the template and populates the prediction column with results from the BEST estimator.
# From alphapy/model.py
if submission_file:
sample_spec = PSEP.join([submission_file, extension])
sample_input = SSEP.join([input_dir, sample_spec])
ss = pd.read_csv(sample_input)
if submit_probas and model_type == ModelType.classification:
ss[ss.columns[1]] = probas
else:
ss[ss.columns[1]] = preds
submission_base = USEP.join(['submission', timestamp])
# ... saves to output directory
Sources: alphapy/model.py:1040-1052
Visualization
The setup is configured to generate a full suite of diagnostic plots to evaluate model performance:
- Calibration Plots: To check the reliability of predicted probabilities.
- Confusion Matrix: To visualize classification errors.
- Feature Importances: To identify which variables contributed most to the prediction.
- Learning Curves: To diagnose bias and variance.
- ROC Curves: To visualize the trade-off between true positive and false positive rates.
Sources: alphapy/examples/Kaggle/config/model.yml:81-86, alphapy/plots.py:129-152
Summary
The Kaggle Example Setup demonstrates a robust implementation of the AlphaPy framework for competitive data science. By combining advanced algorithms with automated feature engineering and systematic hyperparameter tuning, it provides a template that minimizes manual intervention while maximizing predictive performance. The architecture ensures that models are not only trained but also thoroughly evaluated and formatted correctly for submission to platforms like Kaggle.