# -*- coding: utf-8 -*-
"""Copy of Copy of paulo_svm_ex1_adaptado_para_base_Churn_Modelling.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1SOayCr0K6MghlFMqjZMXA4JbM9XFtOxq
"""

# Support Vector Machine (SVM)
# from https://www.superdatascience.com/machine-learning/ 


# Part 1 - Data Preprocessing

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

import os
import tarfile
from six.moves import urllib

FILE_TO_DOWNLOAD =  "Churn_Modelling.csv"
DOWNLOAD_ROOT = "https://github.com/ect-info/ml/raw/master/"
DATA_PATH = "dados/"
DATA_URL = DOWNLOAD_ROOT + DATA_PATH + FILE_TO_DOWNLOAD

def fetch_data(data_url=DATA_URL, data_path=DATA_PATH, file_to_download=FILE_TO_DOWNLOAD):
  if not os.path.isdir(data_path):
    os.makedirs(data_path)
  urllib.request.urlretrieve(data_url, data_path+file_to_download)
  
  
fetch_data()

# observando se o diretório datasets foi criado com sucesso 
##!ls dados

# Importing the dataset
dataset = pd.read_csv(DATA_PATH+FILE_TO_DOWNLOAD)


dataset.head(  )

X = dataset.iloc[:,[3,6,7,8,9,10,11,12]].values
y = dataset.iloc[:,13].values

print(X[0:6,:])

# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)

# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

# Fitting SVM to the Training set
from sklearn.svm import SVC
classifier = SVC(kernel = 'rbf', random_state = 0,C=100)
classifier.fit(X_train, y_train)

# Predicting the Test set results
y_pred = classifier.predict(X_test)

print(y_test[0:35])
print(y_pred[0:35])

# Making the Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)

print(cm)

total = (cm[0,0]+cm[0,1]+cm[1,0]+cm[1,1])

pp = (cm[0,0]/total*100)
fp = (cm[0,1]/total*100)
fn = (cm[1,0]/total*100)
nn = (cm[1,1]/total*100)

print ("\n")
print ("TOTAL POSITIVO = {:.2f}".format(pp+fp))
print ("PP = {:.2f}".format(pp))
print ("FP = {:.2f}".format(fp))
print ("\n")
print ("TOTAL NEGATIVO = {:.2f}".format(fn+nn))
print ("FN = {:.2f}".format(fn))
print ("NN = {:.2f}".format(nn))

print ("TOTAL = ", pp+fp+fn+nn)
print ("\n")

print ("SHOOOOW SHOOOOW  professor  ???")





