"R MSE 계산"의 두 판 사이의 차이

(새 문서: ==개요== ;R MSE 계산 <syntaxhighlight lang='r' run> options(echo=T) df = data.frame( radio_ads = c(3,4,9,4,5,5,2,6,5,3), tv_ads = c(1,3,4,1,4,1,4,2,4,2), retention = c(5...)
 
2번째 줄: 2번째 줄:
;R MSE 계산
;R MSE 계산


==예시: 단순회귀분석==
<syntaxhighlight lang='r' run>
options(echo=T)
df = data.frame(
  x = c(1  , 2  , 3  , 4  , 5  , 6  , 7  , 8  , 9  , 10  ),
  y = c(2.5, 4.0, 3.5, 3.0, 4.5, 4.0, 5.5, 7.0, 6.5,  7.0)
)
model = lm(y ~ x, data=df)
summary( model )
pred = predict(model, data=df)
# MSE
mean((df$y - pred)^2) # 0.4
</syntaxhighlight>
==예시: 다중회귀분석==
<syntaxhighlight lang='r' run>
<syntaxhighlight lang='r' run>
options(echo=T)
options(echo=T)
15번째 줄: 30번째 줄:
mean((df$retention - pred)^2)
mean((df$retention - pred)^2)
</syntaxhighlight>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 10월 27일 (화) 02:02 판

1 개요

R MSE 계산

2 예시: 단순회귀분석

options(echo=T)
df = data.frame(
  x = c(1  , 2  , 3  , 4  , 5  , 6  , 7  , 8  , 9  , 10  ),
  y = c(2.5, 4.0, 3.5, 3.0, 4.5, 4.0, 5.5, 7.0, 6.5,  7.0)
)
model = lm(y ~ x, data=df)
summary( model )
pred = predict(model, data=df)
# MSE
mean((df$y - pred)^2) # 0.4

3 예시: 다중회귀분석

options(echo=T)
df = data.frame(
  radio_ads = c(3,4,9,4,5,5,2,6,5,3),
  tv_ads    = c(1,3,4,1,4,1,4,2,4,2),
  retention = c(5,1,6,2,8,3,4,9,7,4)
)
model = lm(retention ~ radio_ads + tv_ads, data=df)
summary( model )
pred = predict(model, data=df)
# MSE
mean((df$retention - pred)^2)

4 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}