Skip to main content

A package for Logistic Regression, KNN, and Decision Linear SVM

Project description

ML Package: Logistic Regression, KNN, and Linear SVM

This package, mlpackage, provides implementations of three popular machine learning algorithms:

  • Logistic Regression with Softmax

  • K-Nearest Neighbors (KNN) Classifier

  • Linear Support Vector Machine (SVM)

It also includes test scripts to validate each module's functionality.

Usage

Logistic Regression with Softmax

Example:

from mlpackage.logistic_regression import LogisticRegressionSoftmax
import numpy as np

# Sample data
X = np.array([[1, 2], [2, 3], [3, 4]])
y = np.array([0, 1, 0])

# Train the model
model = LogisticRegressionSoftmax(learning_rate=0.1, epochs=1000)
model.fit(X, y)

# Make predictions
predictions = model.predict(X)
print(predictions)

K-Nearest Neighbors (KNN) Classifier

Example:

from mlpackage.knn import KNNClassifier
import numpy as np

# Sample data
X = np.array([[1, 1], [2, 2], [3, 3]])
y = np.array([0, 1, 0])

# Train and predict
model = KNNClassifier(k=1)
model.fit(X, y)
predictions = model.predict(X)
print(predictions)

Linear Support Vector Machine (SVM)

Example:

from mlpackage.linear_svm import LinearSVM
import numpy as np

# Sample data
X = np.array([[1, 2], [2, 3], [3, 4]])
y = np.array([1, -1, 1])

# Train the model
model = LinearSVM(learning_rate=0.001, epochs=1000, lambda_param=0.01)
model.fit(X, y)

# Make predictions
predictions = model.predict(X)
print(predictions)

Running Tests

To verify the implementation, you can run the unit tests located in the tests/ directory.

Run All Tests:

python -m unittest discover -s tests -p "*.py" -v

#Example Output
test_fit_predict (tests.test_logistic_regression.TestLogisticRegression) ... ok
test_fit_predict (tests.test_knn.TestKNNClassifier) ... ok
test_fit_predict (tests.test_linear_svm.TestLinearSVM) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.XXXs

OK

Dependencies

  • Python 3.6+

  • NumPy

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ml_packages-1.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

ml_packages-1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file ml_packages-1.0.tar.gz.

File metadata

  • Download URL: ml_packages-1.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for ml_packages-1.0.tar.gz
Algorithm Hash digest
SHA256 2e4ae1569b9d5aa44905267aa4b450a2792d3aaf3fcda122fc45f8205e2b41e5
MD5 cb9bd5229c36fa557ca3e9583b9c8e2c
BLAKE2b-256 2ea78e8a229974333064fcdeadde53c63ff9edcbb9364d49a2f321312b1ecbb9

See more details on using hashes here.

File details

Details for the file ml_packages-1.0-py3-none-any.whl.

File metadata

  • Download URL: ml_packages-1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for ml_packages-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02b35167ad0fa36d9973b924f34edbe49d9c0b31847fb3352d6ecb55cbad8bec
MD5 e48df8a1db11547945bfb529a8c33997
BLAKE2b-256 83da077f521d6c09fda058a804eb096f458b0dfeb791fc5f4956d1712b804699

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