Test/Train split से मॉडल का मूल्यांकन करें
अब आप मॉडल mpg_model को test डेटा mpg_test पर जाँचेंगे.
सुविधा के लिए RMSE और R-squared निकालने के फ़ंक्शन rmse() और r_squared() दिए गए हैं:
rmse(predcol, ycol)
r_squared(predcol, ycol)
जहाँ:
- predcol: अनुमानित (predicted) मान
- ycol: वास्तविक outcome
आप predictions बनाम outcome का प्लॉट भी बनाएँगे.
आमतौर पर, training डेटा पर मॉडल का प्रदर्शन test डेटा की तुलना में बेहतर होता है (हालाँकि कभी-कभी test सेट पर "किस्मत" अच्छी हो जाती है). प्रदर्शन में थोड़ा अंतर ठीक है; यदि training पर प्रदर्शन बहुत बेहतर हो, तो समस्या है.
mpg_train और mpg_test डेटा फ्रेम, mpg_model मॉडल, तथा फ़ंक्शन rmse() और r_squared() पहले से लोड किए गए हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
R में Supervised Learning: Regression
अभ्यास निर्देश
mpg_trainडेटा परhwyसे city fuel efficiency की भविष्यवाणी करें. predictions को कॉलमpredमें असाइन करें.mpg_testडेटा परhwyसे city fuel efficiency की भविष्यवाणी करें. predictions को कॉलमpredमें असाइन करें.rmse()का उपयोग करके test और training, दोनों सेट्स के लिए RMSE निकालें. तुलना करें. क्या प्रदर्शन समान है?- यही काम
r_squared()के साथ करें. क्या प्रदर्शन समान है? ggplot2का उपयोग करकेtestडेटा पर predictions कोctyके विरुद्ध प्लॉट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Examine the objects that have been loaded
ls.str()
# predict cty from hwy for the training set
mpg_train$pred <- ___
# predict cty from hwy for the test set
mpg_test$pred <- ___
# Evaluate the rmse on both training and test data and print them
(rmse_train <- ___)
(rmse_test <- ___)
# Evaluate the r-squared on both training and test data.and print them
(rsq_train <- ___)
(rsq_test <- ___)
# Plot the predictions (on the x-axis) against the outcome (cty) on the test data
ggplot(___, aes(x = ___, y = ___)) +
geom_point() +
geom_abline()