{"id":10774,"date":"2018-08-26T11:39:06","date_gmt":"2018-08-26T06:09:06","guid":{"rendered":"http:\/\/ucanalytics.com\/blogs\/?p=10774"},"modified":"2018-08-26T11:39:06","modified_gmt":"2018-08-26T06:09:06","slug":"machine-learning-cross-validation-and-hyper-parameter-tuning-part-3","status":"publish","type":"post","link":"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/","title":{"rendered":"Machine Learning : Cross Validation and Hyper-Parameter Tuning (Part 3)"},"content":{"rendered":"<hr \/>\n<p><a href=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning.jpg\"><img data-attachment-id=\"10775\" data-permalink=\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/cross-validation-and-hyperparameter-tuning\/\" data-orig-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning.jpg?fit=747%2C560&amp;ssl=1\" data-orig-size=\"747,560\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Cross Validation and Hyperparameter Tuning\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning.jpg?fit=300%2C225&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning.jpg?fit=640%2C480&amp;ssl=1\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-10775 aligncenter\" src=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning.jpg?resize=640%2C480\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning.jpg?w=747&amp;ssl=1 747w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning.jpg?resize=250%2C187&amp;ssl=1 250w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning.jpg?resize=300%2C225&amp;ssl=1 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>In the last part of this series on fundamental machine learning, you learned about\u00a0<strong><a href=\"http:\/\/ucanalytics.com\/blogs\/machine-learning-regularization-ridge-lasso-elastic-net-simplified-part-2\/\" target=\"_blank\" rel=\"noopener\">regularization and cross-validation<\/a><\/strong>. Here, you will gain a sound understanding of model hyper-parameter tuning to develop robust\u00a0models. The machines do learn but they still need a good human tutor. In the last part, you were also introduced to my paternal grandmother to learn about regularization. This time let me introduce my maternal grandfather with a story. He and his radio will eventually help us understand the principles behind hyper-parameter tuning.<\/p>\n<h2><span style=\"color: #3366ff;\">Color Pencils<\/span><\/h2>\n<p>My maternal\u00a0grandfather was in the police which is considered as one of the more corrupt institutions in India. My cousin often tells this story.\u00a0Our grandfather used to prepare certain monthly reports for his police station. This work required him to work with several color pencils. One day he was preparing these reports at home. My cousin saw him with all the pretty\u00a0and colorful pencils. He asked grandpa to give him a few pencils. To his surprise, grandpa walked him to the neighborhood market a couple of miles from their house. After buying new pencils, when they were returning\u00a0home my cousin asked, &#8220;Grandpa, w<em>e had so many similar pencils at home then why did you buy me new ones?<\/em>&#8220;. Grandpa answered, &#8220;<em>Those pencils at home belong to the Government of India.\u00a0<\/em><em>They are meant to be used for official work.<\/em>&#8221;<\/p>\n<p>Grandpa could have easily given a few of his official pencils to my cousin without anybody taking notice.\u00a0Somehow, whenever my cousin tells this story both of us feel proud. Both of us, after all these years, are so glad that grandpa chose to walk those extra miles to the market.<\/p>\n<p>I don&#8217;t have many memories of grandpa since he died when I was very young. I only remember an old radio that he used to own and I was completely fascinated with that radio.<\/p>\n<h2><span style=\"color: #3366ff;\">Radio and Model Hyper-Parameter Tuning<\/span><\/h2>\n<p><a href=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/05\/radio-dial.jpg\"><img data-attachment-id=\"11077\" data-permalink=\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/radio-dial\/\" data-orig-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/05\/radio-dial.jpg?fit=303%2C223&amp;ssl=1\" data-orig-size=\"303,223\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1526737811&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;1&quot;}\" data-image-title=\"radio dial\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/05\/radio-dial.jpg?fit=300%2C221&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/05\/radio-dial.jpg?fit=303%2C223&amp;ssl=1\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-11077 alignright\" src=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/05\/radio-dial.jpg?resize=303%2C223\" alt=\"\" width=\"303\" height=\"223\" srcset=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/05\/radio-dial.jpg?w=303&amp;ssl=1 303w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/05\/radio-dial.jpg?resize=250%2C184&amp;ssl=1 250w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/05\/radio-dial.jpg?resize=300%2C221&amp;ssl=1 300w\" sizes=\"(max-width: 303px) 100vw, 303px\" data-recalc-dims=\"1\" \/><\/a>It was a large wooden radio with a couple of round tuners. I used to love rotating those tuners to see the red dial move up and down. Other than giving kids something to play with, the purpose of those tuners\u00a0was to connect the radio to the station. When the radio was not tuned it used to make funny noises. Once tuned, it played the melodious music which we all used to listen to while having our dinner.<\/p>\n<p>The idea of machine learning hyper-parameter tuning is the same as using tuners for the radio. The effort is to identify the right setting for the model&#8217;s hyper-parameters to decipher music out of the seemingly noisy data. If you recall, we had two hyper-parameters, alpha (\u03b1) and lambda ( \u03bb), in <strong><a href=\"http:\/\/ucanalytics.com\/blogs\/machine-learning-regularization-ridge-lasso-elastic-net-simplified-part-2\/\" target=\"_blank\" rel=\"noopener\">the elastic net model<\/a><\/strong> we trained in the last part. The loss function was:<\/p>\n<pre><img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=LF%3A+%5Cfrac%7B1%7D%7BN%7D+%5Csum_%7Bi%3D1%7D%5E%7BN%7D+%28y_%7Bi%7D-%5Chat%7By%7D_%7Bi%7D%29%5E%7B2%7D%2B+%5Clambda%5Cleft+%5B+%281-%5Calpha%29%5Csum_%7Bj%3D1%7D%5E%7BM%7D%5Ctheta_%7Bj%7D%5E%7B2%7D%2B+%5Calpha%5Csum_%7Bj%3D1%7D%5E%7BM%7D%5Cleft+%7C+%5Ctheta_%7Bj%7D+%5Cright+%7C%5Cright+%5D&#038;bg=ffffff&#038;fg=000&#038;s=2&#038;c=20201002\" alt=\"LF: &#92;frac{1}{N} &#92;sum_{i=1}^{N} (y_{i}-&#92;hat{y}_{i})^{2}+ &#92;lambda&#92;left [ (1-&#92;alpha)&#92;sum_{j=1}^{M}&#92;theta_{j}^{2}+ &#92;alpha&#92;sum_{j=1}^{M}&#92;left | &#92;theta_{j} &#92;right |&#92;right ]\" class=\"latex\" \/><\/pre>\n<p>Think of these hyper-parameters (\u03b1 and \u03bb) as the round tuners for the radio. The values of these hyper-parameters are changed slowly to decipher the signals hidden in the data. We will come back to the loss functions later in the article. The loss functions are kind of like FM and AM channels for the radio station. But before that let&#8217;s go back to the model we are working on throughout this series of articles.<\/p>\n<h2><span style=\"color: #3366ff;\">Improving Models using Hyper-Parameter Tuning<\/span><\/h2>\n<p>Remember, we developed three different models in the last part using different variants of the loss function. The objective of all these models was to get the lowest value for the mean\u00a0square error (MSE). The first term in the loss function (LF) was the MSE i.e <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=MSE+%3D+%5Cfrac%7B1%7D%7BN%7D+%5Csum_%7Bi%3D1%7D%5E%7BN%7D+%28y_%7Bi%7D-%5Chat%7By%7D_%7Bi%7D%29%5E%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"MSE = &#92;frac{1}{N} &#92;sum_{i=1}^{N} (y_{i}-&#92;hat{y}_{i})^{2}\" class=\"latex\" \/>. The second regularization term imposes constraints to avoid overfitting\u00a0<img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Clambda%5Cleft+%5B+%281-%5Calpha%29%5Csum_%7Bj%3D1%7D%5E%7BM%7D%5Ctheta_%7Bj%7D%5E%7B2%7D%2B+%5Calpha%5Csum_%7Bj%3D1%7D%5E%7BM%7D%5Cleft+%7C+%5Ctheta_%7Bj%7D+%5Cright+%7C%5Cright+%5D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;lambda&#92;left [ (1-&#92;alpha)&#92;sum_{j=1}^{M}&#92;theta_{j}^{2}+ &#92;alpha&#92;sum_{j=1}^{M}&#92;left | &#92;theta_{j} &#92;right |&#92;right ]\" class=\"latex\" \/><\/p>\n<p>Let me quickly share the results of the final model we built at the end of <strong><a href=\"http:\/\/ucanalytics.com\/blogs\/machine-learning-regularization-ridge-lasso-elastic-net-simplified-part-2\/\" target=\"_blank\" rel=\"noopener\">the last article<\/a><\/strong>. Out of the three models, this model had the minimum MSE. Here, we kept the value of\u00a0\u03b1 constant at 1 &#8211; which is the Lasso regularization. We changed the value of \u03bb. This change in \u03bb was also hyper-parameter tuning.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-3-Regression-with-Regularization-Lasso-and-Cross-Validated-Lambda.jpg\"><img data-attachment-id=\"10925\" data-permalink=\"https:\/\/ucanalytics.com\/blogs\/machine-learning-regularization-ridge-lasso-elastic-net-simplified-part-2\/graph-3-regression-with-regularization-lasso-and-cross-validated-lambda\/\" data-orig-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-3-Regression-with-Regularization-Lasso-and-Cross-Validated-Lambda.jpg?fit=1293%2C742&amp;ssl=1\" data-orig-size=\"1293,742\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Graph 3 &#8211; Regression with Regularization (Lasso and Cross Validated Lambda)\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-3-Regression-with-Regularization-Lasso-and-Cross-Validated-Lambda.jpg?fit=300%2C172&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-3-Regression-with-Regularization-Lasso-and-Cross-Validated-Lambda.jpg?fit=640%2C368&amp;ssl=1\" decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-10925\" src=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-3-Regression-with-Regularization-Lasso-and-Cross-Validated-Lambda.jpg?resize=640%2C367\" alt=\"\" width=\"640\" height=\"367\" srcset=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-3-Regression-with-Regularization-Lasso-and-Cross-Validated-Lambda.jpg?w=1293&amp;ssl=1 1293w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-3-Regression-with-Regularization-Lasso-and-Cross-Validated-Lambda.jpg?resize=250%2C143&amp;ssl=1 250w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-3-Regression-with-Regularization-Lasso-and-Cross-Validated-Lambda.jpg?resize=300%2C172&amp;ssl=1 300w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-3-Regression-with-Regularization-Lasso-and-Cross-Validated-Lambda.jpg?resize=768%2C441&amp;ssl=1 768w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-3-Regression-with-Regularization-Lasso-and-Cross-Validated-Lambda.jpg?resize=1024%2C588&amp;ssl=1 1024w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>Now that we have got some understanding of hyper-parameter tuning, let&#8217;s change both the hyper-parameters in the objective function simultaneously. The objective is still to get the minimum value for the MSE.<\/p>\n<h2><span style=\"color: #3366ff;\">Hyper-Parameter Tunning &#8211; Changing both\u00a0\u03b1 and\u00a0\u03b8 (Caret Package)<\/span><\/h2>\n<p>Caret Package in R offers the functionality to change these hyper-parameters simultaneously. You could find the entire code used for this series of articles at this link\u00a0<a href=\"http:\/\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Regularization-Lasso-Ridge-Elastic-Net-and-Cross-Validation.txt\"><strong>Regularization &#8211; Lasso &amp; Ridge (Elastic Net) and Cross-Validation<\/strong>.<\/a>\u00a0Model-4 onwards in this code contains the analysis you will see in the subsequent segments.<\/p>\n<p>When we perform a detained hyper-parameter tuning we are supposed to fit the underlying sine curve in the data to a greater extent. Let&#8217;s see the results. Firstly, there is a significant improvement in reduction of MSE values for both the training and test samples from the best fit we observed last time. For instance, the MSE for the test set has gone down from 2754.84 to 14.74 with the new values of hyper-parameters. How does the fit look?<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-4-Regression-wth-Regularization-Cross-Validated-Lambda-and-Alpha-Caret.jpg\"><img data-attachment-id=\"10926\" data-permalink=\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/graph-4-regression-wth-regularization-cross-validated-lambda-and-alpha-caret\/\" data-orig-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-4-Regression-wth-Regularization-Cross-Validated-Lambda-and-Alpha-Caret.jpg?fit=1287%2C742&amp;ssl=1\" data-orig-size=\"1287,742\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Graph 4 &#8211; Regression wth Regularization (Cross Validated Lambda and Alpha &#8211; Caret)\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-4-Regression-wth-Regularization-Cross-Validated-Lambda-and-Alpha-Caret.jpg?fit=300%2C173&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-4-Regression-wth-Regularization-Cross-Validated-Lambda-and-Alpha-Caret.jpg?fit=640%2C369&amp;ssl=1\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-10926 aligncenter\" src=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-4-Regression-wth-Regularization-Cross-Validated-Lambda-and-Alpha-Caret.jpg?resize=640%2C369\" alt=\"\" width=\"640\" height=\"369\" srcset=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-4-Regression-wth-Regularization-Cross-Validated-Lambda-and-Alpha-Caret.jpg?w=1287&amp;ssl=1 1287w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-4-Regression-wth-Regularization-Cross-Validated-Lambda-and-Alpha-Caret.jpg?resize=250%2C144&amp;ssl=1 250w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-4-Regression-wth-Regularization-Cross-Validated-Lambda-and-Alpha-Caret.jpg?resize=300%2C173&amp;ssl=1 300w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-4-Regression-wth-Regularization-Cross-Validated-Lambda-and-Alpha-Caret.jpg?resize=768%2C443&amp;ssl=1 768w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-4-Regression-wth-Regularization-Cross-Validated-Lambda-and-Alpha-Caret.jpg?resize=1024%2C590&amp;ssl=1 1024w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>Ouch! That was completely unexpected. The ripples for the expected sine curve have completely disappeared. With the best-tuned hyper-parameters, we have got an almost flat line bent at the corners. What is going on here?\u00a0 To understand, let&#8217;s just fit a straight line to the training data points represented as the blue dots.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-6-Linear-Regression-wo-Regularization.jpg\"><img data-attachment-id=\"10928\" data-permalink=\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/graph-6-linear-regression-wo-regularization\/\" data-orig-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-6-Linear-Regression-wo-Regularization.jpg?fit=1267%2C742&amp;ssl=1\" data-orig-size=\"1267,742\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Graph 6 &#8211; Linear Regression wo Regularization\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-6-Linear-Regression-wo-Regularization.jpg?fit=300%2C176&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-6-Linear-Regression-wo-Regularization.jpg?fit=640%2C375&amp;ssl=1\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-10928 aligncenter\" src=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-6-Linear-Regression-wo-Regularization.jpg?resize=640%2C375\" alt=\"\" width=\"640\" height=\"375\" srcset=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-6-Linear-Regression-wo-Regularization.jpg?w=1267&amp;ssl=1 1267w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-6-Linear-Regression-wo-Regularization.jpg?resize=250%2C146&amp;ssl=1 250w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-6-Linear-Regression-wo-Regularization.jpg?resize=300%2C176&amp;ssl=1 300w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-6-Linear-Regression-wo-Regularization.jpg?resize=768%2C450&amp;ssl=1 768w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-6-Linear-Regression-wo-Regularization.jpg?resize=1024%2C600&amp;ssl=1 1024w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>The MESs for both training and test samples have further reduced with the straight line. Eyes trained in statistics would identify the problem in a straight line fit to this data set through the analysis of error terms. You will soon realize, in this case, the MSE is not the only objective function one must look at.<\/p>\n<h2><span style=\"color: #3366ff;\">Loss Functions &#8211; Not All Objectives are Same<\/span><\/h2>\n<p>A model can have other objectives than minimizing MSE. As mentioned earlier, these\u00a0objectives are kind of like the AM and FM channels on the radio. This means sometimes you tune your radio for an AM channel (MSE) and other time for an FM (other objectives). In this case, we want to reduce the MSE (i.e. the overall error in estimation of Y using polynomials of X). Moreover, we also want the curve to fit the underlying sine curve.<\/p>\n<p>As a solution, you could create your own customized loss function to achieve both these objectives. Then you can identify the optimal value for this new objective using the gradient descent approach. Another solution is to identify other metrics that could capture the degree of underlying fit to the data. Then, the two objectives values can be compared to identify the optimal values of hyper-parameters.<\/p>\n<p>It turned out that for this problem the second objective could be satisfied with the R-Squared value. Then using Caret you could get different values of MSE and R-Squared values for different values of hyper-parameters. The lowest value of MSE along with the highest value of R-Squared will result in the satisfaction of both the objectives.\u00a0 Let&#8217;s plot MSE and R-Squared to identify such condition. RMSE is the square root of MSE.<a href=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-5-Cross-Validation-Metrics.jpg\"><img data-attachment-id=\"10927\" data-permalink=\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/graph-5-cross-validation-metrics\/\" data-orig-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-5-Cross-Validation-Metrics.jpg?fit=1114%2C744&amp;ssl=1\" data-orig-size=\"1114,744\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Graph 5 &#8211; Cross Validation Metrics\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-5-Cross-Validation-Metrics.jpg?fit=300%2C200&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-5-Cross-Validation-Metrics.jpg?fit=640%2C428&amp;ssl=1\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-10927 aligncenter\" src=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-5-Cross-Validation-Metrics.jpg?resize=640%2C427\" alt=\"\" width=\"640\" height=\"427\" srcset=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-5-Cross-Validation-Metrics.jpg?w=1114&amp;ssl=1 1114w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-5-Cross-Validation-Metrics.jpg?resize=250%2C167&amp;ssl=1 250w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-5-Cross-Validation-Metrics.jpg?resize=300%2C200&amp;ssl=1 300w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-5-Cross-Validation-Metrics.jpg?resize=768%2C513&amp;ssl=1 768w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-5-Cross-Validation-Metrics.jpg?resize=1024%2C684&amp;ssl=1 1024w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>As you must have noticed, R-Squared value increases without much increase in the RMSE value as we move from left to right in the plot. If we settle for the minimum RMSE or MSE value, the R-Squared value is less than 0.3. However, if we let the RMSE increase by a few notches then the R-Squared rises to above 0.65. It turned out this happens for the following values of the hyper-parameters.<\/p>\n<pre><span style=\"font-family: 'andale mono', monospace; font-size: 14pt;\">\u03b1 = 1<\/span>\r\n\r\n<span style=\"font-family: 'andale mono', monospace; font-size: 14pt;\">\u03bb = 0.00295<\/span><\/pre>\n<h2><span style=\"color: #3366ff;\">Final Model with Optimal Hyper-Parameters<\/span><\/h2>\n<p>Let&#8217;s fit the data with these optimal values of hy<span style=\"font-family: georgia, palatino, serif;\">per-parameters (<span style=\"font-size: 14pt;\">\u03b1 and\u00a0\u03bb).\u00a0<\/span><\/span><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-7-Final-Regression-Model-wo-Regularization.jpg\"><img data-attachment-id=\"10929\" data-permalink=\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/graph-7-final-regression-model-wo-regularization\/\" data-orig-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-7-Final-Regression-Model-wo-Regularization.jpg?fit=1301%2C742&amp;ssl=1\" data-orig-size=\"1301,742\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Graph 7 &#8211; Final Regression Model wo Regularization\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-7-Final-Regression-Model-wo-Regularization.jpg?fit=300%2C171&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-7-Final-Regression-Model-wo-Regularization.jpg?fit=640%2C365&amp;ssl=1\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-10929 aligncenter\" src=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-7-Final-Regression-Model-wo-Regularization.jpg?resize=640%2C365\" alt=\"\" width=\"640\" height=\"365\" srcset=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-7-Final-Regression-Model-wo-Regularization.jpg?w=1301&amp;ssl=1 1301w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-7-Final-Regression-Model-wo-Regularization.jpg?resize=250%2C143&amp;ssl=1 250w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-7-Final-Regression-Model-wo-Regularization.jpg?resize=300%2C171&amp;ssl=1 300w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-7-Final-Regression-Model-wo-Regularization.jpg?resize=768%2C438&amp;ssl=1 768w, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/04\/Graph-7-Final-Regression-Model-wo-Regularization.jpg?resize=1024%2C584&amp;ssl=1 1024w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>The MSE for both training and test set is much lower for this model than the one we observed last time. MSE of the test data has gone down from 2754 to 169. This is still higher than the straight line MSE of 0.43. What you have gained by losing the MSE is a relatively better fit for the data.<\/p>\n<h4><span style=\"color: #3366ff;\">Sign-off Note<\/span><\/h4>\n<p>Tuning hyper-parameters requires a lot of thinking and requires a lot of supervision. The machines do learn but they still need a good human tutor.<\/p>\n<p>See you all soon with an exciting series on deep learning and deep neural networks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the last part of this series on fundamental machine learning, you learned about\u00a0regularization and cross-validation. Here, you will gain a sound understanding of model hyper-parameter tuning to develop robust\u00a0models. The machines do learn but they still need a good human tutor. In the last part, you were also introduced to my paternal grandmother to<\/p>\n<p><a class=\"excerpt-more blog-excerpt\" href=\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":10781,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[84,85],"tags":[],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v17.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Machine Learning : Cross Validation and Hyper-Parameter Tuning (Part 3) &ndash; YOU CANalytics |<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Machine Learning : Cross Validation and Hyper-Parameter Tuning (Part 3) &ndash; YOU CANalytics |\" \/>\n<meta property=\"og:description\" content=\"In the last part of this series on fundamental machine learning, you learned about\u00a0regularization and cross-validation. Here, you will gain a sound understanding of model hyper-parameter tuning to develop robust\u00a0models. The machines do learn but they still need a good human tutor. In the last part, you were also introduced to my paternal grandmother toRead More...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/\" \/>\n<meta property=\"og:site_name\" content=\"YOU CANalytics |\" \/>\n<meta property=\"article:author\" content=\"roopam\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-26T06:09:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning-Cover-3.jpg?fit=746%2C560&#038;ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"746\" \/>\n\t<meta property=\"og:image:height\" content=\"560\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Roopam Upadhyay\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/ucanalytics.com\/blogs\/#organization\",\"name\":\"YOU CANalytics\",\"url\":\"https:\/\/ucanalytics.com\/blogs\/\",\"sameAs\":[],\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/ucanalytics.com\/blogs\/#logo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2015\/11\/YOU-CANalytics-Logo.jpg?fit=607%2C120\",\"contentUrl\":\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2015\/11\/YOU-CANalytics-Logo.jpg?fit=607%2C120\",\"width\":607,\"height\":120,\"caption\":\"YOU CANalytics\"},\"image\":{\"@id\":\"https:\/\/ucanalytics.com\/blogs\/#logo\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ucanalytics.com\/blogs\/#website\",\"url\":\"https:\/\/ucanalytics.com\/blogs\/\",\"name\":\"YOU CANalytics |\",\"description\":\"Explore the Power of Data Science\",\"publisher\":{\"@id\":\"https:\/\/ucanalytics.com\/blogs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ucanalytics.com\/blogs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning-Cover-3.jpg?fit=746%2C560&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning-Cover-3.jpg?fit=746%2C560&ssl=1\",\"width\":746,\"height\":560},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#webpage\",\"url\":\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/\",\"name\":\"Machine Learning : Cross Validation and Hyper-Parameter Tuning (Part 3) &ndash; YOU CANalytics |\",\"isPartOf\":{\"@id\":\"https:\/\/ucanalytics.com\/blogs\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#primaryimage\"},\"datePublished\":\"2018-08-26T06:09:06+00:00\",\"dateModified\":\"2018-08-26T06:09:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ucanalytics.com\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Machine Learning : Cross Validation and Hyper-Parameter Tuning (Part 3)\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#webpage\"},\"author\":{\"@id\":\"https:\/\/ucanalytics.com\/blogs\/#\/schema\/person\/55961a1cea272ecdf290cb387be069b6\"},\"headline\":\"Machine Learning : Cross Validation and Hyper-Parameter Tuning (Part 3)\",\"datePublished\":\"2018-08-26T06:09:06+00:00\",\"dateModified\":\"2018-08-26T06:09:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#webpage\"},\"wordCount\":1380,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/ucanalytics.com\/blogs\/#organization\"},\"image\":{\"@id\":\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning-Cover-3.jpg?fit=746%2C560&ssl=1\",\"articleSection\":[\"Machine Learning and Artificial Intelligence\",\"Regularization and Cross Validation\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#respond\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/ucanalytics.com\/blogs\/#\/schema\/person\/55961a1cea272ecdf290cb387be069b6\",\"name\":\"Roopam Upadhyay\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/ucanalytics.com\/blogs\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/dd1aa0b0e813f7639800bcfad6a554f1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/dd1aa0b0e813f7639800bcfad6a554f1?s=96&d=mm&r=g\",\"caption\":\"Roopam Upadhyay\"},\"description\":\"This blog contains my personal views and thoughts on predictive Analytics and big data. - Roopam Upadhyay\",\"sameAs\":[\"roopam\"],\"url\":\"https:\/\/ucanalytics.com\/blogs\/author\/roopam\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Machine Learning : Cross Validation and Hyper-Parameter Tuning (Part 3) &ndash; YOU CANalytics |","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/","og_locale":"en_US","og_type":"article","og_title":"Machine Learning : Cross Validation and Hyper-Parameter Tuning (Part 3) &ndash; YOU CANalytics |","og_description":"In the last part of this series on fundamental machine learning, you learned about\u00a0regularization and cross-validation. Here, you will gain a sound understanding of model hyper-parameter tuning to develop robust\u00a0models. The machines do learn but they still need a good human tutor. In the last part, you were also introduced to my paternal grandmother toRead More...","og_url":"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/","og_site_name":"YOU CANalytics |","article_author":"roopam","article_published_time":"2018-08-26T06:09:06+00:00","og_image":[{"width":746,"height":560,"url":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning-Cover-3.jpg?fit=746%2C560&ssl=1","type":"image\/jpeg"}],"twitter_misc":{"Written by":"Roopam Upadhyay","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/ucanalytics.com\/blogs\/#organization","name":"YOU CANalytics","url":"https:\/\/ucanalytics.com\/blogs\/","sameAs":[],"logo":{"@type":"ImageObject","@id":"https:\/\/ucanalytics.com\/blogs\/#logo","inLanguage":"en-US","url":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2015\/11\/YOU-CANalytics-Logo.jpg?fit=607%2C120","contentUrl":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2015\/11\/YOU-CANalytics-Logo.jpg?fit=607%2C120","width":607,"height":120,"caption":"YOU CANalytics"},"image":{"@id":"https:\/\/ucanalytics.com\/blogs\/#logo"}},{"@type":"WebSite","@id":"https:\/\/ucanalytics.com\/blogs\/#website","url":"https:\/\/ucanalytics.com\/blogs\/","name":"YOU CANalytics |","description":"Explore the Power of Data Science","publisher":{"@id":"https:\/\/ucanalytics.com\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ucanalytics.com\/blogs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#primaryimage","inLanguage":"en-US","url":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning-Cover-3.jpg?fit=746%2C560&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning-Cover-3.jpg?fit=746%2C560&ssl=1","width":746,"height":560},{"@type":"WebPage","@id":"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#webpage","url":"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/","name":"Machine Learning : Cross Validation and Hyper-Parameter Tuning (Part 3) &ndash; YOU CANalytics |","isPartOf":{"@id":"https:\/\/ucanalytics.com\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#primaryimage"},"datePublished":"2018-08-26T06:09:06+00:00","dateModified":"2018-08-26T06:09:06+00:00","breadcrumb":{"@id":"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ucanalytics.com\/blogs\/"},{"@type":"ListItem","position":2,"name":"Machine Learning : Cross Validation and Hyper-Parameter Tuning (Part 3)"}]},{"@type":"Article","@id":"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#article","isPartOf":{"@id":"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#webpage"},"author":{"@id":"https:\/\/ucanalytics.com\/blogs\/#\/schema\/person\/55961a1cea272ecdf290cb387be069b6"},"headline":"Machine Learning : Cross Validation and Hyper-Parameter Tuning (Part 3)","datePublished":"2018-08-26T06:09:06+00:00","dateModified":"2018-08-26T06:09:06+00:00","mainEntityOfPage":{"@id":"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#webpage"},"wordCount":1380,"commentCount":2,"publisher":{"@id":"https:\/\/ucanalytics.com\/blogs\/#organization"},"image":{"@id":"https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning-Cover-3.jpg?fit=746%2C560&ssl=1","articleSection":["Machine Learning and Artificial Intelligence","Regularization and Cross Validation"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ucanalytics.com\/blogs\/machine-learning-cross-validation-and-hyper-parameter-tuning-part-3\/#respond"]}]},{"@type":"Person","@id":"https:\/\/ucanalytics.com\/blogs\/#\/schema\/person\/55961a1cea272ecdf290cb387be069b6","name":"Roopam Upadhyay","image":{"@type":"ImageObject","@id":"https:\/\/ucanalytics.com\/blogs\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/dd1aa0b0e813f7639800bcfad6a554f1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dd1aa0b0e813f7639800bcfad6a554f1?s=96&d=mm&r=g","caption":"Roopam Upadhyay"},"description":"This blog contains my personal views and thoughts on predictive Analytics and big data. - Roopam Upadhyay","sameAs":["roopam"],"url":"https:\/\/ucanalytics.com\/blogs\/author\/roopam\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2018\/01\/Cross-Validation-and-Hyperparameter-Tuning-Cover-3.jpg?fit=746%2C560&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3L0jT-2NM","jetpack-related-posts":[{"id":10717,"url":"https:\/\/ucanalytics.com\/blogs\/machine-learning-regularization-ridge-lasso-elastic-net-simplified-part-2\/","url_meta":{"origin":10774,"position":0},"title":"Machine Learning : Regularization &#8211; Ridge, Lasso, &#038; Elastic Net Simplified (Part 2)","author":"Roopam Upadhyay","date":false,"format":false,"excerpt":"In the previous article, we started with the theme that\u00a0overfitting is an inherent problem in machine learning associated with big data. Essentially, if you have many variables and their\u00a0polynomial\u00a0terms (X-variables) in a model you could fit any response data (y-variable) to perfection. This perfect fit for the observed data is\u2026","rel":"","context":"In &quot;Machine Learning and Artificial Intelligence&quot;","block_context":{"text":"Machine Learning and Artificial Intelligence","link":"https:\/\/ucanalytics.com\/blogs\/category\/machine-learning-and-artificial-intelligence\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2017\/12\/Regularization-Lasso-and-Ridge.jpg?fit=736%2C531&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2017\/12\/Regularization-Lasso-and-Ridge.jpg?fit=736%2C531&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2017\/12\/Regularization-Lasso-and-Ridge.jpg?fit=736%2C531&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2017\/12\/Regularization-Lasso-and-Ridge.jpg?fit=736%2C531&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":10702,"url":"https:\/\/ucanalytics.com\/blogs\/machine-learning-non-linear-regression-regularization-cross-validation-simplified-part-1\/","url_meta":{"origin":10774,"position":1},"title":"Machine Learning: Non-linear Regression, Regularization &#038; Cross Validation Simplified  (Part 1)","author":"Roopam Upadhyay","date":false,"format":false,"excerpt":"In this 3-part series of articles, you will gain an intuitive understanding of some fundamental concepts in machine learning such as: Building blocks of curves Non-linear regression Curve fitting and overfitting Regularization to prevent overfitting Hyper-parameters in machine learning Cross-validation to fine-tune models You will also get hands-on practice to\u2026","rel":"","context":"In &quot;Machine Learning and Artificial Intelligence&quot;","block_context":{"text":"Machine Learning and Artificial Intelligence","link":"https:\/\/ucanalytics.com\/blogs\/category\/machine-learning-and-artificial-intelligence\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2017\/12\/Machine-Learning-Regularization-Simplified-Front-Page.jpg?fit=928%2C522&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2017\/12\/Machine-Learning-Regularization-Simplified-Front-Page.jpg?fit=928%2C522&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2017\/12\/Machine-Learning-Regularization-Simplified-Front-Page.jpg?fit=928%2C522&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2017\/12\/Machine-Learning-Regularization-Simplified-Front-Page.jpg?fit=928%2C522&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":7923,"url":"https:\/\/ucanalytics.com\/blogs\/intuitive-machine-learning-gradient-descent-simplified\/","url_meta":{"origin":10774,"position":2},"title":"Intuitive Machine Learning : Gradient Descent Simplified","author":"Roopam Upadhyay","date":false,"format":false,"excerpt":"How do machines learn? They learn the same way as humans. Humans learn from experience and so do machines. For machines, the experience is in the form of data. Machines use powerful algorithms to make sense of the data. They identify underlining patterns within the data to learn things about\u2026","rel":"","context":"In &quot;Gradient Descent&quot;","block_context":{"text":"Gradient Descent","link":"https:\/\/ucanalytics.com\/blogs\/category\/gradient-descent\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2016\/03\/Rplot01.png?fit=1000%2C600&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2016\/03\/Rplot01.png?fit=1000%2C600&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2016\/03\/Rplot01.png?fit=1000%2C600&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2016\/03\/Rplot01.png?fit=1000%2C600&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":2374,"url":"https:\/\/ucanalytics.com\/blogs\/learn-r-12-books-and-online-resources\/","url_meta":{"origin":10774,"position":3},"title":"Learn R : 12 Free Books and Online Resources","author":"Roopam Upadhyay","date":false,"format":false,"excerpt":"Please read the disclaimer about the Free PDF Books in this article at the bottom R, an open-source statistical and data mining programming language, is slowly but surely catching up in its race with commercial software like SAS & SPSS. I believe R will eventually replace SAS as the language\u2026","rel":"","context":"In &quot;Analytics Book Club&quot;","block_context":{"text":"Analytics Book Club","link":"https:\/\/ucanalytics.com\/blogs\/category\/analytics-book-club\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2013\/07\/5-Swordsmith1.jpg?fit=768%2C1024&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2013\/07\/5-Swordsmith1.jpg?fit=768%2C1024&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2013\/07\/5-Swordsmith1.jpg?fit=768%2C1024&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2013\/07\/5-Swordsmith1.jpg?fit=768%2C1024&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":8388,"url":"https:\/\/ucanalytics.com\/blogs\/regression-analysis-pricing-case-study-example-part-1\/","url_meta":{"origin":10774,"position":4},"title":"Regression Analysis &#8211; Pricing Case Study Example (Part 1)","author":"Roopam Upadhyay","date":false,"format":false,"excerpt":"How to figure out if you are paying the right price for the property you are about to purchase? Welcome to a new data science case study example on YOU CANalytics to identify the right housing price. Pricing is a highly important and\u00a0specialized function for any business. A right price\u2026","rel":"","context":"In &quot;Pricing Case Study Example&quot;","block_context":{"text":"Pricing Case Study Example","link":"https:\/\/ucanalytics.com\/blogs\/category\/pricing-case-study-example\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2016\/07\/Connect-the-Dots.jpg?fit=397%2C603&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":11924,"url":"https:\/\/ucanalytics.com\/blogs\/artificial-intelligence-and-machine-learning-for-business-a-video-talk\/","url_meta":{"origin":10774,"position":5},"title":"Artificial Intelligence and Machine Learning for Business &#8211; A Video Talk","author":"Roopam Upadhyay","date":false,"format":false,"excerpt":"How will artificial intelligence and machine learning transform businesses? In this introductory part of the talk, learn how artificial intelligence will play a pivotal role to resolve conflicts within businesses.","rel":"","context":"In &quot;Video Discussion&quot;","block_context":{"text":"Video Discussion","link":"https:\/\/ucanalytics.com\/blogs\/category\/video-discussion\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2020\/05\/Front-1.jpg?fit=663%2C373&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2020\/05\/Front-1.jpg?fit=663%2C373&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/ucanalytics.com\/blogs\/wp-content\/uploads\/2020\/05\/Front-1.jpg?fit=663%2C373&ssl=1&resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/ucanalytics.com\/blogs\/wp-json\/wp\/v2\/posts\/10774"}],"collection":[{"href":"https:\/\/ucanalytics.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ucanalytics.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ucanalytics.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ucanalytics.com\/blogs\/wp-json\/wp\/v2\/comments?post=10774"}],"version-history":[{"count":0,"href":"https:\/\/ucanalytics.com\/blogs\/wp-json\/wp\/v2\/posts\/10774\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ucanalytics.com\/blogs\/wp-json\/wp\/v2\/media\/10781"}],"wp:attachment":[{"href":"https:\/\/ucanalytics.com\/blogs\/wp-json\/wp\/v2\/media?parent=10774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ucanalytics.com\/blogs\/wp-json\/wp\/v2\/categories?post=10774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ucanalytics.com\/blogs\/wp-json\/wp\/v2\/tags?post=10774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}