Skip to content

Latest commit

 

History

History
165 lines (93 loc) · 9.37 KB

learn-generalized-linear-models-glm-r.md

File metadata and controls

165 lines (93 loc) · 9.37 KB

菴ソ逕ィR蟄ヲ荵�蟷ソ荵臥コソ諤ァ讓。蝙具シ�LM��

蜴滓枚�喙https://www.kdnuggets.com/2017/10/learn-generalized-linear-models-glm-r.html/2](https://www.kdnuggets.com/2017/10/learn-generalized-linear-models-glm-r.html/2)

隗」驥雁ッケ謨ー蜿俶困

蟇ケ萓晁オ匁焚謐ョ蜥檎峡遶区焚謐ョ霑幄。悟ッケ謨ー蜿俶困譏ッ荳�遘榊、�炊髱樒コソ諤ァ蜈ウ邉サ逧�ョ�蜊墓婿豕輔�りソ咏ァ榊序謐「譛牙勧莠惹スソ逕ィ郤ソ諤ァ讓。蝙句�譫宣撼郤ソ諤ァ蜈ウ邉サ縲よ�莉ャ蟾イ扈剰ョィ隶コ莠�ッケ謨ー郤ソ諤ァ蝗槫ス偵�りソ俶怏荳、荳ェ蜿倅ス� 窶� a) 郤ソ諤ァ窶灘ッケ謨ー蝗槫ス� 窶鍋峡遶句序驥剰ソ幄。悟ッケ謨ー蜿俶困�恵) 蟇ケ謨ー窶灘ッケ謨ー蝗槫ス� 窶謎セ晁オ門序驥丞柱迢ャ遶句序驥城�霑幄。悟序謐「縲ゆク玖。ィ譏セ遉コ莠�ッ丈クェ讓。蝙狗噪譁ケ遞句柱隗」驥翫��


謌台サャ逧�燕3荳ェ隸セ遞区耳闕�

1. Google 鄂醍サ懷ョ牙�隸∽ケヲ - 蠢ォ騾溯ソ帛�鄂醍サ懷ョ牙�閨御ク夂函豸ッ

2. Google 謨ー謐ョ蛻�梵荳謎ク夊ッ∽ケヲ - 謠仙合菴�逧�焚謐ョ蛻�梵閭ス蜉�

3. Google IT 謾ッ謖∽ク謎ク夊ッ∽ケヲ - 謾ッ謖∽ス�逧�サ�サ�噪IT髴�豎�


陦ィ2 莠碁。ケ騾サ霎大屓蠖堤噪譬キ譛ャ謨ー謐ョ

Table

莠碁。ケ騾サ霎大屓蠖�

蠖謎セ晁オ門序驥乗弍邀サ蛻ォ蝙倶ク泌叙蛟シ荳コ0蜥�1譌カ�御スソ逕ィ莠碁。ケ騾サ霎大屓蠖偵�ゆク守ョ�蜊慕コソ諤ァ蝗槫ス剃クュ萓晁オ門序驥冗噪譚。莉カ蛻�ク�クコ豁」諤∝�蟶�ク榊酔�碁�サ霎大屓蠖剃クュ逧�擅莉カ蛻�ク�クコ莨ッ蜉ェ蛻ゥ蛻�ク��ょ惠莨ッ蜉ェ蛻ゥ蛻�ク�クュ�悟序驥丞宵閭ス蜿紋ク、荳ェ蛟シ 窶� 0蜥�1�悟�譛我ク�螳夂噪讎ら紫縲�

隶ゥ謌台サャ騾夊ソ�ク�荳ェ萓句ュ先擂逅�ァ」縲ょ∞隶セ蝨ィ雜ウ逅�クュ�悟ー�ス夂帥霓ャ謐「荳コ霑帷帥逧��蜉帛叙蜀ウ莠主ー�葎閠�噪扈�ケ�蟆乗慮謨ー縲よ�莉ャ蜿ッ莉・逕ィ1陦ィ遉コ謌仙粥鄂夂帥�檎畑0陦ィ遉コ譛ェ謌仙粥鄂夂帥縲よ焚謐ョ螯ゆク具シ�

