Created
February 29, 2020 20:54
-
-
Save dtellogaete/a6db70c6c9ec457c2e11ba4edd0d8937 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
# Regresion logística | |
# Importar dataset | |
dataset = read.csv('Social_Network_Ads.csv') | |
dataset = dataset[, 3:5] | |
# Selección conjunto de entrenamiento y test | |
library(caTools) | |
set.seed(0) | |
split = sample.split(dataset$Purchased, SplitRatio = 0.75) | |
training = subset(dataset, split == TRUE) | |
testing = subset(dataset, split == FALSE) | |
# Escalado de variables | |
training[1:2] = data.frame(scale(training[1:2])) | |
testing[1:2] = data.frame(scale(testing[1:2])) | |
# Aplicación de modelo de regresión logística con la función glm | |
logistic = glm(formula = Purchased ~ ., | |
data = training, | |
family = binomial) | |
# Predicción de los resultados conjunto de testing | |
prob_pred = predict(logistic, type = "response", | |
newdata = testing[,-3]) | |
y_predict = ifelse(prob_pred>=0.5, 1, 0) | |
# Matriz de confusión | |
cm = table(testing[,3], y_predict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment