{ "info": { "author": "G.J.J. van den Burg", "author_email": "gertjanvandenburg@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "GenSVM Python Package\n=====================\n\n.. image:: https://travis-ci.org/GjjvdBurg/PyGenSVM.svg?branch=master\n :target: https://travis-ci.org/GjjvdBurg/PyGenSVM\n\n.. image:: https://readthedocs.org/projects/gensvm/badge/?version=latest\n :target: https://gensvm.readthedocs.io/en/latest/?badge=latest\n :alt: Documentation Status\n\n\nThis is the Python package for the GenSVM multiclass classifier by `Gerrit \nJ.J. van den Burg `_ and `Patrick J.F. Groenen \n`_.\n\n**Important links:**\n\n- Source repository: `https://github.com/GjjvdBurg/PyGenSVM \n `_.\n\n- Package on PyPI: `https://pypi.org/project/gensvm/ \n `_.\n\n- Journal paper: `GenSVM: A Generalized Multiclass Support Vector Machine \n `_ JMLR, 17(225):1\u221242, 2016.\n\n- Package documentation: `Read The Docs \n `_.\n\n- There is also an `R package `_.\n\n- Or you can directly use `the C library \n `_.\n\n\nInstallation\n------------\n\n**Before** GenSVM can be installed, a working NumPy installation is required. \nPlease see `the installation instructions for NumPy \n`_, then install \nGenSVM using the instructions below.\n\nGenSVM can be easily installed through pip:\n\n.. code:: bash\n\n pip install gensvm\n\nIf you encounter any errors, please open an issue on `GitHub \n`_.\n\nCiting\n------\n\nIf you use this package in your research please cite the paper, for instance \nusing the following BibTeX entry::\n\n @article{JMLR:v17:14-526,\n author = {{van den Burg}, G. J. J. and Groenen, P. J. F.},\n title = {{GenSVM}: A Generalized Multiclass Support Vector Machine},\n journal = {Journal of Machine Learning Research},\n year = {2016},\n volume = {17},\n number = {225},\n pages = {1-42},\n url = {http://jmlr.org/papers/v17/14-526.html}\n }\n\nUsage\n-----\n\nThe package contains two classes to fit the GenSVM model: `GenSVM`_ and \n`GenSVMGridSearchCV`_. These classes respectively fit a single GenSVM model \nor fit a series of models for a parameter grid search. The interface to these \nclasses is the same as that of classifiers in `Scikit-Learn`_ so users \nfamiliar with Scikit-Learn should have no trouble using this package. Below \nwe will show some examples of using the GenSVM classifier and the \nGenSVMGridSearchCV class in practice.\n\nIn the examples we assume that we have loaded the `iris dataset\n`_ \nfrom Scikit-Learn as follows:\n\n.. code:: python\n\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.preprocessing import MaxAbsScaler\n >>> X, y = load_iris(return_X_y=True)\n >>> X_train, X_test, y_train, y_test = train_test_split(X, y)\n >>> scaler = MaxAbsScaler().fit(X_train)\n >>> X_train, X_test = scaler.transform(X_train), scaler.transform(X_test)\n\nNote that we scale the data using the `MaxAbsScaler \n`_ \nfunction. This scales the columns of the data matrix to ``[-1, 1]`` without \nbreaking sparsity. Scaling the dataset can have a significant effect on the \ncomputation time of GenSVM and is `generally recommended for SVMs \n`_.\n\n\nExample 1: Fitting a single GenSVM model\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nLet's start by fitting the most basic GenSVM model on the training data:\n\n.. code:: python\n\n >>> from gensvm import GenSVM\n >>> clf = GenSVM()\n >>> clf.fit(X_train, y_train)\n GenSVM(coef=0.0, degree=2.0, epsilon=1e-06, gamma='auto', kappa=0.0,\n kernel='linear', kernel_eigen_cutoff=1e-08, lmd=1e-05,\n max_iter=100000000.0, p=1.0, random_state=None, verbose=0,\n weights='unit')\n\n\nWith the model fitted, we can predict the test dataset:\n\n.. code:: python\n\n >>> y_pred = clf.predict(X_test)\n\nNext, we can compute a score for the predictions. The GenSVM class has a \n``score`` method which computes the `accuracy_score \n`_ \nfor the predictions. In the GenSVM paper, the `adjusted Rand index \n`_ is often used \nto compare performance. We illustrate both options below (your results may be \ndifferent depending on the exact train/test split):\n\n.. code:: python\n\n >>> clf.score(X_test, y_test)\n 1.0\n >>> from sklearn.metrics import adjusted_rand_score\n >>> adjusted_rand_score(clf.predict(X_test), y_test)\n 1.0\n\nWe can try this again by changing the model parameters, for instance we can \nturn on verbosity and use the Euclidean norm in the GenSVM model by setting ``p = 2``:\n\n.. code:: python\n\n >>> clf2 = GenSVM(verbose=True, p=2)\n >>> clf2.fit(X_train, y_train)\n Starting main loop.\n Dataset:\n n = 112\n m = 4\n K = 3\n Parameters:\n kappa = 0.000000\n p = 2.000000\n lambda = 0.0000100000000000\n epsilon = 1e-06\n \n iter = 0, L = 3.4499531579689533, Lbar = 7.3369415851139745, reldiff = 1.1266786095824437\n ...\n Optimization finished, iter = 4046, loss = 0.0230726364692517, rel. diff. = 0.0000009998645783\n Number of support vectors: 9\n GenSVM(coef=0.0, degree=2.0, epsilon=1e-06, gamma='auto', kappa=0.0,\n kernel='linear', kernel_eigen_cutoff=1e-08, lmd=1e-05,\n max_iter=100000000.0, p=2, random_state=None, verbose=True,\n weights='unit')\n\nFor other parameters that can be tuned in the GenSVM model, see `GenSVM`_.\n\n\nExample 2: Fitting a GenSVM model with a \"warm start\"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nOne of the key features of the GenSVM classifier is that training can be \naccelerated by using so-called \"warm-starts\". This way the optimization can be \nstarted in a location that is closer to the final solution than a random \nstarting position would be. To support this, the ``fit`` method of the GenSVM \nclass has an optional ``seed_V`` parameter. We'll illustrate how this can be \nused below.\n\nWe start with relatively large value for the ``epsilon`` parameter in the \nmodel. This is the stopping parameter that determines how long the \noptimization continues (and therefore how exact the fit is).\n\n.. code:: python\n\n >>> clf1 = GenSVM(epsilon=1e-3)\n >>> clf1.fit(X_train, y_train)\n ...\n >>> clf1.n_iter_\n 163\n\nThe ``n_iter_`` attribute tells us how many iterations the model did. Now, we \ncan use the solution of this model to start the training for the next model:\n\n.. code:: python\n\n >>> clf2 = GenSVM(epsilon=1e-8)\n >>> clf2.fit(X_train, y_train, seed_V=clf1.combined_coef_)\n ...\n >>> clf2.n_iter_\n 3196\n\nCompare this to a model with the same stopping parameter, but without the warm \nstart:\n\n.. code:: python\n\n >>> clf2.fit(X_train, y_train)\n ...\n >>> clf2.n_iter_\n 3699\n\nSo we saved about 500 iterations! This effect will be especially significant \nwith large datasets and when you try out many parameter configurations. \nTherefore this technique is built into the `GenSVMGridSearchCV`_ class that \ncan be used to do a grid search of parameters.\n\n\nExample 3: Running a GenSVM grid search\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nOften when we're fitting a machine learning model such as GenSVM, we have to \ntry several parameter configurations to figure out which one performs best on \nour given dataset. This is usually combined with `cross validation \n`_ to avoid \noverfitting. To do this efficiently and to make use of warm starts, the \n`GenSVMGridSearchCV`_ class is available. This class works in the same way as \nthe `GridSearchCV \n`_ \nclass of `Scikit-Learn`_, but uses the GenSVM C library for speed.\n\nTo do a grid search, we first have to define the parameters that we want to \nvary and what values we want to try:\n\n.. code:: python\n\n >>> from gensvm import GenSVMGridSearchCV\n >>> param_grid = {'p': [1.0, 2.0], 'lmd': [1e-8, 1e-6, 1e-4, 1e-2, 1.0], 'kappa': [-0.9, 0.0] }\n\nFor the values that are not varied in the parameter grid, the default values \nwill be used. This means that if you want to change a specific value (such as \n``epsilon`` for instance), you can add this to the parameter grid as a \nparameter with a single value to try (e.g. ``'epsilon': [1e-8]``).\n\nRunning the grid search is now straightforward:\n\n.. code:: python\n\n >>> gg = GenSVMGridSearchCV(param_grid)\n >>> gg.fit(X_train, y_train)\n GenSVMGridSearchCV(cv=None, iid=True,\n param_grid={'p': [1.0, 2.0], 'lmd': [1e-06, 0.0001, 0.01, 1.0], 'kappa': [-0.9, 0.0]},\n refit=True, return_train_score=True, scoring=None, verbose=0)\n\nNote that if we have set ``refit=True`` (the default), then we can use the \n`GenSVMGridSearchCV`_ instance to predict or score using the best estimator \nfound in the grid search:\n\n.. code:: python\n\n >>> y_pred = gg.predict(X_test)\n >>> gg.score(X_test, y_test)\n 1.0\n\nA nice feature borrowed from `Scikit-Learn`_ is that the results from the grid \nsearch can be represented as a ``pandas`` DataFrame:\n\n.. code:: python\n\n >>> from pandas import DataFrame\n >>> df = DataFrame(gg.cv_results_)\n\nThis can make it easier to explore the results of the grid search.\n\nKnown Limitations\n-----------------\n\nThe following are known limitations that are on the roadmap for a future \nrelease of the package. If you need any of these features, please vote on them \non the linked GitHub issues (this can make us add them sooner!).\n\n1. `Support for sparse matrices \n `_. NumPy supports sparse \n matrices, as does the GenSVM C library. Getting them to work together \n requires some time. In the meantime, if you really want to use sparse data \n with GenSVM (this can lead to significant speedups!), check out the GenSVM \n C library.\n2. `Specification of class misclassification weights \n `_. Currently, incorrectly \n classification an object from class A to class C is as bad as incorrectly \n classifying an object from class B to class C. Depending on the \n application, this may not be the desired effect. Adding class \n misclassification weights can solve this issue.\n\nQuestions and Issues\n--------------------\n\nIf you have any questions or encounter any issues with using this package, \nplease ask them on `GitHub `_.\n\nLicense\n-------\n\nThis package is licensed under the GNU General Public License version 3. \n\nCopyright G.J.J. van den Burg, excluding the sections of the code that are \nexplicitly marked to come from Scikit-Learn.\n\n.. _Scikit-Learn:\n http://scikit-learn.org/stable/index.html\n\n.. _GenSVM:\n https://gensvm.readthedocs.io/en/latest/#gensvm\n\n.. _GenSVMGridSearchCV:\n https://gensvm.readthedocs.io/en/latest/#gensvmgridsearchcv", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/GjjvdBurg/PyGenSVM", "keywords": "", "license": "GPL v2", "maintainer": "", "maintainer_email": "", "name": "gensvm", "package_url": "https://pypi.org/project/gensvm/", "platform": "", "project_url": "https://pypi.org/project/gensvm/", "project_urls": { "Homepage": "https://github.com/GjjvdBurg/PyGenSVM" }, "release_url": "https://pypi.org/project/gensvm/0.2.4/", "requires_dist": null, "requires_python": "", "summary": "Python package for the GenSVM classifier", "version": "0.2.4" }, "last_serial": 5338445, "releases": { "0.1.3": [ { "comment_text": "", "digests": { "md5": "6ff426e654588332c09b7b118ef40346", "sha256": "6e745a525cc5610a206dad8c068b2edb9524d5a821c6e174d79420afe1c3239a" }, "downloads": -1, "filename": "gensvm-0.1.3.tar.gz", "has_sig": false, "md5_digest": "6ff426e654588332c09b7b118ef40346", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 159014, "upload_time": "2017-12-13T02:32:31", "url": "https://files.pythonhosted.org/packages/71/7d/087bb4464cf60f3d2fdded7f464380e45295fe63822b69c7e2cfb8ed1240/gensvm-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "5418ce70d9c541af654607358427d441", "sha256": "c6dbe851a3e7a9237cd48dfe8fed2e72408e93cd1803dd4bd96a0e992bfe8d16" }, "downloads": -1, "filename": "gensvm-0.1.4.tar.gz", "has_sig": false, "md5_digest": "5418ce70d9c541af654607358427d441", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 159019, "upload_time": "2017-12-13T02:43:31", "url": "https://files.pythonhosted.org/packages/c7/9b/2279c0b305d49fe1ea0dad7f407636b0ed5ab478f525b2d8b53915fe78cf/gensvm-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "610e3480f8a4c8b97bcc94b1f1226dbb", "sha256": "5bbe394505e983082454750248bb1335025171c9fdfa7729e2c06fd24c52158f" }, "downloads": -1, "filename": "gensvm-0.1.5.tar.gz", "has_sig": false, "md5_digest": "610e3480f8a4c8b97bcc94b1f1226dbb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 159218, "upload_time": "2017-12-13T19:39:52", "url": "https://files.pythonhosted.org/packages/6f/a7/d8671d408c025572973a09a804c64aeb533394c1238218279514187e8b25/gensvm-0.1.5.tar.gz" } ], "0.1.6": [ { "comment_text": "", "digests": { "md5": "1bde2e3660b64165714a905fd2449a87", "sha256": "ff14e3bfc776bcf49e6d40428e122a431283e44954d1ea142f1813f935ca2e88" }, "downloads": -1, "filename": "gensvm-0.1.6.tar.gz", "has_sig": false, "md5_digest": "1bde2e3660b64165714a905fd2449a87", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 160038, "upload_time": "2017-12-30T13:47:00", "url": "https://files.pythonhosted.org/packages/ff/89/e272fd059daea2dcc43d8c5bb921840145c8916f61d700e6a17deaba55e8/gensvm-0.1.6.tar.gz" } ], "0.1.7": [ { "comment_text": "", "digests": { "md5": "efbc8537983b9917120d26fa305ee303", "sha256": "884aa74e16e12cdfc52dbef149f9a1908eb6dadbb3729561c9573b54263ec7ac" }, "downloads": -1, "filename": "gensvm-0.1.7.tar.gz", "has_sig": false, "md5_digest": "efbc8537983b9917120d26fa305ee303", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 160274, "upload_time": "2018-02-28T16:25:44", "url": "https://files.pythonhosted.org/packages/a1/fb/f0f3976b83fb02067076727a0774a37a4e5b1565b6cfe29b97be38fc3ab2/gensvm-0.1.7.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "e60138f8426e49f4119f447c28c38439", "sha256": "8b1b7ac9d2398b2ab5bf4c000a8c92837c241c63b89b0bdb53738064f9f78804" }, "downloads": -1, "filename": "gensvm-0.2.0.tar.gz", "has_sig": false, "md5_digest": "e60138f8426e49f4119f447c28c38439", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 188475, "upload_time": "2019-03-07T16:56:35", "url": "https://files.pythonhosted.org/packages/38/b8/1a9f2693e65ecda52cf83560cfaf184e78c51d0e56ea08cbd10e1eefcc66/gensvm-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "fd46c50b342a7cf25478b893bc448c95", "sha256": "6338235c58b6896d3e66afcd1c5f26e6b40dae9e0c91aabd8200faa2003f2e8b" }, "downloads": -1, "filename": "gensvm-0.2.1.tar.gz", "has_sig": false, "md5_digest": "fd46c50b342a7cf25478b893bc448c95", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 188759, "upload_time": "2019-03-07T17:56:06", "url": "https://files.pythonhosted.org/packages/03/0a/cdee188ae458349c03a3fc6f05df05f517f9651d1ef4f0125a2bab39408a/gensvm-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "c5cbd810911a2bf996f18a8324dac7d1", "sha256": "638b60fde965d2ad95626ac4cec96e62fc8ec4991fb30fb6f0d22cd13eefe934" }, "downloads": -1, "filename": "gensvm-0.2.2.tar.gz", "has_sig": false, "md5_digest": "c5cbd810911a2bf996f18a8324dac7d1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 189079, "upload_time": "2019-03-08T01:30:35", "url": "https://files.pythonhosted.org/packages/6a/1a/ad6b51035a4d64b6581329369840606f72bb9554a6c3296b4d74a7fc3c5e/gensvm-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "b3f87d2099090fcbf9c6d522842da274", "sha256": "8ef296650ac3a93d90cbf2b54100f9b53f0af43449fff7cb932905fcdc082d57" }, "downloads": -1, "filename": "gensvm-0.2.3.tar.gz", "has_sig": false, "md5_digest": "b3f87d2099090fcbf9c6d522842da274", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 189149, "upload_time": "2019-05-17T19:18:31", "url": "https://files.pythonhosted.org/packages/70/e2/0e4971e310d81fb7768631d107cea68e32b628c72af8966c4191d50d29e2/gensvm-0.2.3.tar.gz" } ], "0.2.4": [ { "comment_text": "", "digests": { "md5": "b6455b8a65c988a171f1b4e47657aab1", "sha256": "df35c2ec8703841afda8bab8c5f6d9758577a2e6881240dc90747b96d5a8fd27" }, "downloads": -1, "filename": "gensvm-0.2.4.tar.gz", "has_sig": false, "md5_digest": "b6455b8a65c988a171f1b4e47657aab1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 189873, "upload_time": "2019-05-30T16:35:22", "url": "https://files.pythonhosted.org/packages/fe/f0/dd2c7006c509b62bb40acb9d4f41937a7834afde431610a1a4e9ea055fb1/gensvm-0.2.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b6455b8a65c988a171f1b4e47657aab1", "sha256": "df35c2ec8703841afda8bab8c5f6d9758577a2e6881240dc90747b96d5a8fd27" }, "downloads": -1, "filename": "gensvm-0.2.4.tar.gz", "has_sig": false, "md5_digest": "b6455b8a65c988a171f1b4e47657aab1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 189873, "upload_time": "2019-05-30T16:35:22", "url": "https://files.pythonhosted.org/packages/fe/f0/dd2c7006c509b62bb40acb9d4f41937a7834afde431610a1a4e9ea055fb1/gensvm-0.2.4.tar.gz" } ] }