Created
February 29, 2020 20:53
-
-
Save dtellogaete/67935a06acd5d19fa040959882a643e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Importar librerías | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
# Importar el dataset de training | |
dataset = pd.read_csv('Social_Network_Ads.csv') | |
dataset['Age'] = dataset['Age'].fillna(dataset['Age'].mean()) | |
dataset['EstimatedSalary'] = dataset['EstimatedSalary'].fillna(dataset['EstimatedSalary'].mean()) | |
X = dataset.iloc[:len(dataset),[2,3]].values | |
y = dataset.iloc[:len(dataset), -1] | |
# Dividir dataset en conjunto de entrenamiento y conjunto de testing | |
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) | |
# Escalado de variables | |
from sklearn.preprocessing import StandardScaler | |
sc_X = StandardScaler() | |
X_train = sc_X.fit_transform(X_train) | |
X_test = sc_X.transform(X_test) | |
# Aplicación del modelo con gradient descent | |
regression = LogisticRegressionGD(l_rate = 0.0000001, n_iter = 20000) | |
coef = regression.fit(X_train, y_train) | |
y_predict = regression.predict(X_test) | |
# Aplicación del modelo con librería de sklearn | |
from sklearn.linear_model import LogisticRegression | |
logistic = LogisticRegression(random_state = 0) | |
logistic.fit(X_train, y_train) | |
y_predict_py = logistic.predict(X_test) | |
# Matriz de confusión para ver resultados finales | |
from sklearn.metrics import confusion_matrix | |
cm_sklearn = confusion_matrix(y_test, y_predict_py) | |
cm_GD = confusion_matrix(y_test, y_predict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment