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.2.0.tar.gz (7.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.2.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ncd_knn_classifier-0.2.0.tar.gz
  • Upload date:
  • Size: 7.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.2.0.tar.gz
Algorithm Hash digest
SHA256 cf2417e5be83e61ccd992b91e70b99d93297a2073008456908583ce2519f3116
MD5 d5653e4808d9ae212782db18ee00530c
BLAKE2b-256 03d4554c895f2be00bfd17548e1ceafa308ca9c070bb2f2bdb227277ca096a56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ncd_knn_classifier-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 efa0742b28bf483ced30414705bdf100dc41f489dd3c4c4e50594ea684065239
MD5 351734622b7eac3084d736496c708bc1
BLAKE2b-256 6987537284142c7b094332d0d0ce030f1902913f55d4de0f2d0934c1afe19176

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