ã¢ãã«ã®äºæ¸¬ç²¾åº¦ã測å®ããããã«ä½¿ç¨ãããæãä¸è¬çãªæ¸¬å®åºæºã®1ã¤ã¯MSEã§ãå¹³åäºä¹èª¤å·®ã®ç¥ã ã次ã®ããã«è¨ç®ãããï¼
- Σ - "åè¨ "ãæå³ããè¨å·
- n - ãµã³ãã«ãµã¤ãº
- - å®éã®ãã¼ã¿å¤
- - äºæ¸¬ãã¼ã¿å¤
MSEã®å¤ãå°ããã»ã©ãã¢ãã«ã¯ããæ£ç¢ºã«å¤ãäºæ¸¬ã§ããã
Rã§MSEãè¨ç®ããæ¹æ³ ãã¼ã¿ã®å½¢å¼ã«ãããããRã§å帰ã¢ãã«ã®MSEãè¨ç®ããã«ã¯ã2ã¤ã®ç°¡åãªæ¹æ³ãããã
æ¹æ³1: å帰ã¢ãã«ããMSEãè¨ç®ãã
ããã·ããªãªã§ã¯ãé©åãããå帰ã¢ãã«ããã£ã¦ãåç´ã«ãã®ã¢ãã«ã®MSEãè¨ç®ããããããããªãããã¨ãã°ã次ã®ãããªå帰ã¢ãã«ãããã¨ããï¼
#mtcarsãã¼ã¿ã»ããããã¼ããã data(mtcars) #å帰ã¢ãã«ã®ãã£ãã model <- lm(mpg~disp+hp, data=mtcars) #ã¢ãã«ã®è¦ç´ãå¾ã model_summ <-summary(model)
ãã®ã¢ãã«ã®MSEãè¨ç®ããã«ã¯ã以ä¸ã®å¼ã使ç¨ããï¼
#MSE ãè¨ç®ãã mean(model_summ$residuals^2)
[1] 8.85917
ããã«ãããMSEã¯8.85917ã§ãããã¨ããããã
æ¹æ³2ï¼äºæ¸¬å¤ã¨å®ç¸¾å¤ã®ãªã¹ãããMSEãè¨ç®ãã
å¥ã®ã·ããªãªã§ã¯ãåç´ã«äºæ¸¬å¤ã¨å®éå¤ã®ãªã¹ãããããããããªããä¾ãã°:
#å®ç¸¾å¤ã®åã¨äºæ¸¬å¤ã®åãæã¤ãã¼ã¿ãã¬ã¼ã ãä½æããã data <- data.frame(pred = predict(model), actual = mtcars$mpg) #æåã®6è¡ã®ãã¼ã¿ãè¦ã head(data)
çµæã
pred actual Mazda RX4 23.14809 21.0 Mazda RX4 Wag 23.14809 21.0 Datsun 710 25.14838 22.8 Hornet 4 Drive 20.17416 21.4 Hornet Sportabout 15.46423 18.7 Valiant 21.29978 18.1
ãã®å ´åã以ä¸ã®å¼ã使ã£ã¦MSEãè¨ç®ãããã¨ãã§ããï¼
#MSEãè¨ç®ãã mean((data$actual - data$pred)^2)
[1] 8.85917
ãã®çµæãMSEã¯8.85917ã¨ãªããåã®æ¹æ³ã§è¨ç®ããMSEã¨ä¸è´ããã