import seaborn as sns
#1
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#13
#2
breast_cancer_data = load_breast_cancer()
print(breast_cancer_data.data[0])
#3
print(breast_cancer_data.target)
print(breast_cancer_data.target_names)
print(breast_cancer_data.feature_names)
#4
train_test_split(
breast_cancer_data.data,
breast_cancer_data.target,
test_size = 0.2,
random_state = 100
)
#5
print(train_test_split(
breast_cancer_data.data,
breast_cancer_data.target,
test_size = 0.2,
random_state = 100
))
#6
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)
#7
print(len(training_data))
print(len(training_labels))
#8-#9
classifier = KNeighborsClassifier(n_neighbors = 3)
#10
classifier.fit(training_data, training_labels)
#11
print(classifier.score(validation_data, validation_labels))
#12
accuracies = [] #<<<<<<<15
for k in range(1, 101):
classifier = KNeighborsClassifier(n_neighbors = k)
classifier.fit(training_data, training_labels)
accuracies.append(classifier.score(validation_data, validation_labels))
print(accuracies)
print(classifier.score(validation_data, validation_labels))
#13
#import matplotlib.pyplot as plt#13^^^^
#14
k_list = range(1, 101)
#15^^^^
#16
plt.plot(k_list, accuracies)
plt.show()
#17
plt.plot(k_list, accuracies)
plt.xlabel('k')
plt.ylabel("Validation Accuracy")
plt.title("Breast Cancer Classifier Accuracy")
plt.show()
# Final..