Skip to main content

A kNN classifier based on NCD distance metric for text compression

Project description

NCD-KNN-Classifier

A kNN classifier based on the Normalized Compression Distance (NCD) for text classification.

Installation

Install the package using pip:

pip install NCD_KNN_Classifier

Usage

Here's a basic example of how to use the classifier:

from datasets import load_dataset
from NCD_KNN_Classifier import CompNCDClassifier

# Example of imdb dataset for classification of two labels
dataset = load_dataset("imdb")
test_samples = dataset["test"].shuffle(seed=42).select(range(200))

# Compressing and Saving the Training Dataset Footprint
classifier = CompNCDClassifier(
    train_dataset=dataset['train'],
    test_dataset=test_samples,
    k=3,
    compressor="gzip",
    verbose=True
)
classifier.save_to_pickle("train_footprint.pkl")

# Inference on the test set
metrics = classifier.evaluate()
print("Evaluation metrics:", metrics)

Output Example

After running the example, you should see output similar to this:

INFO:NCD_KNN_Classifier.classifier:Evaluating on the dataset...
Evaluating 200/200: 100%|██████████| 200/200 [00:55<00:00,  3.63it/s]
Evaluation metrics: {'accuracy': 0.69, 'precision': 0.6969369369369369, 'recall': 0.69, 'f1_score': 0.68476726342711}

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

ncd_knn_classifier-0.1.4.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ncd_knn_classifier-0.1.4-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file ncd_knn_classifier-0.1.4.tar.gz.

File metadata

  • Download URL: ncd_knn_classifier-0.1.4.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.8

File hashes

Hashes for ncd_knn_classifier-0.1.4.tar.gz
Algorithm Hash digest
SHA256 97f257f42510cafc91277bf3f382d312891c17b1fb3433797ec41ac35510b327
MD5 988bfaee60d5258230fad50db05224ed
BLAKE2b-256 e31c284e1b69224ae8828f7c3f5c5a06db6510caa804808103eafc89b6ff4364

See more details on using hashes here.

File details

Details for the file ncd_knn_classifier-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for ncd_knn_classifier-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f80674475f730e9a0787b5462842c6715147216ca1d434a63489a32c1a113854
MD5 31d96110885d9778037d9f49c1ffc245
BLAKE2b-256 8cff2a7516f730f8c371d00b4106621beb9e7ffa13c40a44f95260603e49b20a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page