{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": false, "deletable": true, "editable": true }, "source": [ "##
Support Vector Machines (SVMs) in scikit-learn
\n", "\n", "- for classification and regression (SVCs, SVRs)\n", "- can be applied on linear and non-linear data\n", "- look for the best separating line or decision boundary\n", "- look for the largest margin " ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "![](SVM.png)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "![](SVM2.png)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true, "deletable": true, "editable": true }, "source": [ "![](SVM3.png)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "### Commonly used kernels:\n", "\n", "- linear\n", "- polynomial\n", "- radial basis function (RBF) - Gaussian RBF\n", "- sigmoid\n", "- etc." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The accuracy on the training subset: 1.000\n", "The accuracy on the test subset: 0.629\n" ] } ], "source": [ "from sklearn.svm import SVC \n", "from sklearn.model_selection import train_test_split\n", "from sklearn.datasets import load_breast_cancer\n", "\n", "cancer = load_breast_cancer()\n", "X_train, X_test, y_train, y_test = train_test_split(cancer.data, cancer.target, random_state=0)\n", "\n", "svm = SVC()\n", "svm.fit(X_train, y_train)\n", "\n", "print('The accuracy on the training subset: {:.3f}'.format(svm.score(X_train, y_train)))\n", "print('The accuracy on the test subset: {:.3f}'.format(svm.score(X_test, y_test)))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.0" } }, "nbformat": 4, "nbformat_minor": 2 }