-
Notifications
You must be signed in to change notification settings - Fork 0
/
Breast Cancer Classifier Project.txt
33 lines (26 loc) · 1.17 KB
/
Breast Cancer Classifier Project.txt
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
import codecademylib3_seaborn
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
import matplotlib.pyplot as plt
breast_cancer_data = load_breast_cancer()
print(breast_cancer_data.data[0])
print(breast_cancer_data.feature_names)
print(breast_cancer_data.target)
print(breast_cancer_data.target_names)
train_test_split(breast_cancer_data.data,breast_cancer_data.target,test_size = 0.2,random_state = 100)
training_data,validation_data, training_labels, validation_labels = train_test_split(breast_cancer_data.data,breast_cancer_data.target,test_size = 0.2,random_state = 100)
print(len(training_data))
print(len(training_labels))
accuracies = []
for k in range(1,101):
classifier = KNeighborsClassifier(n_neighbors=k)
classifier.fit(training_data, training_labels)
print(classifier.score(validation_data, validation_labels))
accuracies.append(classifier.score(validation_data, validation_labels))
k_list = range(1,101)
plt.plot(k_list,accuracies)
plt.xlabel("k")
plt.ylabel("Validation Accuracy")
plt.title("Breast Cancer Classifier Accuracy")
plt.show()