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 virtualenv (for python2) or venv (for python3)
  # for python3
  python3 -m venv .env
  # or for python2
  python2 -m virtualenv .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.1.1.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

ksvmlib-0.1.1-py2.py3-none-any.whl (19.4 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: ksvmlib-0.1.1.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for ksvmlib-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ea6d2dd6cc2be646c49e491fcc36634b17ab7be9d8057d08db492f187f9e5a1f
MD5 5c60941bd6f30da5e304a7ea96c8b66f
BLAKE2b-256 5d2be641234cd20a1612329f52f0c1247ad6dc7ef6be9107c68b9a6b5a4847e9

See more details on using hashes here.

File details

Details for the file ksvmlib-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: ksvmlib-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for ksvmlib-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5a17358d533b66b0259a70fe3d5ec5ac278aae4231a1627da463f443d33814b1
MD5 375c28b5d76dca088ff0124ef4f4e139
BLAKE2b-256 ccbd52c65d7b11b1424f232649aea43130edb8a9ed101a6f795590f40ec98b94

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page