Total Pageviews

Blog Archive

Teaching (237) Mathematica (155) 3Q (48) Excel (45) SPSS (32) Cat (24) LaTeX (23) Mac (22) 君達呀 (15) Kaohsiung (14) 論文測試 (13) Mathematica教學講義 (3)

 

Followers

Mathematica 教學 Logistic regression

Chung-Yuan Dye 於 Saturday, December 10, 2011 11:56 PM 發表

Logistic regression


data={{1,0},{1,1},{1,1},{2,0},{2,0},{2,1},{2,1},{2,1},{2,1},{3,1},
{3,1},{3,1},{3,1},{3,1}};

(* 成功機率 *)
pi[x_]:=1/(1+Exp[-(a+b*x)])

(* Likelihood function*)
obj=Apply[Times,pi[#[[1]]]^#[[2]]*(1-pi[#[[1]]])^(1-#[[2]])&/@data]

(* 求解a and b *)

FindMaximum[Log[obj],{a,0.1},{b,0.1}]
Plot[pi[x]/.FindMaximum[obj,{a,b}][[2]],{x,1,3},PlotRange->All]
Tags:

讀者回應 ( 0 意見 )

Post a Comment

Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.

如果這篇文章對你有幫助,那請留個訊息給我~