Skip to main content

A linear classifier built using tensorflow.

Project description

classifier-anshp

classifier-anshp is a simple linear classifier built using TensorFlow. This package includes a customizable linear model for binary classification and provides sample datasets for quick testing. The classifier is designed for flexibility and can be applied to custom datasets or pre-defined datasets, such as logical operations (AND, OR, XOR, XNOR).

Features

  • Customizable Linear Classifier: Modify input features, learning rate, and number of steps to train a linear model for binary classification.
  • Predefined Datasets: Two sample datasets are included:
    • Dataset 1: Generates a synthetic dataset using multivariate Gaussian distributions.
    • Dataset 2: Logical operations (AND, OR, XOR, XNOR) for testing the classifier.
  • TensorFlow Backend: Leverages TensorFlow for handling large-scale computations and efficient gradient-based optimization.

Installation

You can install the package directly from PyPI:

pip install classifier-anshp

Usage

1. Training a Custom Linear Classifier

The clsfr function allows you to train a linear classifier on your own dataset.

from classifier_anshp import clsfr
import numpy as np

# Example dataset
inputs = np.array([[1.0, 2.0], [1.5, 1.8], [5.0, 8.0], [8.0, 8.0]])
val_true = np.array([0, 0, 1, 1])

# Train classifier with learning rate of 0.01 for 50 steps
val_pred, weights, bias = clsfr(inputs, val_true, lrn_rt=0.01, steps=50)

# Predicted output
print(f'Predictions: {val_pred}')
print(f'Weights: {weights}')
print(f'Bias: {bias}')

2. Using Sample Datasets

You can quickly test the classifier using the predefined datasets. The package provides two functions for generating data:

  • Dataset 1: Generates a random binary classification dataset using multivariate normal distribution.
  • Dataset 2: Logical operations like AND, OR, XOR, and XNOR.
from classifier_anshp import dataset_1, dataset_2

# Example 1: Generate random dataset
inputs, val_true = dataset_1(sample_size=100)

# Example 2: Logical OR operation
inputs, val_true = dataset_2(num=2)  # 1 for AND, 2 for OR, 3 for XOR, 4 for XNOR

3. Running from Command Line

After installing the package, you can run the classifier or dataset generation directly from the command line.

Run Classifier:

classifier-anshp --inputs [[1,2],[3,4]] --val_true [0,1] --lrn_rt 0.01 --steps 50

Generate Dataset 1:

dataset-1 --sample_size 100

Generate Dataset 2 (Logical Operations):

dataset-2 --num 2

Advantages Over scikit-learn

  1. TensorFlow-Based: While scikit-learn provides efficient linear models, classifier-anshp is built using TensorFlow, which allows for more customization and seamless integration with larger deep learning frameworks.

  2. Gradient-Based Optimization: The package uses TensorFlow’s gradient-based optimization, making it easy to modify and extend for more complex models beyond linear classifiers.

  3. Dataset Flexibility: In addition to custom datasets, classifier-anshp comes with logical operation datasets, making it easier to test and experiment with common machine learning tasks.

  4. Custom Training Intervals: The classifier provides detailed control over training steps, ensuring outputs are printed every 10 intervals, unlike scikit-learn, where training steps aren’t typically exposed.

Limitations

  • Primarily designed for binary classification tasks.
  • Requires basic knowledge of TensorFlow to fully customize the model.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Author

Anshuman Pattnaik
Email: helloanshu04@gmail.com

For more details, visit the GitHub Repository.

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

classifier_anshp-0.23.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

classifier_anshp-0.23.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file classifier_anshp-0.23.0.tar.gz.

File metadata

  • Download URL: classifier_anshp-0.23.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for classifier_anshp-0.23.0.tar.gz
Algorithm Hash digest
SHA256 0bc5d792fb4d78ee9691e58af7c7a0c00b57d8ed4166af7b81c3da4225ededaf
MD5 cbef552631e77e4a512553f9dab51ed7
BLAKE2b-256 b0e6887e95646a3e7d06513b2cbeec9bbfebffbb1dc52f4830a08a6e6b2b8190

See more details on using hashes here.

File details

Details for the file classifier_anshp-0.23.0-py3-none-any.whl.

File metadata

File hashes

Hashes for classifier_anshp-0.23.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e84f9f6e3502322cd5fadfbbd9e521d1df4efbe37384968c5763e6f507325ef
MD5 34616d999625340d88797c117ac98dd3
BLAKE2b-256 b468d122b5f76a43a868be6ae4399aa42a18f35e5772d5b10eafa2daca74a8a2

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