-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code.py
53 lines (39 loc) · 1.6 KB
/
Code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import classification_report, confusion_matrix
from sklearn.model_selection import GridSearchCV
cancer = load_breast_cancer()
dataFrame = pd.DataFrame(np.c_[cancer['data'], cancer['target']], columns = np.append(cancer['feature_names'], ['target']))
#Graphs
sns.pairplot(dataFrame, hue = 'target', vars = ['mean radius', 'mean texture', 'mean perimeter', 'mean area', 'mean smoothness'])
#Heat Map
plt.figure(figsize = (20, 20))
sns.heatmap(dataFrame.corr(), annot = True)
#Count Plot
sns.countplot(dataFrame['target'])
#Scatter Plot
sns.scatterplot(x = 'mean area', y = 'mean smoothness', hue = 'target', data = dataFrame)
x = dataFrame.drop(['target'], axis = 1)
y = dataFrame['target']
xTrain, xTest, yTrain, yTest = train_test_split(x, y, test_size = 0.2, random_state = 42)
svcModel = SVC()
minTrain = xTrain.min()
rangeTrain = (xTrain - minTrain).max()
xTrainScaled = (xTrain - minTrain) / rangeTrain
minTest = xTest.min()
rangeTest = (xTest - minTest).max()
xTestScaled = (xTest - minTest) / rangeTest
svcModel.fit(xTrainScaled, yTrain)
yPredictScaled = svcModel.predict(xTestScaled)
Grid = GridSearchCV(SVC(), paramGrid, refit = True, verbose = 2)
Grid.fit(xTrainScaled, yTrain)
print(Grid.best_params_)
gridPredictions = Grid.predict(xTestScaled)
cn = confusion_matrix(yTest, gridPredictions)
sns.heatmap(cn, annot = True)
print(classification_report(yTest, gridPredictions))