2016-06-25 22 views
0

これは実際にはthis questionの繰り返しです。しかし、私は初歩的な "マニュアル"コーディング実験で得られたパーセプトロン係数に基づいて決定境界線のプロットに関する非常に具体的な質問をしたいと思います。あなたは素敵な意思決定の境界線でのロジスティック回帰の結果から抽出された係数を見ることができるように:パーセプトロン係数に基づく分類判定境界線のプロット

enter image description here

glm()結果に基づいて:

(Intercept)  test1  test2 
    1.718449 4.012903 3.743903 

パーセプトロン実験上の係数は根本的に異なっています:

 bias  test1  test2 
9.131054 19.095881 20.736352 

回答を容易にするため、here is the dataコード:

# DATA PRE-PROCESSING: 
dat = read.csv("perceptron.txt", header=F) 
dat[,1:2] = apply(dat[,1:2], MARGIN = 2, FUN = function(x) scale(x)) # scaling the data 
data = data.frame(rep(1,nrow(dat)), dat) # introducing the "bias" column 
colnames(data) = c("bias","test1","test2","y") 
data$y[data$y==0] = -1 # Turning 0/1 dependent variable into -1/1. 
data = as.matrix(data) # Turning data.frame into matrix to avoid mmult problems. 

# PERCEPTRON: 
set.seed(62416) 
no.iter = 1000       # Number of loops 
theta = rnorm(ncol(data) - 1)   # Starting a random vector of coefficients. 
theta = theta/sqrt(sum(theta^2))   # Normalizing the vector. 
h = theta %*% t(data[,1:3])    # Performing the first f(theta^T X) 

for (i in 1:no.iter){     # We will recalculate 1,000 times 
    for (j in 1:nrow(data)){    # Each time we go through each example. 
     if(h[j] * data[j, 4] < 0){   # If the hypothesis disagrees with the sign of y, 
     theta = theta + (sign(data[j,4]) * data[j, 1:3]) # We + or - the example from theta. 
     } 
     else 
     theta = theta      # Else we let it be. 
    } 
    h = theta %*% t(data[,1:3])   # Calculating h() after iteration. 
} 
theta         # Final coefficients 
mean(sign(h) == data[,4])    # Accuracy 

QUESTION:我々は唯一のパーセプトロン係数を持っている場合はどのように境界線を(私はロジスティック回帰係数を用いて上記したよう)をプロットするには?

答えて

0

まあ... case of logistic regressionの場合とまったく同じで、横座標(テスト1)の最小値と最大値を選んでわずかなマージンを加え、対応するテスト決定境界(0 = theta_o + theta_1 test1 + theta_2 test2)で2つの値、及び点の間に線を引く:ときシータは^ TX> 0、それはのように分類するように

palette(c("tan3","purple4")) 
plot(test2 ~ test1, col = as.factor(y), pch = 20, data=data, 
    main="College admissions") 
(x = c(min(data[,2])-.2, max(data[,2])+ .2)) 
(y = c((-1/theta[3]) * (theta[2] * x + theta[1]))) 
lines(x, y, lwd=3, col=rgb(.7,0,.2,.5)) 

enter image description here

-1

パーセプトロンの重みを算出します正であり、かつθ= TXのとき< 0負に分類されます。これは、方程式theta^T Xがパーセプトロンの決定境界であることを意味します。

ロジスティック回帰には同じロジックが適用されますが、現在のシグモイド(theta^T X)> 0.5は例外です。

+0

シグモイド関数の通常のしきい値は0.5で、これはTheta^T Xのゼロを通過することに対応します。 – Toni

+0

あなたは正しいです。私はシグモイドが0から1になるのを忘れていました。 – Alex

+0

私の質問は非常に具体的だと思うし、誰かがそれから恩恵を受けることができる場合に備えて答えを残しました。同様の質問)。 – Toni

関連する問題