<jupyter_start><jupyter_text>Clonamos el repositorio para obtener los dataSet<jupyter_code>!git clone https://github.com/joanby/python-ml-course.git<jupyter_output><empty_output><jupyter_text>Damos acceso a nuestro Drive<jupyter_code>from google.colab import drive
drive.mount('/content/drive')
# Test it
!ls '/content/drive/My Drive' 
from google.colab import files # Para manejar los archivos y, por ejemplo, exportar a su navegador
import glob # Para manejar los archivos y, por ejemplo, exportar a su navegador
from google.colab import drive # Montar tu Google drive<jupyter_output><empty_output><jupyter_text>K Nearest Neighbors<jupyter_code>import numpy as np
from sklearn import preprocessing, neighbors
from sklearn. model_selection import cross_val_score
import pandas as pd
df = pd.read_csv("/content/python-ml-course/datasets/cancer/breast-cancer-wisconsin.data.txt", header=None)

df.head()
df.describe()
df.columns = ["name", "V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "class"]
df.head()
df = df.drop(["name"],1)
df.replace("?", -99999, inplace=True)
Y = df["class"]
X = df[["V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9"]]
X.head()
Y.head()<jupyter_output><empty_output><jupyter_text>Clasificador de los K vecinos<jupyter_code>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)
accuracy<jupyter_output><empty_output><jupyter_text>Clasificación sin limpieza<jupyter_code>df = pd.read_csv("/content/python-ml-course/datasets/cancer/breast-cancer-wisconsin.data.txt", header=None)
df.replace("?", -99999, inplace=True)
df.columns = ["name", "V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "class"]

Y = df["class"]
X = df[["name", "V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9"]]

X_train, X_test, Y_train, Y_test = 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)
accuracy<jupyter_output><empty_output><jupyter_text>Clasificar nuevos datos<jupyter_code>sample_measure = np.array([5,4,2,1,1,1,2,3,2,1])
print(sample_measure)
sample_measure = sample_measure.reshape(1,-1)
predict = clf.predict(sample_measure)
predict
sample_measure2 = np.array([[5,4,2,1,1,1,2,3,2,1], [2,2,4,4,2,2,6,2,4,5]]).reshape(2,-1)
predict = clf.predict(sample_measure2)
predict<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1738599348534202, 'fraction_numerical': 0.035423452768729644, 'mean_word_length': 7.328813559322034, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '483749', 'license': 'MIT', 'n_tokens_mistral': 1045, 'n_tokens_neox': 1027, 'n_words': 194, 'path': 'notebooks/T9 - 1 - K Nearest Neighbors-Colab.ipynb', 'repo_name': 'diego1193/python-ml-course', 'size': '2456'}