陦ィ2 莠碁。ケ騾サ霎大屓蠖堤噪譬キ譛ャ謨ー謐ョ

Table

莠碁。ケ騾サ霎大屓蠖呈ィ。蝙句ー��ケ謐ョ扈�ケ�蟆乗慮謨ー霎灘�謌仙粥鄂夂帥逧�ヲら紫縲る�サ霎大屓蠖剃スソ逕ィ騾サ霎大�謨ー譚・蟒コ讓。蜈ウ邉サ縲る�サ霎大�謨ー蜈∬ョク蟆��邉サ蟒コ讓。荳コ讎ら紫�悟屏荳コ螳�噪蛟シ蝨ィ0蜥�1荵矩龍縲ょ�陦ィ遉コ螯ゆク具シ�

Eq 4 [4]

ホイ1 逧�ュ」蛟シ�郁エ溷�シ�芽。ィ遉コ蠖� X 蠅槫刈譌カ Y=1 逧�ヲら紫蠅槫刈�亥㍼蟆托シ峨�る�サ霎大屓蠖呈弍蟷ソ豕帑スソ逕ィ逧�アサ蛻ォ鬚�オ区ィ。蝙倶ケ倶ク�縲ょ、夐。ケ蠑城�サ霎大屓蠖貞ー�コ悟�邀サ讓。蝙区黄螻募芦螟�炊豸牙所螟壻クェ邀サ蛻ォ逧�琉鬚倥�ゆセ句ヲゑシ御ク�荳ェ莠コ譏ッ蜷ヲ莨壼�謐「莨俶Β蛻ク A縲∽シ俶Β蛻ク B 謌紋シ俶Β蛻ク C縲ら鴫蝨ィ謌台サャ蟆�惠 R 荳ュ螳樒鴫騾サ霎大屓蠖呈ィ。蝙九�よ�キ譛ャ謨ー謐ョ蛹�峡荳、荳ェ蜿倬㍼窶披�皮せ逅��蜉�/螟ア雍・陦ィ遉コ荳コ 1/0 蜥檎サ�ケ�蟆乗慮縲りッキ轤ケ蜃サ霑咎㈹荳玖スス縲3 莉」遐∝ヲゆク具シ�

## Prepare scatter plot

#Read data from .csv file
data1 = read.csv("Penalty.csv", header = T)
head(data1)

#Scatter Plot
plot(data1, main = "Scatter Plot")

蝗セ 4 邀サ蛻ォ謨ー謐ョ逧�淵轤ケ蝗セ

Figure

謌台サャ蜿ッ莉・隗ょッ溷芦�悟屏蜿倬㍼莉��蜿紋ク、荳ェ蛟シ窶披��1蜥�0縲ょス鍋サ�ケ�譌カ髣エ蠅槫刈譌カ�檎自螳カ逧�譜邇�ケ滓署鬮倥�ら鴫蝨ィ謌台サャ蟆�スソ逕ィ騾サ霎大屓蠖貞㊥螟�ク�荳ェ讓。蝙区擂鬚�オ句渕莠守サ�ケ�譌カ髣エ逧��蜉滓�螟ア雍・逧�ヲら紫縲3 莉」遐∝ヲゆク具シ�

## Fitting Logistic regression model
fit = glm(Outcome ~ Practice, family = binomial(link = "logit"), data = data1)

#Plot probabilities
plot(data1, main ="Scatter Plot")
curve(predict(fit,data.frame(Practice = x), type = "resp"), add = TRUE)points(data1$Practice,fitted(fit),pch=20)

