This project implements a regression model to predict a target variable based on 53 anonymized features.
-
Clone this repository:
git clone https://github.com/your-username/tabular-regression-project.git cd tabular-regression-project -
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate` -
Install the required packages:
pip install -r requirements.txt
data/: Contains the training and test datasetsnotebooks/: Jupyter notebook with exploratory data analysissrc/: Python scripts for training and predictionrequirements.txt: List of required Python packagesREADME.md: This filepredictions.csv: File with prediction results (generated after running predict.py)model_results.csv: CSV file containing performance metrics for different models
-
Exploratory Data Analysis:
- Open and run the Jupyter notebook in the
notebooks/directory.
- Open and run the Jupyter notebook in the
-
Train the model:
python src/train.py -
Make predictions:
python src/predict.py
The predictions will be saved in predictions.csv in the project root directory.
The current implementation trains and evaluates multiple regression models:
- Linear Regression
- Lasso Regression
- Ridge Regression
- Random Forest Regressor
These models are trained on two different feature sets:
- All available features
- Only features 6 and 7
The training process involves the following steps:
- Data loading and preprocessing
- Splitting the data into training and validation sets
- Feature scaling using StandardScaler
- Training each model using cross-validation
- Evaluating models on the validation set
- Selecting the best-performing model based on validation RMSE
The models are evaluated using Root Mean Square Error (RMSE) on both the training (via cross-validation) and validation sets. RMSE is calculated and logged during the training process, providing a measure of the average prediction error in the same units as the target variable.
The performance metrics for each model are saved in model_results.csv. Here's a summary of the results:
| Model | Mean CV RMSE | Std CV RMSE | Validation RMSE | Description |
|---|---|---|---|---|
| Linear Regression | 28.8866 | 0.0253 | 29.0154 | Using all features |
| Lasso | 28.8709 | 0.0239 | 29.0038 | Using all features |
| Ridge | 28.8866 | 0.0253 | 29.0154 | Using all features |
| Random Forest | 0.0049 | 0.0001 | 0.0038 | Using all features |
| Linear Regression | 28.8716 | 0.0233 | 29.0000 | Using only features 6 and 7 |
| Lasso | 28.8709 | 0.0239 | 29.0038 | Using only features 6 and 7 |
| Ridge | 28.8716 | 0.0233 | 29.0000 | Using only features 6 and 7 |
| Random Forest | 0.0020 | 0.0000 | 0.0016 | Using only features 6 and 7 |
-
Performance comparison:
- The Random Forest model significantly outperforms all other models, achieving much lower RMSE values.
- Linear models (Linear Regression, Lasso, and Ridge) perform similarly, with RMSE values around 29.
-
Feature set comparison:
- For linear models, using only features 6 and 7 yields slightly better results than using all features.
- For the Random Forest model, using only features 6 and 7 provides even better results than using all features.
-
Best performing model:
- The Random Forest model using only features 6 and 7 achieves the lowest Validation RMSE of 0.0016, making it the best-performing model in this experiment.
-
Consistency:
- The Random Forest model shows very low standard deviation in cross-validation RMSE, indicating consistent performance across different subsets of the data.
-
Overfitting consideration:
- The extremely low RMSE values for the Random Forest model might indicate potential overfitting. Further investigation and possibly regularization techniques may be needed to ensure generalization.
Based on these results, the Random Forest model using only features 6 and 7 is selected as the best model for this regression task. However, it's important to monitor its performance on unseen data to ensure it generalizes well.
This project implements multiple classifiers for the MNIST handwritten digit dataset using different algorithms.
Run the main script:
python src/mnist_classifier.py
-
The code defines an abstract base class
DigitClassificationInterfacethat serves as an interface for all classifier models. -
Three classifier models are implemented, each inheriting from
DigitClassificationInterface:CNNModel: A Convolutional Neural Network using TensorFlow/KerasRandomForestModel: A Random Forest classifier using scikit-learnRandomModel: A model that makes random predictions
-
The
DigitClassifierclass acts as a facade, allowing the user to choose which algorithm to use by specifying 'cnn', 'rf', or 'rand'. -
The script loads and preprocesses the MNIST dataset, then trains and evaluates each classifier.
Here are the results from running the script:
CNN accuracy: 0.9891
RF accuracy: 0.9689
RAND accuracy: 0.0995
- The CNN model achieves the highest accuracy at 98.91%.
- The Random Forest model also performs well with 96.89% accuracy.
- As expected, the Random model performs poorly with about 10% accuracy (close to random guessing for 10 classes).
- Both CNN and RF correctly predict the first test image as 7.
These results demonstrate the effectiveness of both the CNN and Random Forest approaches for the MNIST digit classification task, with the CNN slightly outperforming the Random Forest model.