A Python package for performing classification on datasets.
Project description
classifierAgent: Machine Learning Classification Python Package
Overview
This Python package provides a comprehensive solution for performing classification tasks using various popular machine learning algorithms. It allows you to read a dataset, preprocess it, train multiple classifiers, perform hyperparameter tuning, and visualize model performance. Additionally, it provides options for scaling data, saving trained models, and customizing the output display.
Features
-
Classification Algorithms:
- Logistic Regression
- K-Nearest Neighbors
- Decision Tree
- Random Forest
- Gradient Boosting
- Support Vector Classifier
- Gaussian Naive Bayes
- Bernoulli Naive Bayes
-
Advanced Functionality:
- Data Scaling: Options for Min-Max Scaling or Standard Normalization.
- Hyperparameter Tuning: Option to perform Grid Search for finding the best model parameters.
- Model Persistence: Save and load trained models using
joblib
. - Visualization: Option to plot confusion matrices and detailed classification reports.
- Cross-Validation: Evaluate models using cross-validation scores.
- Configurable Outputs: Options to control the display of confusion matrices and classification reports.
-
Results:
- Returns a DataFrame with model names, accuracy, F1-score, and optionally the best hyperparameters.
Parameters
The package takes the following parameters as input:
dataset
: Path to the CSV or Excel dataset file or a pandas DataFrame.output_column
: Name of the output column containing the target variable.train_test_ratio
: Ratio in which the dataset is divided into train and test splits (must be between 0 and 1).scaling_method
(optional): Method to scale the data ('minmax' or 'normalize').perform_grid_search
(optional): Whether to perform grid search for hyperparameter tuning (default isFalse
).save_models
(optional): Whether to save trained models to disk (default isFalse
).show_confusion_matrix
(optional): Whether to display confusion matrix plots (default isFalse
).show_classification_report
(optional): Whether to print classification reports (default isFalse
).
Installation
Make sure you have Python installed on your system. You can install the package using pip:
pip install classifierAgent
Usage
Here's an example of how to use the package:
from classifierAgent import classifierAgent
dataset_path = "sampleFile.csv"
output_column = "Outcome"
train_test_ratio = 0.25
scaling_method = 'minmax' # Choose 'minmax' or 'normalize'
perform_grid_search = True # Whether to perform grid search
save_models = True # Whether to save models
show_confusion_matrix = True # Whether to plot the confusion matrix
show_classification_report = True # Whether to print the classification report
results = classifierAgent(dataset_path, output_column, train_test_ratio, scaling_method, perform_grid_search, save_models, show_confusion_matrix, show_classification_report)
print(results)
Example Output
The output is a DataFrame that looks like this:
Classifier | Accuracy | F1-Score | Best Parameters |
---|---|---|---|
KNeighborsClassifier | 0.78 | 0.76 | {'n_neighbors': 5, 'weights': 'uniform'} |
LogisticRegression | 0.80 | 0.79 | {'C': 0.1, 'solver': 'liblinear'} |
DecisionTreeClassifier | 0.72 | 0.70 | {'criterion': 'entropy', 'max_depth': 20} |
RandomForestClassifier | 0.85 | 0.84 | {'n_estimators': 200, 'max_depth': 20} |
GradientBoostingClassifier | 0.83 | 0.82 | {'n_estimators': 200, 'learning_rate': 0.1} |
SVC | 0.81 | 0.80 | {'C': 1, 'kernel': 'rbf'} |
GaussianNB | 0.75 | 0.73 | {} |
BernoulliNB | 0.73 | 0.72 | {} |
Publishing to PyPI
To publish this package to PyPI, follow these steps:
-
Ensure Your Package is Ready:
- Make sure your
setup.py
andREADME.md
are correctly configured. - Verify that your package is properly structured and tested.
- Make sure your
-
Create Distribution Archives: Run the following command to create distribution archives of your package:
python setup.py sdist bdist_wheel
-
Install Twine: If you haven't already, install Twine, a utility for publishing packages to PyPI:
pip install twine
-
Upload to PyPI: Use Twine to upload your package to PyPI:
twine upload dist/*
You will be prompted to enter your PyPI username and password.
-
Verify Upload: After uploading, check your package on PyPI to ensure it appears correctly.
For more detailed instructions, refer to the PyPI documentation.
Automated Publishing with GitHub Actions
To automate the publishing of your package to PyPI, GitHub Actions is setup. This allows to push updates to PyPI whenever changes are made to the main
branch.
Setting Up GitHub Actions
-
Add Your PyPI Token to GitHub Secrets:
- Go to your repository settings.
- Navigate to "Secrets and variables" > "Actions".
- Add a new secret with the name
PYPI_TOKEN
and paste your PyPI token as the value.
-
Create a GitHub Actions Workflow File:
- Add a
.github/workflows/publish.yml
file to your repository with the following content:
- Add a
This setup will automatically build and publish your package to PyPI whenever you push changes to the main
branch. Make sure to test your workflow to ensure that everything works as expected.
Notes
- The package is actively developed and may receive updates.
- The project is developed with Python version
3.10
. - If you encounter any issues or have questions, feel free to contact me on LinkedIn.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file classifierAgent-1.1.1.tar.gz
.
File metadata
- Download URL: classifierAgent-1.1.1.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ac8a2fa9211b8fb3b1fc3e492616199483da0c96b8ed72cdd5f7f726a904940 |
|
MD5 | 962043706c722b3d9b46ff7d04d655a5 |
|
BLAKE2b-256 | 8b97ccdc2d0404106288267d2df1153b91206dfdc459f4c66d5c831c50e6aef3 |
File details
Details for the file classifierAgent-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: classifierAgent-1.1.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed346a09674eed4548f7553d00d4bda2b05350fc5ededea3eed79311d5b1b134 |
|
MD5 | 1f32f70fdb8f6b6d8d6c28f31ae23ae6 |
|
BLAKE2b-256 | ab9a7e61ba8e2f889cd7f78d972f4d824afbcd8c980ee3d6071aad3a87295863 |