Skip to main content

A package for anomaly detection using Elastic Net and Convex Hull.

Project description

ocelastic: Elastic Net One-Class Classifier for Anomaly Detection

ocelastic is a Python package for one-class classification and anomaly detection. It leverages Elastic Net and convex hull optimization to identify anomalies in data. Designed for flexibility, it supports various kernel methods and is compatible with scikit-learn tools like GridSearchCV and Pipeline.

Key Features

  • Elastic Net Regularization: Combines L1 and L2 penalties for robust optimization.
  • Kernel Support: Includes rbf, linear, poly, and sigmoid kernels.
  • Custom Threshold: Automatically find the best decision boundary using ThresholdFinder.
  • Scikit-learn Compatibility: Fully compatible with scikit-learn tools like Pipeline and GridSearchCV.
  • Anomaly Detection: Designed specifically for one-class classification tasks.

Installation

Install the package using pip:

pip install oneclass-elasticnet

Quick Start

from ocelastic import EnetConvexHull, ThresholdFinder
import numpy as np

# Generate synthetic data
X = np.random.rand(100, 2)  # 100 samples, 2 features

# Initialize and fit the model
model = EnetConvexHull(landa1=0.5, metric='rbf', solver='cvxopt')
model.fit(X)

# Use ThresholdFinder to calculate the optimal threshold
finder = ThresholdFinder(model=model, X=X)
z_values, max_z = finder.find()

# Make predictions
predictions = model.predict(X)

Parameters

  • landa1: The weight for L1 regularization (default: 0.5).
  • metric: Kernel function for pairwise similarity (rbf, linear, poly, sigmoid).
  • thr: Decision threshold for anomaly detection (default: 1.0).
  • kernel_params: Additional kernel parameters like gamma, degree, and coef0.
  • solver: Quadratic programming solver (e.g., cvxopt).

Results

Below is an example of the decision boundary generated by the model:

Decision Boundary

Requirements

  • Python >= 3.8
  • scikit-learn
  • numpy
  • matplotlib
  • tqdm
  • qpsolvers

Contributing

We welcome contributions! To get started:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature-name).
  3. Commit your changes (git commit -m 'Add a new feature').
  4. Push to the branch (git push origin feature/your-feature-name).
  5. Create a pull request.

License

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

Contact

For questions or feedback, please email [yousof.ghalenoei2017@gmail.com] or open an issue in the 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

oneclass_elasticnet-0.0.1.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

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

oneclass_elasticnet-0.0.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file oneclass_elasticnet-0.0.1.tar.gz.

File metadata

  • Download URL: oneclass_elasticnet-0.0.1.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.1

File hashes

Hashes for oneclass_elasticnet-0.0.1.tar.gz
Algorithm Hash digest
SHA256 45d4ddb5aa7c50e4bc9466c62af4a19953b5b5caf818a921836a7f08eb945a32
MD5 5a124adb28407caa450c7bf1af835bf3
BLAKE2b-256 7ac8cf238c570f6ecac307d455890b6cffa0f2ea2fe09489443e6cff9546ccc2

See more details on using hashes here.

File details

Details for the file oneclass_elasticnet-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for oneclass_elasticnet-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 81428e1d168a918027182081d867d20378c9e5897883f073bbc10c4f031413e9
MD5 0d95d42f565182757c1b690df14843f5
BLAKE2b-256 bdd7cd37544d80044c04d66cc9cd8c5b5f0135c0d7746662f920180a11af3581

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