<filename>Lapaz/Proyecto_1/feminicidio_svm.py<gh_stars>1-10
# -*- coding: utf-8 -*-
"""Feminicidio_SVM

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/17_I4flVZoejinMIGJjevaSpFjHgFkbh8
"""

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

url_dataset = 'https://raw.githubusercontent.com/Marseonji/Feminicidio/master/EL%20VALOR%20DE%20T%C3%9A%20VERDAD%20SVM.csv'
dataset = pd.read_csv(url_dataset,sep= ';')
dataset.head()

dataset['genero'].replace(['Femenino','Masculino'],[0,1],inplace= True)
dataset['clase_social'].replace(['Baja','Media','Alta'],[0,1,2],inplace= True)

dataset['1'].replace(['NO','SI'],[0,1],inplace= True)
dataset['2'].replace(['NO','SI'],[0,1],inplace= True)
dataset['3'].replace(['NO','SI'],[0,1],inplace= True)
dataset['4'].replace(['NO','SI'],[0,1],inplace= True)
dataset['5'].replace(['NO','SI'],[0,1],inplace= True)
dataset['6'].replace(['NO','SI'],[0,1],inplace= True)
dataset['7'].replace(['NO','SI'],[0,1],inplace= True)
dataset['8'].replace(['NO','SI'],[0,1],inplace= True)
dataset['9'].replace(['NO','SI'],[0,1],inplace= True)
dataset['10'].replace(['NO','SI'],[0,1],inplace= True)

dataset = dataset.dropna(axis=0,how='all')

X = dataset.drop(['Target'],axis = 1)
X.head()

dataset['Target'].replace(['NO','SI'],[0,1],inplace= True)
y = dataset['Target']
y.head()

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.2,random_state=20)

print('Tamaño del training "X" es: ',X_train.shape)
print('Tamaño del testing "X" es: ',X_test.shape)
print('Tamaño del training "y" es: ',y_train.shape)
print('Tamaño del testing "y" es: ',y_test.shape)

from sklearn.svm import SVC
svc_model = SVC()

svc_model.fit(X_train,y_train)

print("Precision SVM:")
print(svc_model.score(X_train, y_train))

y_predict = svc_model.predict(X_test)

from sklearn.metrics import classification_report,confusion_matrix

cm = np.array(confusion_matrix(y_test, y_predict, 
                               labels=[1,0]))
confusion = pd.DataFrame(cm, index=['es posible feminicida',
                        'no es posible feminicida'], 
                         columns=['predice si es',
                                'predice si no es'])
confusion
<filename>Lapaz/Proyecto_1/feminicidio_svm.py<gh_stars>1-10
# -*- coding: utf-8 -*-
"""Feminicidio_SVM

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/17_I4flVZoejinMIGJjevaSpFjHgFkbh8
"""

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

url_dataset = 'https://raw.githubusercontent.com/Marseonji/Feminicidio/master/EL%20VALOR%20DE%20T%C3%9A%20VERDAD%20SVM.csv'
dataset = pd.read_csv(url_dataset,sep= ';')
dataset.head()

dataset['genero'].replace(['Femenino','Masculino'],[0,1],inplace= True)
dataset['clase_social'].replace(['Baja','Media','Alta'],[0,1,2],inplace= True)

dataset['1'].replace(['NO','SI'],[0,1],inplace= True)
dataset['2'].replace(['NO','SI'],[0,1],inplace= True)
dataset['3'].replace(['NO','SI'],[0,1],inplace= True)
dataset['4'].replace(['NO','SI'],[0,1],inplace= True)
dataset['5'].replace(['NO','SI'],[0,1],inplace= True)
dataset['6'].replace(['NO','SI'],[0,1],inplace= True)
dataset['7'].replace(['NO','SI'],[0,1],inplace= True)
dataset['8'].replace(['NO','SI'],[0,1],inplace= True)
dataset['9'].replace(['NO','SI'],[0,1],inplace= True)
dataset['10'].replace(['NO','SI'],[0,1],inplace= True)

dataset = dataset.dropna(axis=0,how='all')

X = dataset.drop(['Target'],axis = 1)
X.head()

dataset['Target'].replace(['NO','SI'],[0,1],inplace= True)
y = dataset['Target']
y.head()

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.2,random_state=20)

print('Tamaño del training "X" es: ',X_train.shape)
print('Tamaño del testing "X" es: ',X_test.shape)
print('Tamaño del training "y" es: ',y_train.shape)
print('Tamaño del testing "y" es: ',y_test.shape)

from sklearn.svm import SVC
svc_model = SVC()

svc_model.fit(X_train,y_train)

print("Precision SVM:")
print(svc_model.score(X_train, y_train))

y_predict = svc_model.predict(X_test)

from sklearn.metrics import classification_report,confusion_matrix

cm = np.array(confusion_matrix(y_test, y_predict, 
                               labels=[1,0]))
confusion = pd.DataFrame(cm, index=['es posible feminicida',
                        'no es posible feminicida'], 
                         columns=['predice si es',
                                'predice si no es'])
confusion
# -*- coding: utf-8 -*- Feminicidio_SVM  Automatically generated by Colaboratory.  Original file is located at     https://colab.research.google.com/drive/17_I4flVZoejinMIGJjevaSpFjHgFkbh8