Skip to main content

Banknote KNN Utils

Codecov test coverage PyPI version Python versions License

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 dataset
  • ensure_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 distribution
  • plot_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-validation
  • plot_knn_cv(neighbors, cv_scores, output_path=None, figsize=(10, 6)): Plot cross-validation results
  • train_knn_model(X_train, y_train, k): Train a KNN classifier with the specified k
  • evaluate_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:

  1. 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.

  2. Pandas: Provides the core data manipulation capabilities. Banknote Utils extends pandas with specialized functions for handling banknote datasets.

  3. Matplotlib/Seaborn: General-purpose visualization libraries. Banknote Utils offers pre-configured visualization functions specifically designed for banknote feature analysis.

  4. 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Contact

For questions and feedback, please open an issue on GitHub.

Metadata

Release files for banknote-knn-utils 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for banknote-knn-utils 0.1.6
File Size Uploaded Provenance
banknote_knn_utils-0.1.6.tar.gz 11.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for banknote-knn-utils 0.1.6
File Interpreter ABI Platform
banknote_knn_utils-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 21.1 kB

Release files / banknote_knn_utils-0.1.6.tar.gz

Download URL banknote_knn_utils-0.1.6.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
233a78144c16e61a74f039264e4b47307a9d3f10d287d6904d4a60c440f9c960
BLAKE2b-256 checksum
How to use checksums
33c3188eb603b2b5fe31920fcf4fd90cf6f310b35b8de25e2f79e26fdee53a46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release files / banknote_knn_utils-0.1.6-py3-none-any.whl

Download URL banknote_knn_utils-0.1.6-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
54961ee2afa53c19aa62299b41fabb4eefdde00eca509a173e0a7ee4a3a3948d
BLAKE2b-256 checksum
How to use checksums
727dd44381a1407a9fcddd8f9c3628ddf22eeeaac05823fe4c99c4cac440ed15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Security for banknote-knn-utils 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page