[R] Obtaining predicted probabilities for Logistic regression

Christofer Bogaso bog@@o@chr|@to|er @end|ng |rom gm@||@com
Sat Jul 13 13:13:41 CEST 2024


Hi,

I ran below code

Dat = read.csv('https://raw.githubusercontent.com/sam16tyagi/Machine-Learning-techniques-in-python/master/logistic%20regression%20dataset-Social_Network_Ads.csv')
head(Dat)
Model = glm(Purchased ~ Gender, data = Dat, family = binomial())
head(predict(Model, type="response"))
My_Predict = 1/(1+exp(-1 * (as.vector(coef(Model))[1] *
as.vector(coef(Model))[2] * ifelse(Dat['Gender'] == "Male", 1, 0))))
head(My_Predict)

However, My_Predict and predict(Model, type="response")) are differing
when I tried to manually calculate prediction.

Could you please help to identify what was the mistake I made?



More information about the R-help mailing list