蝗セ 5 譏セ遉コ莠�サ朱�サ霎大屓蠖剃クュ闔キ蠕礼噪讎ら紫蛟シ縲よ�莉ャ蜿ッ莉・逵句芦讓。蝙玖。ィ邇ー濶ッ螂ス縲る囂逹�扈�ケ�譌カ髣エ逧�「槫刈�梧�蜉溽噪讎ら紫荵溷「槫刈縲りッ・讓。蝙句惠譁ケ遞� [5] 荳ュ陦ィ遉コ縲ょ庄莉・騾夊ソ�薯蜈・扈�ケ�蟆乗慮謨ー譚・闔キ蠕玲ヲら紫蛟シ縲�

Eq 5 [5]

蝗セ 5 菴ソ逕ィ騾サ霎大屓蠖堤噪讎ら紫蝗セ

Figure

扈楢ョコ

蝨ィ霑咏ッ�枚遶�荳ュ�梧�莉ャ蟄ヲ荵�莠�ケソ荵臥コソ諤ァ讓。蝙具シ�LM�峨�らョ�蜊慕コソ諤ァ蝗槫ス呈弍 GLM 逧�怙蝓コ譛ャ蠖「蠑上��LM 逧�ォ倡コァ蠖「蠑乗怏蜉ゥ莠惹サ・邂�蜊慕噪譁ケ蠑丞、�炊髱樊ュ」諤∝�蟶�柱髱樒コソ諤ァ蜈ウ邉サ縲よ�莉ャ驥咲せ莉狗サ堺コ�ッケ謨ー郤ソ諤ァ蝗槫ス貞柱莠悟�騾サ霎大屓蠖偵�ょス灘屏蜿倬㍼荳手�蜿倬㍼荵矩龍逧��邉サ譏ッ髱樒コソ諤ァ譌カ�悟ッケ謨ー郤ソ諤ァ蝗槫ス帝撼蟶ク譛臥畑縲ょス灘屏蜿倬㍼驕オ蠕ェ蟇ケ謨ー豁」諤∝�蟶��豕頑收蛻�ク�慮�悟ョ�ケ滓署萓帑コ�ソォ騾溽噪隗」蜀ウ譁ケ譯医��

豁、螟厄シ梧�莉ャ隶ィ隶コ莠�コ悟�騾サ霎大屓蠖堤噪蝓コ譛ャ讎ょソオ縲ょス灘屏蜿倬㍼驕オ蠕ェ莨ッ蜉ェ蛻ゥ蛻�ク�シ悟叉蜿ェ閭ス蜿� 0 蜥� 1 逧��シ譌カ�御コ悟�騾サ霎大屓蠖帝撼蟶ク譛臥畑縲よ�莉ャ霑俶署萓帑コ�推遘榊ッケ謨ー蜿俶困逧�婿遞句柱隗」驥奇シ瑚ソ吩コ帛序謐「荳主屓蠖呈ィ。蝙倶ク�襍キ菴ソ逕ィ縲�

髯、莠�炊隶コ隗」驥奇シ梧�莉ャ霑伜�莠ォ莠� R 莉」遐�シ御サ・萓ソ菴�蜿ッ莉・蝨ィ R 荳ュ螳樒鴫隸・讓。蝙九�ゆクコ莠�峩螂ス蝨ー逅�ァ」�梧�莉ャ螻慕、コ莠�サ捺棡蜥御サ」遐√��

謌台サャ蟶梧悍菴�隗牙セ苓ソ咏ッ�枚遶�譛臥畑縲�

**譛ャ譁�クュ菴ソ逕ィ逧�ョ梧紛莉」遐∬ッキ轤ケ蜃サ霑咎㈹**縲�

荳ェ莠コ邂�莉�: Chaitanya Sagar 譏ッ Perceptive Analytics 逧��蟋倶ココ蜈シ鬥門クュ謇ァ陦悟ョ倥�1erceptive Analytics 陲ォ縲晦nalytics India Magazine縲玖ッ��我クコ蛟シ蠕怜�豕ィ逧�香螟ァ蛻�梵蜈ャ蜿ク荵倶ク�縲りッ・蜈ャ蜿ク閾エ蜉帑コ惹クコ逕オ蟄仙膚蜉。縲�峺蜚ョ蜥悟宛闕ッ蜈ャ蜿ク謠蝉セ帛クょ惻蛻�梵譛榊苅縲�

