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.5.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.5-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ncd_knn_classifier-0.1.5.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.5.tar.gz
Algorithm Hash digest
SHA256 d3e807673a0fb495f9a9a579053a1eceda83eee2f9ffae1fdbe9902d5c882885
MD5 336277b62e1ecb3f53c442721f0260f3
BLAKE2b-256 fb496827b3791bcf80b9f0c87b561e5fb93fd536afd69ea34ed062dd161cd52a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ncd_knn_classifier-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 15227671cacc84f4bbc77b5497addbcb90222c4084d96a17ab2669ef52cb45aa
MD5 a95937ad65bb6ccf2ffef0140a8aa58c
BLAKE2b-256 f722123fc02a37bd453c85ec9e93ffe67826eebe05dca2d63657da502f599f59

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