|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# importing the modules" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": 1, |
| 13 | + "metadata": { |
| 14 | + "collapsed": true |
| 15 | + }, |
| 16 | + "outputs": [], |
| 17 | + "source": [ |
| 18 | + "#importin the library from the pip\n", |
| 19 | + "#installing libraries \n", |
| 20 | + "#pip3 install numpy, pandas, scikit\n", |
| 21 | + "import numpy as np\n", |
| 22 | + "import pandas as pd\n", |
| 23 | + "from sklearn import datasets" |
| 24 | + ] |
| 25 | + }, |
| 26 | + { |
| 27 | + "cell_type": "markdown", |
| 28 | + "metadata": {}, |
| 29 | + "source": [ |
| 30 | + "# Loading the Data" |
| 31 | + ] |
| 32 | + }, |
| 33 | + { |
| 34 | + "cell_type": "code", |
| 35 | + "execution_count": 2, |
| 36 | + "metadata": { |
| 37 | + "collapsed": true |
| 38 | + }, |
| 39 | + "outputs": [], |
| 40 | + "source": [ |
| 41 | + "#this is the import dataset from the scikit learn\n", |
| 42 | + "wine = datasets.load_wine()" |
| 43 | + ] |
| 44 | + }, |
| 45 | + { |
| 46 | + "cell_type": "markdown", |
| 47 | + "metadata": {}, |
| 48 | + "source": [ |
| 49 | + "# Features and Labels" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "code", |
| 54 | + "execution_count": 3, |
| 55 | + "metadata": { |
| 56 | + "collapsed": true |
| 57 | + }, |
| 58 | + "outputs": [], |
| 59 | + "source": [ |
| 60 | + "#here x denotes to the Features For the Data\n", |
| 61 | + "X = wine.data\n", |
| 62 | + "#here y denotes to the Labels for the data\n", |
| 63 | + "\"\"\"target is the labels for the data it consists of the classes or the prediction values\"\"\"\n", |
| 64 | + "y = wine.target" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "cell_type": "markdown", |
| 69 | + "metadata": {}, |
| 70 | + "source": [ |
| 71 | + "# Train_Test_Split" |
| 72 | + ] |
| 73 | + }, |
| 74 | + { |
| 75 | + "cell_type": "code", |
| 76 | + "execution_count": 4, |
| 77 | + "metadata": { |
| 78 | + "collapsed": true |
| 79 | + }, |
| 80 | + "outputs": [], |
| 81 | + "source": [ |
| 82 | + "\"\"\"here we will separate the into the parts train part and the test part and into the split part of the data\n", |
| 83 | + "X_train, y_train consists of the only training features and the labels Example:- train_size = 0.8 it will consider \n", |
| 84 | + "80 persent training and 20 persent test (X_test, y_test)\"\"\"\n", |
| 85 | + "from sklearn.model_selection import train_test_split\n", |
| 86 | + "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state = 0)" |
| 87 | + ] |
| 88 | + }, |
| 89 | + { |
| 90 | + "cell_type": "markdown", |
| 91 | + "metadata": {}, |
| 92 | + "source": [ |
| 93 | + "# Standerlization" |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "code", |
| 98 | + "execution_count": 5, |
| 99 | + "metadata": { |
| 100 | + "collapsed": true |
| 101 | + }, |
| 102 | + "outputs": [], |
| 103 | + "source": [ |
| 104 | + "\"\"\"Here we are going to discuss about the scaling techniques the main important scaling technique is StandardScaler\n", |
| 105 | + "which will allow Data in Between the [1, 0] Tis is one of the most import preprocessing technique\"\"\"\n", |
| 106 | + "\n", |
| 107 | + "from sklearn.preprocessing import StandardScaler\n", |
| 108 | + "sc = StandardScaler()\n", |
| 109 | + "X_train = sc.fit_transform(X_train)\n", |
| 110 | + "X_test = sc.transform(X_test)" |
| 111 | + ] |
| 112 | + }, |
| 113 | + { |
| 114 | + "cell_type": "markdown", |
| 115 | + "metadata": {}, |
| 116 | + "source": [ |
| 117 | + "# SVM(Support Vector Machine)" |
| 118 | + ] |
| 119 | + }, |
| 120 | + { |
| 121 | + "cell_type": "code", |
| 122 | + "execution_count": 6, |
| 123 | + "metadata": {}, |
| 124 | + "outputs": [ |
| 125 | + { |
| 126 | + "data": { |
| 127 | + "text/plain": [ |
| 128 | + "SVC(C=1, cache_size=200, class_weight=None, coef0=0.0,\n", |
| 129 | + " decision_function_shape='ovr', degree=3, gamma='auto_deprecated',\n", |
| 130 | + " kernel='rbf', max_iter=-1, probability=False, random_state=0,\n", |
| 131 | + " shrinking=True, tol=0.001, verbose=False)" |
| 132 | + ] |
| 133 | + }, |
| 134 | + "execution_count": 6, |
| 135 | + "metadata": {}, |
| 136 | + "output_type": "execute_result" |
| 137 | + } |
| 138 | + ], |
| 139 | + "source": [ |
| 140 | + "\"\"\"we are importing Support vector Machine from the Scikit Learn \n", |
| 141 | + "Present we are working with SVC(Support Vector Classifier) \n", |
| 142 | + "C is the most important parameter which says about the regularization and create good Hyper perameter line \n", |
| 143 | + "in the algorithm and also know as Penalty parameter C of the error term, random_state is the parameter which will use as the seed function it will work with \n", |
| 144 | + "random numbers , Kernel is the used to use for to solve non-linear complex dimention(Features) in the data set\n", |
| 145 | + "degree is used for only the poly nomial kernels , (rbf, linear, poly, sigmoid)\"\"\"\n", |
| 146 | + "from sklearn.svm import SVC\n", |
| 147 | + "ppn = SVC(C=1, random_state = 0)\n", |
| 148 | + "ppn.fit(X_train,y_train)" |
| 149 | + ] |
| 150 | + }, |
| 151 | + { |
| 152 | + "cell_type": "markdown", |
| 153 | + "metadata": {}, |
| 154 | + "source": [ |
| 155 | + "# predicting" |
| 156 | + ] |
| 157 | + }, |
| 158 | + { |
| 159 | + "cell_type": "code", |
| 160 | + "execution_count": 7, |
| 161 | + "metadata": { |
| 162 | + "collapsed": true |
| 163 | + }, |
| 164 | + "outputs": [], |
| 165 | + "source": [ |
| 166 | + "y_pred = ppn.predict(X_test)" |
| 167 | + ] |
| 168 | + }, |
| 169 | + { |
| 170 | + "cell_type": "markdown", |
| 171 | + "metadata": {}, |
| 172 | + "source": [ |
| 173 | + "# misscalssification" |
| 174 | + ] |
| 175 | + }, |
| 176 | + { |
| 177 | + "cell_type": "code", |
| 178 | + "execution_count": 8, |
| 179 | + "metadata": {}, |
| 180 | + "outputs": [ |
| 181 | + { |
| 182 | + "data": { |
| 183 | + "text/plain": [ |
| 184 | + "0" |
| 185 | + ] |
| 186 | + }, |
| 187 | + "execution_count": 8, |
| 188 | + "metadata": {}, |
| 189 | + "output_type": "execute_result" |
| 190 | + } |
| 191 | + ], |
| 192 | + "source": [ |
| 193 | + "(y_pred != y_test).sum()" |
| 194 | + ] |
| 195 | + }, |
| 196 | + { |
| 197 | + "cell_type": "markdown", |
| 198 | + "metadata": {}, |
| 199 | + "source": [ |
| 200 | + "# Accuracy" |
| 201 | + ] |
| 202 | + }, |
| 203 | + { |
| 204 | + "cell_type": "code", |
| 205 | + "execution_count": 9, |
| 206 | + "metadata": { |
| 207 | + "scrolled": true |
| 208 | + }, |
| 209 | + "outputs": [ |
| 210 | + { |
| 211 | + "data": { |
| 212 | + "text/plain": [ |
| 213 | + "1.0" |
| 214 | + ] |
| 215 | + }, |
| 216 | + "execution_count": 9, |
| 217 | + "metadata": {}, |
| 218 | + "output_type": "execute_result" |
| 219 | + } |
| 220 | + ], |
| 221 | + "source": [ |
| 222 | + "from sklearn.metrics import accuracy_score\n", |
| 223 | + "accuracy_score(y_test, y_pred)" |
| 224 | + ] |
| 225 | + }, |
| 226 | + { |
| 227 | + "cell_type": "raw", |
| 228 | + "metadata": { |
| 229 | + "collapsed": true |
| 230 | + }, |
| 231 | + "source": [] |
| 232 | + }, |
| 233 | + { |
| 234 | + "cell_type": "code", |
| 235 | + "execution_count": null, |
| 236 | + "metadata": { |
| 237 | + "collapsed": true |
| 238 | + }, |
| 239 | + "outputs": [], |
| 240 | + "source": [] |
| 241 | + }, |
| 242 | + { |
| 243 | + "cell_type": "code", |
| 244 | + "execution_count": null, |
| 245 | + "metadata": { |
| 246 | + "collapsed": true |
| 247 | + }, |
| 248 | + "outputs": [], |
| 249 | + "source": [] |
| 250 | + } |
| 251 | + ], |
| 252 | + "metadata": { |
| 253 | + "kernelspec": { |
| 254 | + "display_name": "Python 3", |
| 255 | + "language": "python", |
| 256 | + "name": "python3" |
| 257 | + }, |
| 258 | + "language_info": { |
| 259 | + "codemirror_mode": { |
| 260 | + "name": "ipython", |
| 261 | + "version": 3 |
| 262 | + }, |
| 263 | + "file_extension": ".py", |
| 264 | + "mimetype": "text/x-python", |
| 265 | + "name": "python", |
| 266 | + "nbconvert_exporter": "python", |
| 267 | + "pygments_lexer": "ipython3", |
| 268 | + "version": "3.6.7" |
| 269 | + } |
| 270 | + }, |
| 271 | + "nbformat": 4, |
| 272 | + "nbformat_minor": 2 |
| 273 | +} |
0 commit comments