You are on page 1of 2

:overfitting-‫אמידת ביצועי המודל ו‬

.‫ למודל‬summery ‫ מהפלט שמקבלים כשעושים‬adjusted −r 2 ‫ וגם‬r 2 ‫**ניתן לקבל‬


.overfitting ‫ מעידה על‬adjusted r-‫**ירידה ב‬
:)‫הדרך הקצרה (באמצעות פלטים‬
)‫(*כאן משתמשים ישירות במודל המלא‬
#calculate r squared
summary(model)$r.squared
#calculate adjusted r squared
summary(model)$adj.r.squared
‫הדרך הארוכה‬:
#Adjusted R^2 formuala ( ‫ אבל אם כן אז להציב את‬,‫בפועל לא נצטרך להשתמש‬
‫)הערכים בהתאם‬:
R<-
K<-
N<-
Adjusted<-(R^2)-((K*(1-(R^2)))/(N-K-1))
Adjusted

:‫תיקוף צולב‬
#cross validation:
#we will take a sample from the data randomly:
dgima <- sample.int(n = nrow(data), size = floor(.8*nrow(data)), replace = F)
#0.8 is for the size of the train set (‫ מהנתונים‬80% ‫)בעצם לקחנו‬

#creating train and test sets:


train <- data[dgima, ]
test <- data[-dgima, ]

#building the train model:


train_model<-lm(y~.,data=train)
summary(train_model)
#testing it on the test set:
pred<-predict(object=train_model,test)

#getting the R squared from the test model


(cor(pred,test$y,method="pearson"))^2
.test-‫ של ה‬r^2-‫זה נותן לנו את ה‬
.overfitting ‫) ניתן להסיק שיש‬train( ‫אם הוא נמוך יותר מזה של קבוצת האימון‬

#K-fold Cross Validation:


install.packages("caret")
library(caret)
#Define training control:
train.control <- trainControl(method = "cv", number = 10)
#‫ קבוצות‬10-‫))במקרה הזה החלוקה היא ל‬

#Train the model:


model <- train(satov~., data = fulldata, method = "lm",
trControl = train.control)
#Summarize the results
print(model)
:‫זה נותן לנו את הפלט הבא‬

R squared-‫ אותו אנחנו משווים ל‬,‫ החדש שלנו‬R squared-‫שבו אנחנו רואים את ה‬
.‫הראשוני שקיבלנו במודל המלא‬

You might also like