Tuesday, September 1, 2020

XOR

d <- data.frame(y=c(0, 1, 1, 0),
  x1=c(1, 1, 0, 0), x2=c(1, 0, 1, 0))
f <- glm(y~x1*x2, data=d, family=binomial(link="logit"))

> f$coefficients
(Intercept)          x1          x2       x1:x2 
  -23.56607    47.13214    47.13214   -94.26427
> f$fitted.values
           1            2            3            4 
5.826215e-11 1.000000e+00 1.000000e+00 5.826215e-11 
> f$fitted.values > 0.5
    1     2     3     4 
FALSE  TRUE  TRUE FALSE 

No comments: