0
にストレートの境界線をプロット私は(質問の本質ではない私は、Pythonを選択している可能性が)Rで働くために演習の1つを得たは手動パーセプトロン
[材料はCoursera Machine Learning course by Andrew Ngに属し] 、その上に境界決定ラインと次のプロットを得た:残りはなかった一方で
赤のポイントは、大学に入院しました。
の質問はどのように-するプロット上の行を取得ではなく、なぜコース教材からRに対応したコードに次の行が動作ん:
y = c((-1/coefs[3]) * (coefs[2] * x + coefs[1]))
をだからであります実際にはこのコマンドを支える数学について尋ねています。係数はロジスティック回帰係数に対応する。
Here is the dataset、ここで全体のコードです:
dat = read.csv("perceptron.txt", header=F)
is.data.frame(dat)
colnames(dat) = c("test1","test2","y")
head(dat)
plot(test2 ~ test1, col = as.factor(y), pch = 20, data=dat)
fit = glm(y ~ test1 + test2, family = "binomial", data = dat)
coefs = coef(fit)
(x = c(min(dat[,1])-2, max(dat[,1])+2))
(y = c((-1/coefs[3]) * (coefs[2] * x + coefs[1])))
lines(x, y)