Utilities for banknote classification and analysis
Project description
Banknote KNN Utils
A Python package for banknote classification and analysis utilities, providing tools for data processing, visualization, and modeling focused on banknote authentication.
Overview
Banknote Utils is a specialized package designed to simplify the process of analyzing and classifying banknote data. It provides a collection of utility functions for common tasks in the banknote authentication workflow, including data preprocessing, visualization, and machine learning model evaluation with a focus on K-Nearest Neighbors (KNN) classification.
Installation
pip install banknote-knn-utils
Features
-
Data Handling:
- Check and handle missing values in datasets
- Ensure output directories exist for saving results
-
Visualization Utilities:
- Create count tables for class distribution analysis
- Generate histograms for feature visualization
-
KNN Modeling Tools:
- Train KNN models with customizable parameters
- Evaluate models using cross-validation
- Visualize cross-validation results
- Generate comprehensive model evaluation reports
Usage Examples
Checking for Missing Values
import pandas as pd
from banknote_utils.check_missing_value import check_missing_value
# Load your banknote dataset
data = pd.read_csv('banknote_data.csv')
# Check and handle missing values
clean_data = check_missing_value(data)
Creating Visualizations
from banknote_utils.visualization_utils import create_count_table, plot_histogram
# Create a count table of class distribution
create_count_table(data, 'class', output_prefix='results/class_distribution')
# Create histograms for each feature
plot_histogram(data, 'variance', 'class', labels=['Genuine', 'Counterfeit'],
output_prefix='results/histograms')
Training and Evaluating a KNN Model
from banknote_utils.modeling_utils import evaluate_knn_cv, plot_knn_cv, train_knn_model, evaluate_model
from sklearn.model_selection import train_test_split
# Prepare your data
X = data.drop('class', axis=1)
y = data['class']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
# Find the optimal k value using cross-validation
neighbors, cv_scores, best_k = evaluate_knn_cv(X_train, y_train, k_range=range(1, 21))
# Visualize the cross-validation results
plot_knn_cv(neighbors, cv_scores, output_path='results/knn_cv_plot.png')
# Train the KNN model with the optimal k value
model = train_knn_model(X_train, y_train, best_k)
# Evaluate the model
results = evaluate_model(model, X_test, y_test, output_path='results/confusion_matrix.png')
print(f"Model accuracy: {results['accuracy']:.4f}")
print(results['classification_report'])
API Reference
Data Handling
check_missing_value(bill_data): Check and handle missing values in the datasetensure_output_directory(output_prefix): Ensure output directories exist for saving results
Visualization
create_count_table(dataset, target_variable, output_prefix=None): Create a count table for class distributionplot_histogram(dataset, feature, target_variable, labels=None, output_prefix=None, figsize=(8, 6)): Generate histograms for features
Modeling
evaluate_knn_cv(X_train, y_train, k_range=range(1, 26)): Evaluate different k values using cross-validationplot_knn_cv(neighbors, cv_scores, output_path=None, figsize=(10, 6)): Plot cross-validation resultstrain_knn_model(X_train, y_train, k): Train a KNN classifier with the specified kevaluate_model(model, X_test, y_test, output_path=None, figsize=(6, 5)): Evaluate a trained model and visualize results
Ecosystem Context
Banknote Utils fills a specialized niche in the Python machine learning ecosystem by focusing specifically on banknote authentication workflows. While there are many general-purpose machine learning libraries available in Python, this package provides domain-specific utilities that streamline the banknote classification process.
Related Packages and Differences:
-
Scikit-learn: A general-purpose machine learning library that provides the core KNN implementation used by Banknote Utils. Banknote Utils builds upon scikit-learn by adding domain-specific wrappers and visualization tools tailored for banknote authentication.
-
Pandas: Provides the core data manipulation capabilities. Banknote Utils extends pandas with specialized functions for handling banknote datasets.
-
Matplotlib/Seaborn: General-purpose visualization libraries. Banknote Utils offers pre-configured visualization functions specifically designed for banknote feature analysis.
-
EDA Packages (like pandas-profiling): Provide general exploratory data analysis. Banknote Utils focuses specifically on the visualizations and analyses most relevant to banknote authentication.
Unlike these more general packages, Banknote Utils combines functionality from multiple libraries into a streamlined workflow specifically optimized for banknote authentication tasks, reducing the amount of boilerplate code needed for common operations in this domain.
Requirements
- Python 3.6+
- pandas
- matplotlib
- seaborn
- scikit-learn
- click
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Contact
For questions and feedback, please open an issue on GitHub.
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file banknote_knn_utils-0.1.6.tar.gz.
File metadata
- Download URL: banknote_knn_utils-0.1.6.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
233a78144c16e61a74f039264e4b47307a9d3f10d287d6904d4a60c440f9c960
|
|
| MD5 |
c9f31c909afe2811e860d3488f6e8c56
|
|
| BLAKE2b-256 |
33c3188eb603b2b5fe31920fcf4fd90cf6f310b35b8de25e2f79e26fdee53a46
|
File details
Details for the file banknote_knn_utils-0.1.6-py3-none-any.whl.
File metadata
- Download URL: banknote_knn_utils-0.1.6-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54961ee2afa53c19aa62299b41fabb4eefdde00eca509a173e0a7ee4a3a3948d
|
|
| MD5 |
f3d0d555ac042b7e27bc40aeeb3bb51a
|
|
| BLAKE2b-256 |
727dd44381a1407a9fcddd8f9c3628ddf22eeeaac05823fe4c99c4cac440ed15
|