Skip to main content

Kernel SVM library based on sklearn and GPlib.

Project description

kSVMlib

Kernel SVM library based on sklearn and GPlib. Provides similar functionality to GPlib for SVMs.

Setup kSVMlib

  • Create and activate venv

    python3 -m venv .env
    
    source .env/bin/activate
    
  • Upgrade pip

    python -m pip install --upgrade pip
    
  • Install kSVMlib package

    python -m pip install ksvmlib
    

Use kSVMlib

  • Import kSVMlib to use it in your python script.

    import ksvmlib
    
  • Generate some random data.

    import numpy as np
    data = {}
    data['X'] = np.vstack((
        np.random.multivariate_normal([1, 1], [[1, 0], [0, 1]], 100),
        np.random.multivariate_normal([3, 3], [[1, 0], [0, 1]], 100)
    ))
    data['Y'] = np.vstack((
        np.ones((100, 1)),
        np.zeros((100, 1)),
    ))
    
    validation = ksvmlib.dm.RandFold(fold_len=0.2, n_folds=1)
    train_set, test_set = validation.get_folds(data)[0]
    
  • Initialize the KSVM model and a metric to measure the results.

    model = ksvmlib.KSVM(ksvmlib.ker.SquaredExponential())
    accuracy = ksvmlib.me.Accuracy()
    
  • Fit the model to the data.

    fitting_method = ksvmlib.fit.GridSearch(
        obj_fun=accuracy.fold_measure,
        max_fun_call=300
    )
    train_validation = ksvmlib.dm.RandFold(fold_len=0.2, n_folds=3)
    
    log = fitting_method.fit(model, train_validation.get_folds(
        train_set
    ))
    print("Fitting log: {}".format(log))
    
  • Finally plot the results.

    print("Accuracy: {}".format(accuracy.measure(model, train_set, test_set)))
    ksvmlib.plot.kernel_sort_data(model, test_set)
    
  • There are more examples in examples/ directory. Check them out!

Develop kSVMlib

  • Update API documentation

    source ./.env/bin/activate
    pip install Sphinx
    cd docs/
    sphinx-apidoc -f -o ./ ../ksvmlib
    

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

ksvmlib-0.2.0.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

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

ksvmlib-0.2.0-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

Details for the file ksvmlib-0.2.0.tar.gz.

File metadata

  • Download URL: ksvmlib-0.2.0.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for ksvmlib-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e54ed184860b4d59cf22024e7e2aa99e416a1d34dce11622d022c862154aafcb
MD5 9bae131d189fd3d9ead69b520db3423f
BLAKE2b-256 9d229322957da7658d4dfe4eddec97ecb3e4eea01fa417c1fe48e1af00617345

See more details on using hashes here.

File details

Details for the file ksvmlib-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ksvmlib-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 31.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for ksvmlib-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34d79e1ce61b29a41eafe85ccf0d84b8d248027c635d7dda90a648a0b6d26c4c
MD5 5a4e8d92f9b0f10baab22c4e6c4fb930
BLAKE2b-256 c1fc38c3634b0639f429b486359353b25a249c4c5d085f5ffc70b77495e22f4a

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