#!/usr/bin/env python # coding: utf-8 # In[1]: # Tratamiento de datos # ============================================================================== import pandas as pd import numpy as np # Preprocesado y modelado # ============================================================================== from sklearn.svm import SVC from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score # Configuración warnings # ============================================================================== import warnings warnings.filterwarnings('ignore') # In[2]: #Cargamos los datos! url = 'https://raw.githubusercontent.com/JoaquinAmatRodrigo/' \ + 'Estadistica-machine-learning-python/master/data/ESL.mixture.csv' datos = pd.read_csv(url) datos.head() # In[3]: #Visualizacion! import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=(6,4)) ax.scatter(datos.X1, datos.X2, c=datos.y); ax.set_title("Datos"); # In[4]: # División de los datos en train y test X = datos.drop(columns = 'y') y = datos['y'] # In[5]: X # In[6]: y # In[7]: X_train, X_test, y_train, y_test = train_test_split(X,y.values.reshape(-1,1),train_size= 0.7,random_state = 42,shuffle=True) # In[8]: # Creación del modelo SVM modelo = SVC(C = 100, kernel = 'linear', random_state=42) modelo.fit(X_train, y_train) # In[9]: #Predicciones! y_test_pred = modelo.predict(X_test) # A lo largo de este notebook, se solicita calcular las métricas requeridas como así también su correspondiente interpretación: # # 1. Calcular la métrica Accuracy. # In[10]: ###Completar from sklearn.metrics import accuracy_score accuracy_score(y_test,y_test_pred) # 2. Crear la Matriz de Confusión # In[11]: ###Completar from sklearn.metrics import confusion_matrix confusion_matrix(y_test, y_test_pred) # 3. Calcular la métrica F1 score # In[12]: ###Completar from sklearn.metrics import f1_score f1_score(y_test, y_test_pred) # Calcular todas las metricas al tiempo # In[13]: from sklearn.metrics import classification_report reporte=classification_report(y_test,y_test_pred) print(reporte) # # Created in deepnote.com # Created in Deepnote