-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreastCancerExample.py
59 lines (48 loc) · 1.47 KB
/
breastCancerExample.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
54
55
56
57
58
59
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 16 09:37:17 2017
@author: cecil
"""
#
#import numpy as np
#from sklearn import preprocessing, cross_validation, neighbors, svm
#import pandas as pd
#
#df = pd.read_csv('breast-cancer-wisconsin.data.txt')
#df.replace('?',-99999, inplace=True)
#df.drop(['id'],1,inplace=True)
#
#X = np.array(df.drop(['class'],1))
#y = np.array(df['class'])
#
#X_train, X_test, y_train, y_test = cross_validation.train_test_split(X,y,test_size=0.2)
#
#clf = neighbors.KNeighborsClassifier()
#clf.fit(X_train, y_train)
#
#accuracy = clf.score(X_test, y_test)
#print(accuracy)
#
#example_measures = np.array([[4,2,1,1,1,2,3,2,1],[4,2,1,2,2,2,3,2,1]])
#
#example_measures = example_measures.reshape(len(example_measures), -1)
#
#prediction = clf.predict(example_measures)
#print(prediction)
import numpy as np
from sklearn import preprocessing, cross_validation, neighbors, svm
import pandas as pd
df = pd.read_csv('breast-cancer-wisconsin.data.txt')
df.replace('?',-99999, inplace=True)
df.drop(['id'],1,inplace=True)
X = np.array(df.drop(['class'],1))
y = np.array(df['class'])
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X,y,test_size=0.2)
clf = svm.SVC()
clf.fit(X_train, y_train)
accuracy = clf.score(X_test, y_test)
print(accuracy)
example_measures = np.array([[4,2,1,1,1,2,3,2,1],[4,2,1,2,2,2,3,2,1]])
example_measures = example_measures.reshape(len(example_measures), -1)
prediction = clf.predict(example_measures)
print(prediction)