逶ク蜈ウ蜀�ョケ:

逶ク蜈ウ荳サ鬚�

## Fitting Log-linear model

# Transform the dependent variable
data$LCola = log(data$Cola, base = exp(1))

#Scatter Plot
plot(LCola ~ Temperature, data = data , main = "Scatter Plot")

#Fit the best line in log-linear model
model1 = lm(LCola ~ Temperature, data)
abline(model1)

#Calculate RMSE
PredCola1 = predict(model1, data)
RMSE = rmse(PredCola1, data$LCola)

蝗セ 3 蟇ケ謨ー郤ソ諤ァ蝗槫ス堤サ吝�逧�怙菴ウ諡溷粋郤ソ

蝗セ 3

蝗セ 3 譏セ遉コ莠�スソ逕ィ蟇ケ謨ー郤ソ諤ァ蝗槫ス堤噪譛�菴ウ諡溷粋郤ソ縲よ�莉ャ蜿ッ莉・蟆��隗�クコ荳�荳ェ荳、豁・霑�ィ具シ悟叉蟇ケ謨ー謐ョ霑幄。悟序謐「�亥ッケ荳、霎ケ蜿門ッケ謨ー�会シ檎┯蜷主ッケ蜿俶困蜷守噪謨ー謐ョ霑幄。檎ョ�蜊慕コソ諤ァ蝗槫ス偵�りョ。邂怜�逧�ィ。蝙句ヲゆク具シ�

譁ケ遞� 3 [3]

蜿ッ荵宣楳蜚ョ驥丞庄莉・騾夊ソ�ー�クゥ蠎ヲ蛟シ莉」蜈・譁ケ遞擬3]譚・鬚�オ九�よ�莉ャ隗ょッ溷芦荳守ョ�蜊慕コソ諤ァ蝗槫ス堤嶌豈費シ梧供蜷域譜譫懈怏莠�セ亥、ァ謾ケ蝟��ょ序謐「蜷守噪讓。蝙狗噪RMSE莉�クコ0.24縲りッキ豕ィ諢擾シ梧律蠢礼コソ諤ァ蝗槫ス剃ケ溯ァ」蜀ウ莠�庄荵宣楳蜚ョ驥丞�邇ー闕定ーャ雍溷�シ逧�琉鬚倥�ょッケ莠惹ササ菴墓クゥ蠎ヲ蛟シ�梧�莉ャ驛ス荳堺シ壼セ怜芦雍溽噪蜿ッ荵宣楳蜚ョ驥上�らョ�蜊慕噪蟇ケ謨ー蜿俶困蟶ョ蜉ゥ謌台サャ螟�炊莠�ソ咏ァ崎穀隹ャ諠��縲ょ惠荳倶ク�驛ィ蛻�シ梧�莉ャ蟆�ョィ隶コ蜈カ莉門惠蜷�ァ肴ュ蜀オ荳矩撼蟶ク譛臥畑逧�ッケ謨ー蜿俶困縲�


謌台サャ逧�ク牙、ァ隸セ遞区耳闕�

1. 隹キ豁檎ス醍サ懷ョ牙�隸∽ケヲ - 蠢ォ騾溯ソ帛�鄂醍サ懷ョ牙�閨御ク夂函豸ッ縲�

2. 隹キ豁梧焚謐ョ蛻�梵荳謎ク夊ッ∽ケヲ - 謠仙合菴�逧�焚謐ョ蛻�梵閭ス蜉帙��

3. 隹キ豁栗T謾ッ謖∽ク謎ク夊ッ∽ケヲ - 謾ッ謖∽ス�逧�サ�サ⑩T髴�豎ゅ��


譖エ螟夂嶌蜈ウ隸晞「