A linear classifier built using tensorflow.
Project description
classifier-anshp
classifier-anshp is a powerful linear classifier built using TensorFlow. This package features a customizable linear model for binary classification and includes tools for hyperparameter tuning, making it suitable for various machine learning tasks.
Features
-
Customizable Linear Classifier: Modify input features, learning rate, and number of steps to train a linear model for binary classification.
-
Hyperparameter Tuner: The
hyper_tunnerfunction enables efficient tuning of model parameters to optimize performance across different settings. It supports various optimizers and loss functions, allowing users to find the best configuration for their datasets. -
Predefined Datasets: The package includes three sample datasets for quick testing:
- Dataset 1: Generates a synthetic dataset using multivariate Gaussian distributions.
- Dataset 2: Logical operations (AND, OR, XOR, XNOR) for testing the classifier.
- Dataset 3: IMDB movie reviews dataset for sentiment analysis, providing a real-world binary classification task.
-
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 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. Hyperparameter Tuning
The hyper_tunner function is designed to optimize the model's performance by adjusting various parameters.
from classifier_anshp import hyper_tunner
# Example usage
optimal_epoch = hyper_tunner(x_train, y_train, x_test, y_test, epoch=50, mode=0)
print(f'Optimal Epoch: {optimal_epoch}')
3. Using Sample Datasets
You can quickly test the classifier using the predefined datasets. The package provides three 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.
- Dataset 3: IMDB dataset for sentiment analysis.
from classifier_anshp import dataset_1, dataset_2, dataset_3
# 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
# Example 3: Load IMDB dataset
partial_x_train, partial_y_train, x_val, y_val, x_test, y_test = dataset_3()
4. 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
Generate Dataset 3 (IMDB Reviews):
dataset-3
Advantages Over scikit-learn
-
TensorFlow-Based: While
scikit-learnprovides efficient linear models,classifier-anshpis built using TensorFlow, allowing for more customization and seamless integration with larger deep learning frameworks. -
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.
-
Dataset Flexibility: In addition to custom datasets,
classifier-anshpcomes with logical operation datasets and the IMDB dataset, making it easier to test and experiment with common machine learning tasks. -
Custom Training Intervals: The classifier provides detailed control over training steps, ensuring outputs are printed at regular intervals.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file classifier_anshp-0.30.7.tar.gz.
File metadata
- Download URL: classifier_anshp-0.30.7.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0503c8f482fff4fa5de5a2382efffcc53e0be8c8079a4c513d1b5cfcd9b1fbc
|
|
| MD5 |
0c6871ab66693ad4bd1e1113f6e02310
|
|
| BLAKE2b-256 |
0ae439dce1196f90faa8afe2439934e6f5bcea1d2b9978f3473fa3a55bc7826d
|
File details
Details for the file classifier_anshp-0.30.7-py3-none-any.whl.
File metadata
- Download URL: classifier_anshp-0.30.7-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e66f8cf33db717b671c7b979cdb20584207e4f37e9f01845da6624cf02a67529
|
|
| MD5 |
0fb314ecc3a20729fb5b23f4a504b691
|
|
| BLAKE2b-256 |
422333b956717d971e0219479e862205e5eb549c6a0ac7b64573b14c253a0f08
|