{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# SVM (Support Vector Machines)\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Importing Needed packages" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "from sklearn import preprocessing, svm\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.metrics import classification_report, confusion_matrix, f1_score\n", "import itertools\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline " ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false } }, "source": [ "## Load the Cancer data\n", "\n", "The example is based on a dataset that is publicly available from the UCI Machine Learning Repository (Asuncion and Newman, 2007) http://mlearn.ics.uci.edu/MLRepository.html. The dataset consists of several hundred human cell sample records, each of which contains the values of a set of cell characteristics. The fields in each record are:\n", "\n", "|Field name|Description|\n", "|--- |--- |\n", "|ID|Clump thickness|\n", "|Clump|Clump thickness|\n", "|UnifSize|Uniformity of cell size|\n", "|UnifShape|Uniformity of cell shape|\n", "|MargAdh|Marginal adhesion|\n", "|SingEpiSize|Single epithelial cell size|\n", "|BareNuc|Bare nuclei|\n", "|BlandChrom|Bland chromatin|\n", "|NormNucl|Normal nucleoli|\n", "|Mit|Mitoses|\n", "|Class|Benign or malignant|\n" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false } }, "source": [ "### Load Data From CSV File " ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false } }, "outputs": [ { "data": { "text/html": [ "
\n", " | ID | \n", "Clump | \n", "UnifSize | \n", "UnifShape | \n", "MargAdh | \n", "SingEpiSize | \n", "BareNuc | \n", "BlandChrom | \n", "NormNucl | \n", "Mit | \n", "Class | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "1000025 | \n", "5 | \n", "1 | \n", "1 | \n", "1 | \n", "2 | \n", "1 | \n", "3 | \n", "1 | \n", "1 | \n", "2 | \n", "
1 | \n", "1002945 | \n", "5 | \n", "4 | \n", "4 | \n", "5 | \n", "7 | \n", "10 | \n", "3 | \n", "2 | \n", "1 | \n", "2 | \n", "
2 | \n", "1015425 | \n", "3 | \n", "1 | \n", "1 | \n", "1 | \n", "2 | \n", "2 | \n", "3 | \n", "1 | \n", "1 | \n", "2 | \n", "
3 | \n", "1016277 | \n", "6 | \n", "8 | \n", "8 | \n", "1 | \n", "3 | \n", "4 | \n", "3 | \n", "7 | \n", "1 | \n", "2 | \n", "
4 | \n", "1017023 | \n", "4 | \n", "1 | \n", "1 | \n", "3 | \n", "2 | \n", "1 | \n", "3 | \n", "1 | \n", "1 | \n", "2 | \n", "