Whitening and standardization

From snake wiki
Revision as of 12:50, 13 September 2021 by Snake (talk | contribs)
Jump to navigation Jump to search

<!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8" />

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="pingback" href="https://machinelearningmastery.com/xmlrpc.php" /> <meta name='robots' content='index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' />


<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=yes" name="viewport"/>

<title>How to use Data Scaling Improve Deep Learning Model Stability and Performance</title><link rel="stylesheet" href="https://machinelearningmastery.com/wp-content/cache/min/1/7ab4e5ffb1c7994e88de46542752e00b.css" media="all" data-minify="1" /> <link rel="canonical" href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/" /> <meta property="og:locale" content="en_US" /> <meta property="og:type" content="article" /> <meta property="og:title" content="How to use Data Scaling Improve Deep Learning Model Stability and Performance" /> <meta property="og:description" content="Deep learning neural networks learn how to map inputs to outputs from examples in a training dataset. The weights of […]" /> <meta property="og:url" content="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/" /> <meta property="og:site_name" content="Machine Learning Mastery" /> <meta property="article:publisher" content="https://www.facebook.com/MachineLearningMastery/" /> <meta property="article:author" content="https://www.facebook.com/MachineLearningMastery/" /> <meta property="article:published_time" content="2019-02-03T18:00:34+00:00" /> <meta property="article:modified_time" content="2020-08-25T00:18:53+00:00" /> <meta property="og:image" content="https://machinelearningmastery.com/wp-content/uploads/2018/11/Box-and-Whisker-Plots-of-Mean-Squared-Error-With-Unscaled-Normalized-and-Standardized-Input-Variables-for-the-Regression-Problem.png" /> <meta property="og:image:width" content="1280" /> <meta property="og:image:height" content="960" /> <meta name="twitter:label1" content="Written by" /> <meta name="twitter:data1" content="Jason Brownlee" /> <meta name="twitter:label2" content="Est. reading time" /> <meta name="twitter:data2" content="26 minutes" /> <script type="application/ld+json" class="yoast-schema-graph">{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://machinelearningmastery.com/#organization","name":"Machine Learning Mastery","url":"https://machinelearningmastery.com/","sameAs":["https://www.facebook.com/MachineLearningMastery/","https://www.linkedin.com/company/machine-learning-mastery","https://twitter.com/TeachTheMachine"],"logo":{"@type":"ImageObject","@id":"https://machinelearningmastery.com/#logo","inLanguage":"en-US","url":"https://machinelearningmastery.com/wp-content/uploads/2016/09/cropped-icon.png","contentUrl":"https://machinelearningmastery.com/wp-content/uploads/2016/09/cropped-icon.png","width":512,"height":512,"caption":"Machine Learning Mastery"},"image":{"@id":"https://machinelearningmastery.com/#logo"}},{"@type":"WebSite","@id":"https://machinelearningmastery.com/#website","url":"https://machinelearningmastery.com/","name":"Machine Learning Mastery","description":"Making developers awesome at machine learning","publisher":{"@id":"https://machinelearningmastery.com/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://machinelearningmastery.com/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#primaryimage","inLanguage":"en-US","url":"https://machinelearningmastery.com/wp-content/uploads/2018/11/Box-and-Whisker-Plots-of-Mean-Squared-Error-With-Unscaled-Normalized-and-Standardized-Input-Variables-for-the-Regression-Problem.png","contentUrl":"https://machinelearningmastery.com/wp-content/uploads/2018/11/Box-and-Whisker-Plots-of-Mean-Squared-Error-With-Unscaled-Normalized-and-Standardized-Input-Variables-for-the-Regression-Problem.png","width":1280,"height":960,"caption":"Box and Whisker Plots of Mean Squared Error With Unscaled, Normalized and Standardized Input Variables for the Regression Problem"},{"@type":"WebPage","@id":"https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#webpage","url":"https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/","name":"How to use Data Scaling Improve Deep Learning Model Stability and Performance","isPartOf":{"@id":"https://machinelearningmastery.com/#website"},"primaryImageOfPage":{"@id":"https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#primaryimage"},"datePublished":"2019-02-03T18:00:34+00:00","dateModified":"2020-08-25T00:18:53+00:00","breadcrumb":{"@id":"https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/"]}]},{"@type":"BreadcrumbList","@id":"https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://machinelearningmastery.com/"},{"@type":"ListItem","position":2,"name":"Blog","item":"https://machinelearningmastery.com/blog/"},{"@type":"ListItem","position":3,"name":"How to use Data Scaling Improve Deep Learning Model Stability and Performance"}]},{"@type":"Article","@id":"https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#article","isPartOf":{"@id":"https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#webpage"},"author":{"@id":"https://machinelearningmastery.com/#/schema/person/e2d0ff4828d406a3b47e5a3c9a0591e8"},"headline":"How to use Data Scaling Improve Deep Learning Model Stability and Performance","datePublished":"2019-02-03T18:00:34+00:00","dateModified":"2020-08-25T00:18:53+00:00","mainEntityOfPage":{"@id":"https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#webpage"},"wordCount":3566,"commentCount":125,"publisher":{"@id":"https://machinelearningmastery.com/#organization"},"image":{"@id":"https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#primaryimage"},"thumbnailUrl":"https://machinelearningmastery.com/wp-content/uploads/2018/11/Box-and-Whisker-Plots-of-Mean-Squared-Error-With-Unscaled-Normalized-and-Standardized-Input-Variables-for-the-Regression-Problem.png","articleSection":["Deep Learning Performance"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#respond"]}]},{"@type":"Person","@id":"https://machinelearningmastery.com/#/schema/person/e2d0ff4828d406a3b47e5a3c9a0591e8","name":"Jason Brownlee","image":{"@type":"ImageObject","@id":"https://machinelearningmastery.com/#personlogo","inLanguage":"en-US","url":"https://secure.gravatar.com/avatar/a0942b56b07831ac15d4a168a750e34a?s=96&d=mm&r=g","contentUrl":"https://secure.gravatar.com/avatar/a0942b56b07831ac15d4a168a750e34a?s=96&d=mm&r=g","caption":"Jason Brownlee"},"description":"Jason Brownlee, PhD is a machine learning specialist who teaches developers how to get results with modern machine learning methods via hands-on tutorials.","sameAs":["http://MachineLearningMastery.com","https://www.facebook.com/MachineLearningMastery/","https://www.linkedin.com/company/machine-learning-mastery","https://twitter.com/teachthemachine"]}]}</script>


<link rel='dns-prefetch' href='//cdn.jsdelivr.net' /> <link rel='dns-prefetch' href='//ads.adthrive.com' /> <link rel='dns-prefetch' href='//www.google-analytics.com' /> <link rel='dns-prefetch' href='//loadeu.exelator.com' /> <link rel='dns-prefetch' href='//sync.crwdcntrl.net' /> <link rel='dns-prefetch' href='//gdpr-wrapper.privacymanager.io' /> <link rel='dns-prefetch' href='//securepubads.g.doubleclick.net' /> <link rel='dns-prefetch' href='//gdpr.privacymanager.io' /> <link rel='dns-prefetch' href='//sb.scorecardresearch.com' /> <link rel='dns-prefetch' href='//confiant-integrations.global.ssl.fastly.net' />

<link rel="alternate" type="application/rss+xml" title="Machine Learning Mastery » Feed" href="https://feeds.feedburner.com/MachineLearningMastery" /> <link rel="alternate" type="application/rss+xml" title="Machine Learning Mastery » Comments Feed" href="https://machinelearningmastery.com/comments/feed/" /> <link rel="alternate" type="application/rss+xml" title="Machine Learning Mastery » How to use Data Scaling Improve Deep Learning Model Stability and Performance Comments Feed" href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/feed/" /> <style type="text/css"> img.wp-smiley, img.emoji { display: inline !important; border: none !important; box-shadow: none !important; height: 1em !important; width: 1em !important; margin: 0 .07em !important; vertical-align: -0.1em !important; background: none !important; padding: 0 !important; } </style>






<script type="f3886dae12b0536ad361ea93-text/javascript" src='https://machinelearningmastery.com/wp-includes/js/jquery/jquery.min.js?ver=3.6.0' id='jquery-core-js' defer></script>


<script type="f3886dae12b0536ad361ea93-text/javascript" id='ssb-front-js-js-extra'> /* <![CDATA[ */ var SSB = {"ajax_url":"https:\/\/machinelearningmastery.com\/wp-admin\/admin-ajax.php","fb_share_nonce":"0f0d514a34"}; /* ]]> */ </script>



<link rel="https://api.w.org/" href="https://machinelearningmastery.com/wp-json/" /><link rel="alternate" type="application/json" href="https://machinelearningmastery.com/wp-json/wp/v2/posts/6939" /><link rel="EditURI" type="application/rsd+xml" title="RSD" href="https://machinelearningmastery.com/xmlrpc.php?rsd" /> <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="https://machinelearningmastery.com/wp-includes/wlwmanifest.xml" /> <link rel='shortlink' href='https://machinelearningmastery.com/?p=6939' />

   <style type="text/css">
     .mpcs-classroom .nav-back i,
     .mpcs-classroom .navbar-section a.btn,
     .mpcs-classroom .navbar-section a,
     .mpcs-classroom .navbar-section button {
       color: rgba(255, 255, 255) !important;
     }
     .mpcs-classroom .navbar-section .dropdown .menu a {
       color: rgba(44, 54, 55) !important;
     }
     .mpcs-classroom .mpcs-progress-ring {
       background-color: rgba(29, 166, 154) !important;
     }
     .mpcs-classroom .mpcs-course-filter .dropdown .btn span,
     .mpcs-classroom .mpcs-course-filter .dropdown .btn i,
     .mpcs-classroom .mpcs-course-filter .input-group .input-group-btn,
     .mpcs-classroom .mpcs-course-filter .input-group .mpcs-search,
     .mpcs-classroom .mpcs-course-filter .input-group input[type=text],
     .mpcs-classroom .mpcs-course-filter .dropdown a,
     .mpcs-classroom .pagination,
     .mpcs-classroom .pagination i,
     .mpcs-classroom .pagination a {
       color: rgba(44, 54, 55) !important;
       border-color: rgba(44, 54, 55) !important;
     }
     /* body.mpcs-classroom a{
       color: rgba();
     } */
     #mpcs-navbar,
     #mpcs-navbar button#previous_lesson_link,
     #mpcs-navbar button#previous_lesson_link:hover {
       background: rgba(44, 54, 55);
     }
     .course-progress .user-progress,
     .btn-green,
     #mpcs-navbar button:not(#previous_lesson_link){
       background: rgba(29, 166, 154, 0.9);
     }
     .btn-green:hover,
     #mpcs-navbar button:not(#previous_lesson_link):focus,
     #mpcs-navbar button:not(#previous_lesson_link):hover{
       background: rgba(29, 166, 154);
     }
     .btn-green{border: rgba(29, 166, 154)}
     .course-progress .progress-text,
     .mpcs-lesson i.mpcs-circle-regular {
       color: rgba(29, 166, 154)
     }
     #mpcs-main #bookmark, .mpcs-lesson.current{background: rgba(29, 166, 154, 0.3)}
     .mpcs-instructor .tile-subtitle{
       color: rgba(29, 166, 154, 1)
     }
   </style>
    <style media="screen">

.simplesocialbuttons.simplesocialbuttons_inline .ssb-fb-like { margin: ; } /*inline margin*/




.simplesocialbuttons.simplesocialbuttons_inline.simplesocial-simple-icons button{ margin: ; }

/*margin-digbar*/





</style>

<meta property="og:title" content="How to use Data Scaling Improve Deep Learning Model Stability and Performance - Machine Learning Mastery" /> <meta property="og:description" content="Deep learning neural networks learn how to map inputs to outputs from examples in a training dataset.

The weights of the model are initialized to small random values and updated via an optimization algorithm in response to estimates of error on the training dataset.

Given the use of small weights in the model and the use of error between predictions and expected" /> <meta property="og:url" content="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/" /> <meta property="og:site_name" content="Machine Learning Mastery" /> <meta property="og:image" content="https://machinelearningmastery.com/wp-content/uploads/2018/11/Box-and-Whisker-Plots-of-Mean-Squared-Error-With-Unscaled-Normalized-and-Standardized-Input-Variables-for-the-Regression-Problem.png" /> <meta name="twitter:card" content="summary_large_image" /> <meta name="twitter:description" content="Deep learning neural networks learn how to map inputs to outputs from examples in a training dataset.

The weights of the model are initialized to small random values and updated via an optimization algorithm in response to estimates of error on the training dataset.

Given the use of small weights in the model and the use of error between predictions and expected" /> <meta name="twitter:title" content="How to use Data Scaling Improve Deep Learning Model Stability and Performance - Machine Learning Mastery" /> <meta property="twitter:image" content="https://machinelearningmastery.com/wp-content/uploads/2018/11/Box-and-Whisker-Plots-of-Mean-Squared-Error-With-Unscaled-Normalized-and-Standardized-Input-Variables-for-the-Regression-Problem.png" />

<style id="wplmi-inline-css" type="text/css"> span.wplmi-user-avatar { width: 16px;display: inline-block !important;flex-shrink: 0; } img.wplmi-elementor-avatar { border-radius: 100%;margin-right: 3px; }

</style>

<link rel="preload" as="font" href="https://machinelearningmastery.com/wp-content/themes/canvas-new/includes/fonts/fontawesome-webfont.woff2?v=4.5.0" crossorigin> <style type="text/css">

  1. logo .site-title, #logo .site-description { display:none; }

body {background-repeat:no-repeat;background-position:top left;background-attachment:scroll;border-top:0px solid #000000;}

  1. header {background-repeat:no-repeat;background-position:left top;margin-top:0px;margin-bottom:0px;padding-top:10px;padding-bottom:10px;border:0px solid ;}
  2. logo .site-title a {font:bold 40px/1em "Helvetica Neue", Helvetica, sans-serif;color:#222222;}
  3. logo .site-description {font:normal 13px/1em "Helvetica Neue", Helvetica, sans-serif;color:#999999;}

body, p { font:normal 14px/1.5em "Helvetica Neue", Helvetica, sans-serif;color:#555555; } h1 { font:bold 28px/1.2em "Helvetica Neue", Helvetica, sans-serif;color:#222222; }h2 { font:bold 24px/1.2em "Helvetica Neue", Helvetica, sans-serif;color:#222222; }h3 { font:bold 20px/1.2em "Helvetica Neue", Helvetica, sans-serif;color:#222222; }h4 { font:bold 16px/1.2em "Helvetica Neue", Helvetica, sans-serif;color:#222222; }h5 { font:bold 14px/1.2em "Helvetica Neue", Helvetica, sans-serif;color:#222222; }h6 { font:bold 12px/1.2em "Helvetica Neue", Helvetica, sans-serif;color:#222222; } .page-title, .post .title, .page .title {font:bold 28px/1.1em "Helvetica Neue", Helvetica, sans-serif;color:#222222;} .post .title a:link, .post .title a:visited, .page .title a:link, .page .title a:visited {color:#222222} .post-meta { font:normal 12px/1.5em "Helvetica Neue", Helvetica, sans-serif;color:#999999; } .entry, .entry p{ font:normal 15px/1.5em "Helvetica Neue", Helvetica, sans-serif;color:#555555; } .post-more {font:normal 13px/1.5em "Helvetica Neue", Helvetica, sans-serif;color:;border-top:0px solid #e6e6e6;border-bottom:0px solid #e6e6e6;}

  1. post-author, #connect {border-top:1px solid #e6e6e6;border-bottom:1px solid #e6e6e6;border-left:1px solid #e6e6e6;border-right:1px solid #e6e6e6;border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px;background-color:#fafafa}

.nav-entries a, .woo-pagination { font:normal 13px/1em "Helvetica Neue", Helvetica, sans-serif;color:#888; } .woo-pagination a, .woo-pagination a:hover {color:#888!important} .widget h3 {font:bold 14px/1.2em "Helvetica Neue", Helvetica, sans-serif;color:#555555;border-bottom:1px solid #e6e6e6;} .widget_recent_comments li, #twitter li { border-color: #e6e6e6;} .widget p, .widget .textwidget { font:normal 13px/1.5em "Helvetica Neue", Helvetica, sans-serif;color:#555555; } .widget {font:normal 13px/1.5em "Helvetica Neue", Helvetica, sans-serif;color:#555555;border-radius:0px;-moz-border-radius:0px;-webkit-border-radius:0px;}

  1. tabs .inside li a, .widget_woodojo_tabs .tabbable .tab-pane li a { font:bold 12px/1.5em "Helvetica Neue", Helvetica, sans-serif;color:#555555; }
  2. tabs .inside li span.meta, .widget_woodojo_tabs .tabbable .tab-pane li span.meta { font:300 11px/1.5em "Helvetica Neue", Helvetica, sans-serif;color:#999999; }
  3. tabs ul.wooTabs li a, .widget_woodojo_tabs .tabbable .nav-tabs li a { font:300 11px/2em "Helvetica Neue", Helvetica, sans-serif;color:#999999; }

@media only screen and (min-width:768px) { ul.nav li a, #navigation ul.rss a, #navigation ul.cart a.cart-contents, #navigation .cart-contents #navigation ul.rss, #navigation ul.nav-search, #navigation ul.nav-search a { font:bold 15px/1.2em "Helvetica Neue", Helvetica, sans-serif;color:#ffffff; } #navigation ul.rss li a:before, #navigation ul.nav-search a.search-contents:before { color:#ffffff;}

  1. navigation ul.nav > li a:hover, #navigation ul.nav > li:hover a, #navigation ul.nav li ul li a, #navigation ul.cart > li:hover > a, #navigation ul.cart > li > ul > div, #navigation ul.cart > li > ul > div p, #navigation ul.cart > li > ul span, #navigation ul.cart .cart_list a, #navigation ul.nav li.current_page_item a, #navigation ul.nav li.current_page_parent a, #navigation ul.nav li.current-menu-ancestor a, #navigation ul.nav li.current-cat a, #navigation ul.nav li.current-menu-item a { color:#eeeeee!important; }
  2. navigation ul.nav > li a:hover, #navigation ul.nav > li:hover, #navigation ul.nav li ul, #navigation ul.cart li:hover a.cart-contents, #navigation ul.nav-search li:hover a.search-contents, #navigation ul.nav-search a.search-contents + ul, #navigation ul.cart a.cart-contents + ul, #navigation ul.nav li.current_page_item a, #navigation ul.nav li.current_page_parent a, #navigation ul.nav li.current-menu-ancestor a, #navigation ul.nav li.current-cat a, #navigation ul.nav li.current-menu-item a{background-color:#84abc7!important}
  3. navigation ul.nav li ul, #navigation ul.cart > li > ul > div { border: 0px solid #dbdbdb; }
  4. navigation ul.nav > li:hover > ul { left: 0; }
  5. navigation ul.nav > li { border-right: 0px solid #dbdbdb; }#navigation ul.nav > li:hover > ul { left: 0; }
  6. navigation { box-shadow: none; -moz-box-shadow: none; -webkit-box-shadow: none; }#navigation ul li:first-child, #navigation ul li:first-child a { border-radius:0px 0 0 0px; -moz-border-radius:0px 0 0 0px; -webkit-border-radius:0px 0 0 0px; }
  7. navigation {background:#84abc7;border-top:0px solid #dbdbdb;border-bottom:0px solid #dbdbdb;border-left:0px solid #dbdbdb;border-right:0px solid #dbdbdb;border-radius:0px; -moz-border-radius:0px; -webkit-border-radius:0px;}
  8. top ul.nav li a { font:normal 12px/1.6em "Helvetica Neue", Helvetica, sans-serif;color:#ddd; }

}

  1. footer, #footer p { font:normal 13px/1.4em "Helvetica Neue", Helvetica, sans-serif;color:#999999; }
  2. footer {border-top:1px solid #dbdbdb;border-bottom:0px solid ;border-left:0px solid ;border-right:0px solid ;border-radius:0px; -moz-border-radius:0px; -webkit-border-radius:0px;}

.magazine #loopedSlider .content h2.title a { font:bold 24px/1em Arial, sans-serif;color:#ffffff; } .wooslider-theme-magazine .slide-title a { font:bold 24px/1em Arial, sans-serif;color:#ffffff; } .magazine #loopedSlider .content .excerpt p { font:300 13px/1.5em Arial, sans-serif;color:#cccccc; } .wooslider-theme-magazine .slide-content p, .wooslider-theme-magazine .slide-excerpt p { font:300 13px/1.5em Arial, sans-serif;color:#cccccc; } .magazine .block .post .title a {font:bold 18px/1.2em Helvetica Neue, Helvetica, sans-serif;color:#222222; }

  1. loopedSlider.business-slider .content h2 { font:bold 24px/1em Arial, sans-serif;color:#ffffff; }
  2. loopedSlider.business-slider .content h2.title a { font:bold 24px/1em Arial, sans-serif;color:#ffffff; }

.wooslider-theme-business .has-featured-image .slide-title { font:bold 24px/1em Arial, sans-serif;color:#ffffff; } .wooslider-theme-business .has-featured-image .slide-title a { font:bold 24px/1em Arial, sans-serif;color:#ffffff; }

  1. wrapper #loopedSlider.business-slider .content p { font:300 13px/1.5em Arial, sans-serif;color:#cccccc; }

.wooslider-theme-business .has-featured-image .slide-content p { font:300 13px/1.5em Arial, sans-serif;color:#cccccc; } .wooslider-theme-business .has-featured-image .slide-excerpt p { font:300 13px/1.5em Arial, sans-serif;color:#cccccc; } .archive_header { font:bold 18px/1em Arial, sans-serif;color:#222222; } .archive_header {border-bottom:1px solid #e6e6e6;} .archive_header .catrss { display:none; } </style>

<link rel="shortcut icon" href="https://machinelearningmastery.com/wp-content/uploads/2019/09/icon-16x16.png"/> <style type="text/css">

  1. logo img {
  max-width: 100%;
  height: auto;

} </style>




<meta name="generator" content="Canvas 5.9.21" /> <meta name="generator" content="WooFramework 6.2.9" />

<link rel="icon" href="https://machinelearningmastery.com/wp-content/uploads/2016/09/cropped-icon-32x32.png" sizes="32x32" /> <link rel="icon" href="https://machinelearningmastery.com/wp-content/uploads/2016/09/cropped-icon-192x192.png" sizes="192x192" /> <link rel="apple-touch-icon" href="https://machinelearningmastery.com/wp-content/uploads/2016/09/cropped-icon-180x180.png" /> <meta name="msapplication-TileImage" content="https://machinelearningmastery.com/wp-content/uploads/2016/09/cropped-icon-270x270.png" /> <style type="text/css" id="wp-custom-css"> .display-posts-listing.image-left .listing-item { overflow: hidden; margin-bottom: 30px; width: 100%; }

.display-posts-listing.image-left .image { float: left; margin: 0 10px 0 0; }

.display-posts-listing.image-left .attachment-thumbnail { height: auto; width: auto; max-width: 50px; max-height: 50px; border-radius: 50%; }

.display-posts-listing.image-left .title { display: block; }

.display-posts-listing.image-left .excerpt-dash { display: none; }

.display-posts-listing.image-left { margin: 0 0 40px 0; } </style> <noscript><style id="rocket-lazyload-nojs-css">.rll-youtube-player, [data-lazy-src]{display:none !important;}</style></noscript> <script type="f3886dae12b0536ad361ea93-text/javascript"> !function(f,b,e,v,n,t,s) {if(f.fbq)return;n=f.fbq=function(){n.callMethod? n.callMethod.apply(n,arguments):n.queue.push(arguments)}; if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0'; n.queue=[];t=b.createElement(e);t.async=!0; t.src=v;s=b.getElementsByTagName(e)[0]; s.parentNode.insertBefore(t,s)}(window, document,'script', 'https://machinelearningmastery.com/wp-content/cache/busting/facebook-tracking/fbpix-events-en_US-2.9.5.js'); fbq('init', '834324500844861'); fbq('track', 'PageView'); </script> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=834324500844861&ev=PageView&noscript=1" /></noscript> </head> <body class="post-template-default single single-post postid-6939 single-format-standard chrome alt-style-default two-col-left width-960 two-col-left-960">

 	 <a href="/super-bundle/?utm_campaign=Machine%20Learning%20Mastery%20Super%20Bundle&utm_source=website&utm_medium=banner">Click to get the 20-book Super Bundle! (Save $250)</a>

<header id="header" class="col-full">

<a href="https://machinelearningmastery.lpages.co/bdl-mini-course/">Click to Take the FREE Deep Learning Performane Crash-Course</a>

</header> <nav id="navigation" class="col-full" role="navigation">


<section class="menus">

<a href="https://machinelearningmastery.com" class="nav-home">Home</a>

Main Menu

</section>

<a href="#top" class="nav-close">Return to Content</a>

</nav>

                       <section id="main">                       

<article class="post-6939 post type-post status-publish format-standard has-post-thumbnail hentry category-better-deep-learning"> <header>

How to use Data Scaling Improve Deep Learning Model Stability and Performance

</header>

<section class="entry">

<button class="ssb_tweet-icon" data-href="https://twitter.com/share?text=How+to+use+Data+Scaling+Improve+Deep+Learning+Model+Stability+and+Performance&url=https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/" rel="nofollow" onclick="if (!window.__cfRLUnblockHandlers) return false; javascript:window.open(this.dataset.href, , 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;" data-cf-modified-f3886dae12b0536ad361ea93-=""> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 72"><path fill="none" d="M0 0h72v72H0z"/><path class="icon" fill="#fff" d="M68.812 15.14c-2.348 1.04-4.87 1.744-7.52 2.06 2.704-1.62 4.78-4.186 5.757-7.243-2.53 1.5-5.33 2.592-8.314 3.176C56.35 10.59 52.948 9 49.182 9c-7.23 0-13.092 5.86-13.092 13.093 0 1.026.118 2.02.338 2.98C25.543 24.527 15.9 19.318 9.44 11.396c-1.125 1.936-1.77 4.184-1.77 6.58 0 4.543 2.312 8.552 5.824 10.9-2.146-.07-4.165-.658-5.93-1.64-.002.056-.002.11-.002.163 0 6.345 4.513 11.638 10.504 12.84-1.1.298-2.256.457-3.45.457-.845 0-1.666-.078-2.464-.23 1.667 5.2 6.5 8.985 12.23 9.09-4.482 3.51-10.13 5.605-16.26 5.605-1.055 0-2.096-.06-3.122-.184 5.794 3.717 12.676 5.882 20.067 5.882 24.083 0 37.25-19.95 37.25-37.25 0-.565-.013-1.133-.038-1.693 2.558-1.847 4.778-4.15 6.532-6.774z"/></svg>Tweet </button> <button class="ssb_fbshare-icon" target="_blank" data-href="https://www.facebook.com/sharer/sharer.php?u=https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/" onclick="if (!window.__cfRLUnblockHandlers) return false; javascript:window.open(this.dataset.href, , 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;" data-cf-modified-f3886dae12b0536ad361ea93-=""> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" class="_1pbq" color="#ffffff"><path fill="#ffffff" fill-rule="evenodd" class="icon" d="M8 14H3.667C2.733 13.9 2 13.167 2 12.233V3.667A1.65 1.65 0 0 1 3.667 2h8.666A1.65 1.65 0 0 1 14 3.667v8.566c0 .934-.733 1.667-1.667 1.767H10v-3.967h1.3l.7-2.066h-2V6.933c0-.466.167-.9.867-.9H12v-1.8c.033 0-.933-.266-1.533-.266-1.267 0-2.434.7-2.467 2.133v1.867H6v2.066h2V14z"></path></svg> Share </button> <button class="ssb_linkedin-icon" data-href="https://www.linkedin.com/cws/share?url=https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/" onclick="if (!window.__cfRLUnblockHandlers) return false; javascript:window.open(this.dataset.href, , 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;" data-cf-modified-f3886dae12b0536ad361ea93-=""> <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="15px" height="14.1px" viewBox="-301.4 387.5 15 14.1" enable-background="new -301.4 387.5 15 14.1" xml:space="preserve"> <g id="XMLID_398_"> <path id="XMLID_399_" fill="#FFFFFF" d="M-296.2,401.6c0-3.2,0-6.3,0-9.5h0.1c1,0,2,0,2.9,0c0.1,0,0.1,0,0.1,0.1c0,0.4,0,0.8,0,1.2 c0.1-0.1,0.2-0.3,0.3-0.4c0.5-0.7,1.2-1,2.1-1.1c0.8-0.1,1.5,0,2.2,0.3c0.7,0.4,1.2,0.8,1.5,1.4c0.4,0.8,0.6,1.7,0.6,2.5 c0,1.8,0,3.6,0,5.4v0.1c-1.1,0-2.1,0-3.2,0c0-0.1,0-0.1,0-0.2c0-1.6,0-3.2,0-4.8c0-0.4,0-0.8-0.2-1.2c-0.2-0.7-0.8-1-1.6-1 c-0.8,0.1-1.3,0.5-1.6,1.2c-0.1,0.2-0.1,0.5-0.1,0.8c0,1.7,0,3.4,0,5.1c0,0.2,0,0.2-0.2,0.2c-1,0-1.9,0-2.9,0 C-296.1,401.6-296.2,401.6-296.2,401.6z"/> <path id="XMLID_400_" fill="#FFFFFF" d="M-298,401.6L-298,401.6c-1.1,0-2.1,0-3,0c-0.1,0-0.1,0-0.1-0.1c0-3.1,0-6.1,0-9.2 c0-0.1,0-0.1,0.1-0.1c1,0,2,0,2.9,0h0.1C-298,395.3-298,398.5-298,401.6z"/> <path id="XMLID_401_" fill="#FFFFFF" d="M-299.6,390.9c-0.7-0.1-1.2-0.3-1.6-0.8c-0.5-0.8-0.2-2.1,1-2.4c0.6-0.2,1.2-0.1,1.8,0.2 c0.5,0.4,0.7,0.9,0.6,1.5c-0.1,0.7-0.5,1.1-1.1,1.3C-299.1,390.8-299.4,390.8-299.6,390.9L-299.6,390.9z"/> </g> </svg> Share </button>

Last Updated on August 25, 2020

Deep learning neural networks learn how to map inputs to outputs from examples in a training dataset.

The weights of the model are initialized to small random values and updated via an optimization algorithm in response to estimates of error on the training dataset.

Given the use of small weights in the model and the use of error between predictions and expected values, the scale of inputs and outputs used to train the model are an important factor. Unscaled input variables can result in a slow or unstable learning process, whereas unscaled target variables on regression problems can result in exploding gradients causing the learning process to fail.

Data preparation involves using techniques such as the normalization and standardization to rescale input and output variables prior to training a neural network model.

In this tutorial, you will discover how to improve neural network stability and modeling performance by scaling data.

After completing this tutorial, you will know:

  • Data scaling is a recommended pre-processing step when working with deep learning neural networks.
  • Data scaling can be achieved by normalizing or standardizing real-valued input and output variables.
  • How to apply standardization and normalization to improve the performance of a Multilayer Perceptron model on a regression predictive modeling problem.

Kick-start your project with my new book <a href="https://machinelearningmastery.com/better-deep-learning/">Better Deep Learning</a>, including step-by-step tutorials and the Python source code files for all examples.

Let’s get started.

<img aria-describedby="caption-attachment-6944" loading="lazy" class="size-full wp-image-6944" src="https://machinelearningmastery.com/wp-content/uploads/2019/02/How-to-Improve-Neural-Network-Stability-and-Modeling-Performance-With-Data-Scaling.jpg" alt="How to Improve Neural Network Stability and Modeling Performance With Data Scaling" width="640" height="249" srcset="https://machinelearningmastery.com/wp-content/uploads/2019/02/How-to-Improve-Neural-Network-Stability-and-Modeling-Performance-With-Data-Scaling.jpg 640w, https://machinelearningmastery.com/wp-content/uploads/2019/02/How-to-Improve-Neural-Network-Stability-and-Modeling-Performance-With-Data-Scaling-300x117.jpg 300w" sizes="(max-width: 640px) 100vw, 640px" />

How to Improve Neural Network Stability and Modeling Performance With Data Scaling
Photo by <a href="https://www.flickr.com/photos/javiersanp/14202569306/">Javier Sanchez Portero</a>, some rights reserved.

Tutorial Overview

This tutorial is divided into six parts; they are:

  1. The Scale of Your Data Matters
  2. Data Scaling Methods
  3. Regression Predictive Modeling Problem
  4. Multilayer Perceptron With Unscaled Data
  5. Multilayer Perceptron With Scaled Output Variables
  6. Multilayer Perceptron With Scaled Input Variables

The Scale of Your Data Matters

Deep learning neural network models learn a mapping from input variables to an output variable.

As such, the scale and distribution of the data drawn from the domain may be different for each variable.

Input variables may have different units (e.g. feet, kilometers, and hours) that, in turn, may mean the variables have different scales.

Differences in the scales across input variables may increase the difficulty of the problem being modeled. An example of this is that large input values (e.g. a spread of hundreds or thousands of units) can result in a model that learns large weight values. A model with large weight values is often unstable, meaning that it may suffer from poor performance during learning and sensitivity to input values resulting in higher generalization error.

One of the most common forms of pre-processing consists of a simple linear rescaling of the input variables.

— Page 298, <a href="https://amzn.to/2S8qdwt">Neural Networks for Pattern Recognition</a>, 1995.

A target variable with a large spread of values, in turn, may result in large error gradient values causing weight values to change dramatically, making the learning process unstable.

Scaling input and output variables is a critical step in using neural network models.

In practice it is nearly always advantageous to apply pre-processing transformations to the input data before it is presented to a network. Similarly, the outputs of the network are often post-processed to give the required output values.

— Page 296, <a href="https://amzn.to/2S8qdwt">Neural Networks for Pattern Recognition</a>, 1995.

Scaling Input Variables

The input variables are those that the network takes on the input or visible layer in order to make a prediction.

A good rule of thumb is that input variables should be small values, probably in the range of 0-1 or standardized with a zero mean and a standard deviation of one.

Whether input variables require scaling depends on the specifics of your problem and of each variable.

You may have a sequence of quantities as inputs, such as prices or temperatures.

If the distribution of the quantity is normal, then it should be standardized, otherwise the data should be normalized. This applies if the range of quantity values is large (10s, 100s, etc.) or small (0.01, 0.0001).

If the quantity values are small (near 0-1) and the distribution is limited (e.g. standard deviation near 1) then perhaps you can get away with no scaling of the data.

Problems can be complex and it may not be clear how to best scale input data.

If in doubt, normalize the input sequence. If you have the resources, explore modeling with the raw data, standardized data, and normalized data and see if there is a beneficial difference in the performance of the resulting model.

If the input variables are combined linearly, as in an MLP [Multilayer Perceptron], then it is rarely strictly necessary to standardize the inputs, at least in theory. […] However, there are a variety of practical reasons why standardizing the inputs can make training faster and reduce the chances of getting stuck in local optima.

— <a href="ftp://ftp.sas.com/pub/neural/FAQ2.html#A_std">Should I normalize/standardize/rescale the data? Neural Nets FAQ</a>

Scaling Output Variables

The output variable is the variable predicted by the network.

You must ensure that the scale of your output variable matches the scale of the activation function (transfer function) on the output layer of your network.

If your output activation function has a range of [0,1], then obviously you must ensure that the target values lie within that range. But it is generally better to choose an output activation function suited to the distribution of the targets than to force your data to conform to the output activation function.

— <a href="ftp://ftp.sas.com/pub/neural/FAQ2.html#A_std">Should I normalize/standardize/rescale the data? Neural Nets FAQ</a>

If your problem is a regression problem, then the output will be a real value.

This is best modeled with a linear activation function. If the distribution of the value is normal, then you can standardize the output variable. Otherwise, the output variable can be normalized.

Want Better Results with Deep Learning?

Take my free 7-day email crash course now (with sample code).

Click to sign-up and also get a free PDF Ebook version of the course.

<a href="https://machinelearningmastery.lpages.co/leadbox/1433e7773f72a2%3A164f8be4f346dc/5764144745676800/" target="_blank" style="background: rgb(255, 206, 10); color: rgb(255, 255, 255); text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-weight: bold; font-size: 16px; line-height: 20px; padding: 10px; display: inline-block; max-width: 300px; border-radius: 5px; text-shadow: rgba(0, 0, 0, 0.25) 0px -1px 1px; box-shadow: rgba(255, 255, 255, 0.5) 0px 1px 3px inset, rgba(0, 0, 0, 0.5) 0px 1px 3px;" rel="noopener noreferrer">Download Your FREE Mini-Course</a>

Data Scaling Methods

There are two types of scaling of your data that you may want to consider: normalization and standardization.

These can both be achieved using the scikit-learn library.

Data Normalization

Normalization is a rescaling of the data from the original range so that all values are within the range of 0 and 1.

Normalization requires that you know or are able to accurately estimate the minimum and maximum observable values. You may be able to estimate these values from your available data.

A value is normalized as follows:

Where the minimum and maximum values pertain to the value x being normalized.

For example, for a dataset, we could guesstimate the min and max observable values as 30 and -10. We can then normalize any value, like 18.8, as follows:

You can see that if an x value is provided that is outside the bounds of the minimum and maximum values, the resulting value will not be in the range of 0 and 1. You could check for these observations prior to making predictions and either remove them from the dataset or limit them to the pre-defined maximum or minimum values.

You can normalize your dataset using the scikit-learn object <a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html">MinMaxScaler</a>.

Good practice usage with the MinMaxScaler and other scaling techniques is as follows:

  • Fit the scaler using available training data. For normalization, this means the training data will be used to estimate the minimum and maximum observable values. This is done by calling the fit() function.
  • Apply the scale to training data. This means you can use the normalized data to train your model. This is done by calling the transform() function.
  • Apply the scale to data going forward. This means you can prepare new data in the future on which you want to make predictions.

The default scale for the MinMaxScaler is to rescale variables into the range [0,1], although a preferred scale can be specified via the “feature_range” argument and specify a tuple including the min and the max for all variables.

If needed, the transform can be inverted. This is useful for converting predictions back into their original scale for reporting or plotting. This can be done by calling the inverse_transform() function.

The example below provides a general demonstration for using the MinMaxScaler to normalize data.

You can also perform the fit and transform in a single step using the fit_transform() function; for example:

Data Standardization

Standardizing a dataset involves rescaling the distribution of values so that the mean of observed values is 0 and the standard deviation is 1. It is sometimes referred to as “whitening.”

This can be thought of as subtracting the mean value or centering the data.

Like normalization, standardization can be useful, and even required in some machine learning algorithms when your data has input values with differing scales.

Standardization assumes that your observations fit a Gaussian distribution (bell curve) with a well behaved mean and standard deviation. You can still standardize your data if this expectation is not met, but you may not get reliable results.

Standardization requires that you know or are able to accurately estimate the mean and standard deviation of observable values. You may be able to estimate these values from your training data.

A value is standardized as follows:

Where the mean is calculated as:

And the standard_deviation is calculated as:

We can guesstimate a mean of 10 and a standard deviation of about 5. Using these values, we can standardize the first value of 20.7 as follows:

The mean and standard deviation estimates of a dataset can be more robust to new data than the minimum and maximum.

You can standardize your dataset using the scikit-learn object <a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html">StandardScaler</a>.

You can also perform the fit and transform in a single step using the fit_transform() function; for example:

Regression Predictive Modeling Problem

A regression <a href="https://machinelearningmastery.com/gentle-introduction-to-predictive-modeling/">predictive modeling</a> problem involves predicting a real-valued quantity.

We can use a standard regression problem generator provided by the scikit-learn library in the <a href="http://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_regression.html">make_regression() function</a>. This function will generate examples from a simple regression problem with a given number of input variables, statistical noise, and other properties.

We will use this function to define a problem that has 20 input features; 10 of the features will be meaningful and 10 will not be relevant. A total of 1,000 examples will be randomly generated. The <a href="https://machinelearningmastery.com/how-to-generate-random-numbers-in-python/">pseudorandom number generator</a> will be fixed to ensure that we get the same 1,000 examples each time the code is run.

Each input variable has a Gaussian distribution, as does the target variable.

We can demonstrate this by creating histograms of some of the input variables and the output variable.

Running the example creates two figures.

The first shows histograms of the first two of the twenty input variables, showing that each has a Gaussian data distribution.

The second figure shows a histogram of the target variable, showing a much larger range for the variable as compared to the input variables and, again, a Gaussian data distribution.

Now that we have a regression problem that we can use as the basis for the investigation, we can develop a model to address it.

Multilayer Perceptron With Unscaled Data

We can develop a Multilayer Perceptron (MLP) model for the regression problem.

A model will be demonstrated on the raw data, without any scaling of the input or output variables. We expect that model performance will be generally poor.

The first step is to split the data into train and test sets so that we can fit and evaluate a model. We will generate 1,000 examples from the domain and split the dataset in half, using 500 examples for the train and test datasets.

Next, we can define an MLP model. The model will expect 20 inputs in the 20 input variables in the problem.

A single hidden layer will be used with 25 nodes and a rectified linear activation function. The output layer has one node for the single target variable and a linear activation function to predict real values directly.

The mean squared error loss function will be used to optimize the model and the stochastic gradient descent optimization algorithm will be used with the sensible default configuration of a learning rate of 0.01 and a momentum of 0.9.

The model will be fit for 100 training epochs and the test set will be used as a validation set, evaluated at the end of each training epoch.

The mean squared error is calculated on the train and test datasets at the end of training to get an idea of how well the model learned the problem.

Finally, learning curves of mean squared error on the train and test sets at the end of each training epoch are graphed using line plots, providing learning curves to get an idea of the dynamics of the model while learning the problem.

Tying these elements together, the complete example is listed below.

Running the example fits the model and calculates the mean squared error on the train and test sets.

In this case, the model is unable to learn the problem, resulting in predictions of NaN values. The <a href="https://machinelearningmastery.com/exploding-gradients-in-neural-networks/">model weights exploded</a> during training given the very large errors and, in turn, error gradients calculated for weight updates.

This demonstrates that, at the very least, some data scaling is required for the target variable.

A line plot of training history is created but does not show anything as the model almost immediately results in a NaN mean squared error.

Multilayer Perceptron With Scaled Output Variables

The MLP model can be updated to scale the target variable.

Reducing the scale of the target variable will, in turn, reduce the size of the gradient used to update the weights and result in a more stable model and training process.

Given the Gaussian distribution of the target variable, a natural method for rescaling the variable would be to standardize the variable. This requires estimating the mean and standard deviation of the variable and using these estimates to perform the rescaling.

It is best practice is to estimate the mean and standard deviation of the training dataset and use these variables to scale the train and test dataset. This is to avoid any data leakage during the model evaluation process.

The scikit-learn transformers expect input data to be matrices of rows and columns, therefore the 1D arrays for the target variable will have to be reshaped into 2D arrays prior to the transforms.

We can then create and apply the StandardScaler to rescale the target variable.

Rescaling the target variable means that estimating the performance of the model and plotting the learning curves will calculate an MSE in squared units of the scaled variable rather than squared units of the original scale. This can make interpreting the error within the context of the domain challenging.

In practice, it may be helpful to estimate the performance of the model by first inverting the transform on the test dataset target variable and on the model predictions and estimating model performance using the root mean squared error on the unscaled data. This is left as an exercise to the reader.

The complete example of standardizing the target variable for the MLP on the regression problem is listed below.

Running the example fits the model and calculates the mean squared error on the train and test sets.

Note: Your <a href="https://machinelearningmastery.com/different-results-each-time-in-machine-learning/">results may vary</a> given the stochastic nature of the algorithm or evaluation procedure, or differences in numerical precision. Consider running the example a few times and compare the average outcome.

In this case, the model does appear to learn the problem and achieves near-zero mean squared error, at least to three decimal places.

A line plot of the mean squared error on the train (blue) and test (orange) dataset over each training epoch is created.

In this case, we can see that the model rapidly learns to effectively map inputs to outputs for the regression problem and achieves good performance on both datasets over the course of the run, neither overfitting or underfitting the training dataset.

It may be interesting to repeat this experiment and normalize the target variable instead and compare results.

Multilayer Perceptron With Scaled Input Variables

We have seen that data scaling can stabilize the training process when fitting a model for regression with a target variable that has a wide spread.

It is also possible to improve the stability and performance of the model by scaling the input variables.

In this section, we will design an experiment to compare the performance of different scaling methods for the input variables.

The input variables also have a Gaussian data distribution, like the target variable, therefore we would expect that standardizing the data would be the best approach. This is not always the case.

We can compare the performance of the unscaled input variables to models fit with either standardized and normalized input variables.

The first step is to define a function to create the same 1,000 data samples, split them into train and test sets, and apply the data scaling methods specified via input arguments. The get_dataset() function below implements this, requiring the scaler to be provided for the input and target variables and returns the train and test datasets split into input and output components ready to train and evaluate a model.

Next, we can define a function to fit an MLP model on a given dataset and return the mean squared error for the fit model on the test dataset.

The evaluate_model() function below implements this behavior.

Neural networks are trained using a stochastic learning algorithm. This means that the same model fit on the same data may result in a different performance.

We can address this in our experiment by repeating the evaluation of each model configuration, in this case a choice of data scaling, multiple times and report performance as the mean of the error scores across all of the runs. We will repeat each run 30 times to ensure the mean is statistically robust.

The repeated_evaluation() function below implements this, taking the scaler for input and output variables as arguments, evaluating a model 30 times with those scalers, printing error scores along the way, and returning a list of the calculated error scores from each run.

Finally, we can run the experiment and evaluate the same model on the same dataset three different ways:

  • No scaling of inputs, standardized outputs.
  • Normalized inputs, standardized outputs.
  • Standardized inputs, standardized outputs.

The mean and standard deviation of the error for each configuration is reported, then box and whisker plots are created to summarize the error scores for each configuration.

Tying these elements together, the complete example is listed below.

Running the example prints the mean squared error for each model run along the way.

After each of the three configurations have been evaluated 30 times each, the mean errors for each are reported.

Note: Your <a href="https://machinelearningmastery.com/different-results-each-time-in-machine-learning/">results may vary</a> given the stochastic nature of the algorithm or evaluation procedure, or differences in numerical precision. Consider running the example a few times and compare the average outcome.

In this case, we can see that as we expected, scaling the input variables does result in a model with better performance. Unexpectedly, better performance is seen using normalized inputs instead of standardized inputs. This may be related to the choice of the rectified linear activation function in the first hidden layer.

A figure with three box and whisker plots is created summarizing the spread of error scores for each configuration.

The plots show that there was little difference between the distributions of error scores for the unscaled and standardized input variables, and that the normalized input variables result in better performance and more stable or a tighter distribution of error scores.

These results highlight that it is important to actually experiment and confirm the results of data scaling methods rather than assuming that a given data preparation scheme will work best based on the observed distribution of the data.

Extensions

This section lists some ideas for extending the tutorial that you may wish to explore.

  • Normalize Target Variable. Update the example and normalize instead of standardize the target variable and compare results.
  • Compared Scaling for Target Variable. Update the example to compare standardizing and normalizing the target variable using repeated experiments and compare the results.
  • Other Scales. Update the example to evaluate other min/max scales when normalizing and compare performance, e.g. [-1, 1] and [0.0, 0.5].

If you explore any of these extensions, I’d love to know.

Further Reading

This section provides more resources on the topic if you are looking to go deeper.

Posts

Books

  • Section 8.2 Input normalization and encoding, <a href="https://amzn.to/2S8qdwt">Neural Networks for Pattern Recognition</a>, 1995.

API

Articles

Summary

In this tutorial, you discovered how to improve neural network stability and modeling performance by scaling data.

Specifically, you learned:

  • Data scaling is a recommended pre-processing step when working with deep learning neural networks.
  • Data scaling can be achieved by normalizing or standardizing real-valued input and output variables.
  • How to apply standardization and normalization to improve the performance of a Multilayer Perceptron model on a regression predictive modeling problem.

Do you have any questions?
Ask your questions in the comments below and I will do my best to answer.

Develop Better Deep Learning Models Today!

<a href="/better-deep-learning/" rel="nofollow"><img width="220" height="311" style="border: 0;" src="/wp-content/uploads/2018/12/Cover-220.png" alt="Better Deep Learning" align="left" /></a>

Train Faster, Reduce Overftting, and Ensembles

...with just a few lines of python code

Discover how in my new Ebook:
<a href="/better-deep-learning/" rel="nofollow">Better Deep Learning</a>

It provides self-study tutorials on topics like:
weight decay, batch normalization, dropout, model stacking and much more...

Bring better deep learning to your projects!

Skip the Academics. Just Results.

<a href="/better-deep-learning/" class="woo-sc-button red" >See What's Inside</a>

<button class="ssb_tweet-icon" data-href="https://twitter.com/share?text=How+to+use+Data+Scaling+Improve+Deep+Learning+Model+Stability+and+Performance&url=https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/" rel="nofollow" onclick="if (!window.__cfRLUnblockHandlers) return false; javascript:window.open(this.dataset.href, , 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;" data-cf-modified-f3886dae12b0536ad361ea93-=""> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 72"><path fill="none" d="M0 0h72v72H0z"/><path class="icon" fill="#fff" d="M68.812 15.14c-2.348 1.04-4.87 1.744-7.52 2.06 2.704-1.62 4.78-4.186 5.757-7.243-2.53 1.5-5.33 2.592-8.314 3.176C56.35 10.59 52.948 9 49.182 9c-7.23 0-13.092 5.86-13.092 13.093 0 1.026.118 2.02.338 2.98C25.543 24.527 15.9 19.318 9.44 11.396c-1.125 1.936-1.77 4.184-1.77 6.58 0 4.543 2.312 8.552 5.824 10.9-2.146-.07-4.165-.658-5.93-1.64-.002.056-.002.11-.002.163 0 6.345 4.513 11.638 10.504 12.84-1.1.298-2.256.457-3.45.457-.845 0-1.666-.078-2.464-.23 1.667 5.2 6.5 8.985 12.23 9.09-4.482 3.51-10.13 5.605-16.26 5.605-1.055 0-2.096-.06-3.122-.184 5.794 3.717 12.676 5.882 20.067 5.882 24.083 0 37.25-19.95 37.25-37.25 0-.565-.013-1.133-.038-1.693 2.558-1.847 4.778-4.15 6.532-6.774z"/></svg>Tweet </button> <button class="ssb_fbshare-icon" target="_blank" data-href="https://www.facebook.com/sharer/sharer.php?u=https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/" onclick="if (!window.__cfRLUnblockHandlers) return false; javascript:window.open(this.dataset.href, , 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;" data-cf-modified-f3886dae12b0536ad361ea93-=""> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" class="_1pbq" color="#ffffff"><path fill="#ffffff" fill-rule="evenodd" class="icon" d="M8 14H3.667C2.733 13.9 2 13.167 2 12.233V3.667A1.65 1.65 0 0 1 3.667 2h8.666A1.65 1.65 0 0 1 14 3.667v8.566c0 .934-.733 1.667-1.667 1.767H10v-3.967h1.3l.7-2.066h-2V6.933c0-.466.167-.9.867-.9H12v-1.8c.033 0-.933-.266-1.533-.266-1.267 0-2.434.7-2.467 2.133v1.867H6v2.066h2V14z"></path></svg> Share </button> <button class="ssb_linkedin-icon" data-href="https://www.linkedin.com/cws/share?url=https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/" onclick="if (!window.__cfRLUnblockHandlers) return false; javascript:window.open(this.dataset.href, , 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;" data-cf-modified-f3886dae12b0536ad361ea93-=""> <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="15px" height="14.1px" viewBox="-301.4 387.5 15 14.1" enable-background="new -301.4 387.5 15 14.1" xml:space="preserve"> <g id="XMLID_398_"> <path id="XMLID_399_" fill="#FFFFFF" d="M-296.2,401.6c0-3.2,0-6.3,0-9.5h0.1c1,0,2,0,2.9,0c0.1,0,0.1,0,0.1,0.1c0,0.4,0,0.8,0,1.2 c0.1-0.1,0.2-0.3,0.3-0.4c0.5-0.7,1.2-1,2.1-1.1c0.8-0.1,1.5,0,2.2,0.3c0.7,0.4,1.2,0.8,1.5,1.4c0.4,0.8,0.6,1.7,0.6,2.5 c0,1.8,0,3.6,0,5.4v0.1c-1.1,0-2.1,0-3.2,0c0-0.1,0-0.1,0-0.2c0-1.6,0-3.2,0-4.8c0-0.4,0-0.8-0.2-1.2c-0.2-0.7-0.8-1-1.6-1 c-0.8,0.1-1.3,0.5-1.6,1.2c-0.1,0.2-0.1,0.5-0.1,0.8c0,1.7,0,3.4,0,5.1c0,0.2,0,0.2-0.2,0.2c-1,0-1.9,0-2.9,0 C-296.1,401.6-296.2,401.6-296.2,401.6z"/> <path id="XMLID_400_" fill="#FFFFFF" d="M-298,401.6L-298,401.6c-1.1,0-2.1,0-3,0c-0.1,0-0.1,0-0.1-0.1c0-3.1,0-6.1,0-9.2 c0-0.1,0-0.1,0.1-0.1c1,0,2,0,2.9,0h0.1C-298,395.3-298,398.5-298,401.6z"/> <path id="XMLID_401_" fill="#FFFFFF" d="M-299.6,390.9c-0.7-0.1-1.2-0.3-1.6-0.8c-0.5-0.8-0.2-2.1,1-2.4c0.6-0.2,1.2-0.1,1.8,0.2 c0.5,0.4,0.7,0.9,0.6,1.5c-0.1,0.7-0.5,1.1-1.1,1.3C-299.1,390.8-299.4,390.8-299.6,390.9L-299.6,390.9z"/> </g> </svg> Share </button>

</section>

<aside id="post-author">

About Jason Brownlee

Jason Brownlee, PhD is a machine learning specialist who teaches developers how to get results with modern machine learning methods via hands-on tutorials.

</aside>

</article>

125 Responses to How to use Data Scaling Improve Deep Learning Model Stability and Performance

  1. Wonbin February 13, 2019 at 6:03 pm <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-468125" title="Direct link to this comment">#</a>

    Thank you for this helpful post for beginners!

    Could you please provide more details about the steps of “using the root mean squared error on the unscaled data” to interpret the performance in a specific domain?

    Would it be like this??
    ———————————————————–
    1. Finalize the model (based on the performance being calculated from the scaled output variable)
    2. Make predictions on test set
    3. Invert the predictions (to convert them back into their original scale)
    4. Calculate the metrics (e.g. RMSE, MAPE)
    ———————————————————–

    Waiting for your reply! Cheers mate!


    <a rel='nofollow' class='comment-reply-link' href='#comment-468125' data-commentid="468125" data-postid="6939" data-belowelement="comment-468125" data-respondelement="respond" data-replyto="Reply to Wonbin" aria-label='Reply to Wonbin'>Reply</a>
  2. mk123qwe February 19, 2019 at 5:38 pm <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-469330" title="Direct link to this comment">#</a>

    we want standardized inputs, no scaling of outputs,but outputs value is not in (0,1).Are the predictions inaccurate?


    <a rel='nofollow' class='comment-reply-link' href='#comment-469330' data-commentid="469330" data-postid="6939" data-belowelement="comment-469330" data-respondelement="respond" data-replyto="Reply to mk123qwe" aria-label='Reply to mk123qwe'>Reply</a>
  3. yingxiao kong February 28, 2019 at 8:17 am <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-471145" title="Direct link to this comment">#</a>

    Hi Jason,

    Your experiment is very helpful for me to understand the difference between different methods, actually I have also done similar things. I always standardized the input data. I have compared the results between standardized and standardized targets. The plots shows that with standardized targets, the network seems to work better. However, here I have a question: suppose the standard deviation of my target is 300, then I think the MSE will be strongly decreased after you fixed the standard deviation to 1. So shall we multiply the original std to the MSE in order to get the MSE in the original target value space?


    <a rel='nofollow' class='comment-reply-link' href='#comment-471145' data-commentid="471145" data-postid="6939" data-belowelement="comment-471145" data-respondelement="respond" data-replyto="Reply to yingxiao kong" aria-label='Reply to yingxiao kong'>Reply</a>
  4. Hi Jason,

    My data includes categorical and continued data. Could I transform the categorical data with 1,2,3…into standardized data and put them into the neural network models to make classification? Or do I need to transformr the categorical data with with one-hot coding(0,1)? I have been confused about it. Thanks


    <a rel='nofollow' class='comment-reply-link' href='#comment-473491' data-commentid="473491" data-postid="6939" data-belowelement="comment-473491" data-respondelement="respond" data-replyto="Reply to Beato" aria-label='Reply to Beato'>Reply</a>
  5. Hi Jason, I have a specific Question regarding the normalization (min-max scaling) of the output value. Usually you are supposed to use normalization only on the training data set and then apply those stats to the validation and test set. Otherwise you would feed the model at training time certain information about the world it shouldn’t have access to. (The Elements of Statistical Learning: Data Mining, Inference, and Prediction p.247)

    But for instance, my output value is a single percentage value ranging [0, 100%] and I am using the ReLU activation function in my output layer. I know for sure that in the “real world” regarding my problem statement, that I will get samples ranging form 60 – 100%. But my training sample size is to small and does not contain enough data points including all possible output values. So here comes my question: Should I stay with my initial statement (normalization only on training data set) or should I apply the maximum possible value of 100% to max()-value of the normalization step? The latter would contradict the literature. Best Regards Bart


    <a rel='nofollow' class='comment-reply-link' href='#comment-474594' data-commentid="474594" data-postid="6939" data-belowelement="comment-474594" data-respondelement="respond" data-replyto="Reply to Bart" aria-label='Reply to Bart'>Reply</a>
  6. Dear Jason, thank you for the great article.

    I am wondering if there is any advantage using StadardScaler or MinMaxScaler over scaling manually. I could calculate the mean, std or min, max of my training data and apply them with the corresponding formula for standard or minmax scaling.

    Would this approach produce the same results as the StadardScaler or MinMaxScaler or are the sklearn scalers special?


    <a rel='nofollow' class='comment-reply-link' href='#comment-476186' data-commentid="476186" data-postid="6939" data-belowelement="comment-476186" data-respondelement="respond" data-replyto="Reply to Mike" aria-label='Reply to Mike'>Reply</a>
  7. Dear Jason,

    I have a few questions from section “Data normalization”. You mention that we should estimate the max and min values, and use that to normalize the training set to e.g. [-1,1]. But what if the max and min values are in the validation or test set? Then I might get values e.g. [-1.2, 1.3] in the validation set. Do you consider this to be incorrect or not?

    Another approach is then to make sure that the min and max values for all parameters are contained in the training set. What are your thoughts on this? Is this the way to do it? Or should we use the max and min values for all data combined (training, validation and test sets) when normalizing the training set?

    For the moment I use the MinMaxScaler and fit_transform on the training set and then apply that scaler on the validation and test set using transform. But I realise that some of my max values are in the validation set. I suppose this is also related to network saturation.


    <a rel='nofollow' class='comment-reply-link' href='#comment-484599' data-commentid="484599" data-postid="6939" data-belowelement="comment-484599" data-respondelement="respond" data-replyto="Reply to Magnus" aria-label='Reply to Magnus'>Reply</a>
  8. Hello Jason, I am a huge fan of your work! Thank you so much for your insightful tutorials. You are a life saver! I have a small question if i may:

    I am trying to fit spectrograms in a cnn in order to do some classification tasks. Unfortunately each spectrogram is around (3000,300) array. Is there a way to reduce the dimensionality without losing so much information?


    <a rel='nofollow' class='comment-reply-link' href='#comment-487085' data-commentid="487085" data-postid="6939" data-belowelement="comment-487085" data-respondelement="respond" data-replyto="Reply to youssef" aria-label='Reply to youssef'>Reply</a>
  9. Hi Jason,
    It was always good and informative to go through your blogs and your interaction with comments by different people all across the globe.
    I have question regarding the scaling techniques.

    As you explained about scaling :
    Case1:

    1. created scaler
    scaler = StandardScaler()
    1. fit scaler on training dataset
    scaler.fit(trainy)
    1. transform training dataset
    trainy = scaler.transform(trainy)
    1. transform test dataset
    testy = scaler.transform(testy)

    in this case mean and standard deviation for all train and test remain same.

    What i approached is:
    case2

    1. created scaler
    scaler_train = StandardScaler()
    1. fit scaler on training dataset
    scaler_train.fit(trainy)
    1. transform training dataset
    trainy = scaler_train.transform(trainy)

    # created scaler
    scaler_test = StandardScaler()

    1. fit scaler on training dataset
    scaler_test.fit(trainy)
    1. transform test dataset
    testy = scaler_test.transform(testy)

    Here the mean and standard deviation in train data and test data are different.so model may find the test data completely unknown and new .rather in first case where mean and standard deviation is same on train and test data that may leads to providing the known test data to model (known in term of same mean and standard deviation treatment).

    Jason,can you guide me if my logics is good to go with case2 or shall i consider case1 .
    or if logic is wrong you can also say that and explain.
    (Also i applied Same for min-max scaling i.e normalization, if i choose this then)
    Again thanks Jason for such a nice work !

    Happy Learning !!


    <a rel='nofollow' class='comment-reply-link' href='#comment-491581' data-commentid="491581" data-postid="6939" data-belowelement="comment-491581" data-respondelement="respond" data-replyto="Reply to Muktamani" aria-label='Reply to Muktamani'>Reply</a>
  10. Hi Jason,

    I’m working on sequence2sequence problem. Input’s max and min points are around 500-300, however output’s are 200-0. If I want to normalize them, should I use different scalers? For example:

    scx = MinMaxScaler(feature_range = (0, 1))
    scy = MinMaxScaler(feature_range = (0, 1))

    trainx = scx.fit_transform(trainx)
    trainy = scy.fit_transform(trainy)

    or should I scale them with same scale like below?

    sc = MinMaxScaler(feature_range = (0, 1))

    trainx = sc.fit_transform(trainx)
    trainy = sc.fit_transform(trainy)


    <a rel='nofollow' class='comment-reply-link' href='#comment-491776' data-commentid="491776" data-postid="6939" data-belowelement="comment-491776" data-respondelement="respond" data-replyto="Reply to ICHaLiL" aria-label='Reply to ICHaLiL'>Reply</a>
  11. Hi Jason,

    Confused about one aspect, I have a small NN with 8 independent variables and one dichotomous dependent variable. I have standardized the input variables (the output variable was left untouched). I have both trained and created the final model with the same standardized data. However, the question is, if I want to create a user interface to receive manual inputs, those will no longer be in the standardized format, so what is the best way to proceed?


    <a rel='nofollow' class='comment-reply-link' href='#comment-492643' data-commentid="492643" data-postid="6939" data-belowelement="comment-492643" data-respondelement="respond" data-replyto="Reply to Brent" aria-label='Reply to Brent'>Reply</a>
  12. Hi Jason,

    I have built an ANN model and scaled my inputs and outputs before feeding to the network. I measure the performance of the model by r2_score. My output variable is height. My r2_score when the output variable is in metres is .98, but when my output variable is in centi-metres , my r2_score is .91. I have scaled my output too before feeding to the network, why is there a difference in r2_score even because the output variable is scaled before feeding to the network.

    Thanks in advance


    <a rel='nofollow' class='comment-reply-link' href='#comment-493673' data-commentid="493673" data-postid="6939" data-belowelement="comment-493673" data-respondelement="respond" data-replyto="Reply to cgv" aria-label='Reply to cgv'>Reply</a>
  13. joshBorrison October 7, 2019 at 5:08 pm <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-504531" title="Direct link to this comment">#</a>

    Hi Jason,

    Do I have to use only one normalization formula for all inputs?

    For example: I have 5 inputs [inp1, inp2, inp3, inp4, inp5] where I can estimate max and min only for [inp1, inp2]. So can I use

    y = (x – min) / (max – min)

    for [inp1, inp2] and

    y = x/(1+x)

    for [inp3, inp4, inp5]?


    <a rel='nofollow' class='comment-reply-link' href='#comment-504531' data-commentid="504531" data-postid="6939" data-belowelement="comment-504531" data-respondelement="respond" data-replyto="Reply to joshBorrison" aria-label='Reply to joshBorrison'>Reply</a>
  14. shiva November 13, 2019 at 4:17 am <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-510336" title="Direct link to this comment">#</a>

    Hi Jason

    what if I scale the word vectors(glove) for exposing to LSTM?

    would it affect the accuracy of results or it maintains the semantic relations of words?

    Thank you a lot.


    <a rel='nofollow' class='comment-reply-link' href='#comment-510336' data-commentid="510336" data-postid="6939" data-belowelement="comment-510336" data-respondelement="respond" data-replyto="Reply to shiva" aria-label='Reply to shiva'>Reply</a>
  15. Murilo Souza November 14, 2019 at 12:35 am <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-510516" title="Direct link to this comment">#</a>

    Hello, i was trying to normalize/inverse transoformation in my data, but i got one error that i think its due to the resize i did in my input data. Here’s my code:

    import numpy as np
    import tensorflow as tf
    from tensorflow import keras
    import pandas as pd
    import time as time
    import matplotlib.pyplot as plt
    import pydot
    import csv as csv
    import keras.backend as K
    from sklearn.preprocessing import MinMaxScaler

    # Downloading data
    !wget <a href="https://raw.githubusercontent.com/sibyjackgrove/CNN-on-Wind-Power-Data/master/MISO_power_data_classification_labels.csv" rel="nofollow ugc">https://raw.githubusercontent.com/sibyjackgrove/CNN-on-Wind-Power-Data/master/MISO_power_data_classification_labels.csv</a>
    !wget <a href="https://raw.githubusercontent.com/sibyjackgrove/CNN-on-Wind-Power-Data/master/MISO_power_data_input.csv" rel="nofollow ugc">https://raw.githubusercontent.com/sibyjackgrove/CNN-on-Wind-Power-Data/master/MISO_power_data_input.csv</a>

    # Trying normalization
    batch_size = 1
    valid_size = max(1,np.int(0.2*batch_size))
    df_input = pd.read_csv(‘./MISO_power_data_input.csv’,usecols =[‘Wind_MWh’,’Actual_Load_MWh’], chunksize=24*(batch_size+valid_size),nrows = 24*(batch_size+valid_size),iterator=True)
    df_target = pd.read_csv(‘./MISO_power_data_classification_labels.csv’,usecols =[‘Mean Wind Power’,’Standard Deviation’,’WindShare’],chunksize =batch_size+valid_size,nrows = batch_size+valid_size, iterator=True)
    for chunk, chunk2 in zip(df_input,df_target):
    InputX = chunk.values
    InputX = np.resize(InputX,(batch_size+valid_size,24,2,1))
    print(InputX)
    InputX.astype(‘float32’, copy=False)
    InputY = chunk2.values
    InputY.astype(‘float32’, copy=False)
    print(InputY)

    # create scaler
    scaler = MinMaxScaler() # Define limits for normalize data
    normalized_input = scaler.fit_transform(InputX) # Normalize input data
    normalized_output = scaler.fit_transform(InputY) # Normalize output data
    print(normalized_input)
    print(normalized_output)
    inverse_output = scaler.inverse_transform(normalized_output) # Inverse transformation of output data
    print(inverse_output)

    The error:

    “ValueError: Found array with dim 4. MinMaxScaler expected <= 2."

    Do you have any idea how can i fix this? I really didn't wish to change the resize command at the moment.


    <a rel='nofollow' class='comment-reply-link' href='#comment-510516' data-commentid="510516" data-postid="6939" data-belowelement="comment-510516" data-respondelement="respond" data-replyto="Reply to Murilo Souza" aria-label='Reply to Murilo Souza'>Reply</a>
  16. Jules Damji November 14, 2019 at 6:55 am <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-510545" title="Direct link to this comment">#</a>

    Hey Jason,

    I love this tutorial. I was wondering if I can get your permission to use this tutorial, convert all its experimentation and tracking using MLflow, and include it in my tutorials I teach at conferences.

    It’s a fitting example of how you can use MLFlow to track different experiments and visually compare the outcomes.

    All the credit will be given to you as the source and inspiration. You can see some of the examples here: <a href="https://github.com/dmatrix/spark-saturday/tree/master/tutorials/mlflow/src/python" rel="nofollow ugc">https://github.com/dmatrix/spark-saturday/tree/master/tutorials/mlflow/src/python</a>.


    <a rel='nofollow' class='comment-reply-link' href='#comment-510545' data-commentid="510545" data-postid="6939" data-belowelement="comment-510545" data-respondelement="respond" data-replyto="Reply to Jules Damji" aria-label='Reply to Jules Damji'>Reply</a>
  17. jules Damji November 14, 2019 at 2:45 pm <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-510615" title="Direct link to this comment">#</a>

    Thanks, I will certainly put the original link and plug your book too, along with your site and an excellent resource of tutorials and examples to learn from.

    Cheers
    Jules


    <a rel='nofollow' class='comment-reply-link' href='#comment-510615' data-commentid="510615" data-postid="6939" data-belowelement="comment-510615" data-respondelement="respond" data-replyto="Reply to jules Damji" aria-label='Reply to jules Damji'>Reply</a>
  18. Hanser November 28, 2019 at 8:13 am <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-512747" title="Direct link to this comment">#</a>

    Amazing content Jason! I was wondering if it is possible to apply different scalers to different inputs given based on their original characteristics? I am asking you that because as you mentioned in the tutorial “Differences in the scales across input variables may increase the difficulty of the problem being modeled” Therefore, if I use standard scaler in one input and normal scaler in another it could be bad for gradient descend.


    <a rel='nofollow' class='comment-reply-link' href='#comment-512747' data-commentid="512747" data-postid="6939" data-belowelement="comment-512747" data-respondelement="respond" data-replyto="Reply to Hanser" aria-label='Reply to Hanser'>Reply</a>
  19. Riyaz Pasha December 9, 2019 at 9:26 pm <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-514349" title="Direct link to this comment">#</a>

    Hi Jason,
    I am solving the Regression problem and my accuracy after normalizing the target variable is 92% but I have the doubt about scaling the target variable. So can you elaborate about scaling the Target variable?


    <a rel='nofollow' class='comment-reply-link' href='#comment-514349' data-commentid="514349" data-postid="6939" data-belowelement="comment-514349" data-respondelement="respond" data-replyto="Reply to Riyaz Pasha" aria-label='Reply to Riyaz Pasha'>Reply</a>
  20. Hi Jason Sir!
    My data range is variable, e.g. -1500000, 0.0003456, 2387900,23,50,-45,-0.034, what should i do? i want to use MLP, 1D-CNN and SAE.
    THANKS


    <a rel='nofollow' class='comment-reply-link' href='#comment-516662' data-commentid="516662" data-postid="6939" data-belowelement="comment-516662" data-respondelement="respond" data-replyto="Reply to FAIZ" aria-label='Reply to FAIZ'>Reply</a>
  21. Hi Jason

    I have a question about the normalization of data. Samples from the population may be added to the dataset over time, and the attribute values for these new objects may then lie outside those you have seen so far. One possibility to handle new minimum and maximum values is to periodically renormalize the data after including the new values. Is there any normalization approach without renormalization?

    Thanks,


    <a rel='nofollow' class='comment-reply-link' href='#comment-519745' data-commentid="519745" data-postid="6939" data-belowelement="comment-519745" data-respondelement="respond" data-replyto="Reply to BNB" aria-label='Reply to BNB'>Reply</a>
  22. <a href='http://None.' rel='external nofollow ugc' class='url'>Tajik</a> February 19, 2020 at 1:15 am <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-522214" title="Direct link to this comment">#</a>

    Hi Jason

    Should we use “standard_deviation = sqrt( sum( (x – mean)**2 ) / count(x))” instead of “standard_deviation = sqrt( sum( (x – mean)^2 ) / count(x))”?

    Does “^” sign represent square root in Python and is it fine not to subtract count (x) by 1 (in order to make it std of sample distribution, unless we have 100% observation of a population)?

    Thank you

    Best
    Tajik


    <a rel='nofollow' class='comment-reply-link' href='#comment-522214' data-commentid="522214" data-postid="6939" data-belowelement="comment-522214" data-respondelement="respond" data-replyto="Reply to Tajik" aria-label='Reply to Tajik'>Reply</a>
  23. Peter February 22, 2020 at 6:18 am <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-522703" title="Direct link to this comment">#</a>

    Hi Jason,

    Very helpful post as always! I am slightly confused regarding the use of the scaler object though. In my scenario…

    If I have a set of data that I split into a training set and validation set, I then scale the data as follows:

    scaler = MinMaxScaler()
    scaledTrain = scaler.fit_transform(trainingSet)
    scaledValid = scaler.transform(validationSet)

    I then use this data to train a deep learning model.

    My question is, should I use the same scaler object, which was created using the training set, to scale my new, unseen test data before using that test set for predicting my model’s performance? Or should I create a new, separate scaler object using the test data?

    Thanks in advance

    Michael


    <a rel='nofollow' class='comment-reply-link' href='#comment-522703' data-commentid="522703" data-postid="6939" data-belowelement="comment-522703" data-respondelement="respond" data-replyto="Reply to Peter" aria-label='Reply to Peter'>Reply</a>
  24. Hi Jason,

    Thank you for the tutorial. A question about the conclusion: I find it surprising that standardization did not yield better performance compared to the model with unscaled inputs. Shouldn’t standardization provide better convergence properties when training neural networks? It’s also surprising that min-max scaling worked so well. If all of your inputs are positive (i.e between [0, 1] in this case), doesn’t that mean ALL of your weight updates at each step will be the same sign, which leads to inefficient learning?


    <a rel='nofollow' class='comment-reply-link' href='#comment-525070' data-commentid="525070" data-postid="6939" data-belowelement="comment-525070" data-respondelement="respond" data-replyto="Reply to Mike" aria-label='Reply to Mike'>Reply</a>
  25. Zeynep newby May 15, 2020 at 8:59 pm <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-534865" title="Direct link to this comment">#</a>

    Hi Jason,

    I am an absolute beginner into neural networks and I appreciate your helpful website. In the lecture, I learned that when normalizing a training set, one should use the same mean and standard deviation from training for the test set. But I see in your codes that you’re normalizing training and test sets individually. Is that for a specific reason?


    <a rel='nofollow' class='comment-reply-link' href='#comment-534865' data-commentid="534865" data-postid="6939" data-belowelement="comment-534865" data-respondelement="respond" data-replyto="Reply to Zeynep newby" aria-label='Reply to Zeynep newby'>Reply</a>
  26. Zeynep newby May 15, 2020 at 9:04 pm <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-534866" title="Direct link to this comment">#</a>

    Hi again,

    since I saw another comment having the same question like me, I noticed that you acutally have done exactly the same thing as I expected. Since I am not familiar with the syntax yet, I got it wrong. Thanks very much!


    <a rel='nofollow' class='comment-reply-link' href='#comment-534866' data-commentid="534866" data-postid="6939" data-belowelement="comment-534866" data-respondelement="respond" data-replyto="Reply to Zeynep newby" aria-label='Reply to Zeynep newby'>Reply</a>
  27. Hai Jaison, I am a beginner in ML and I am having an issue with normalizing..
    I am developing a multivariate regression model with three inputs and three outputs.
    The three inputs are in the range of [700 1500] , [700-1500] and [700 1500]
    The three outputs are in the range of [-0.5 0.5] , [-0.5 0.5] and [700 1500]
    I have normalized everything in the range of [-1 1].
    The loss at the end of 1000 epoch is in the order of 1e-4, but still, I am not satisfied with the fit of the model. Since the loss function is based on normalized target variables and normalized prediction, its value id very less from the first epoch itself.

    Is there a way to bring the cost further down?


    <a rel='nofollow' class='comment-reply-link' href='#comment-535093' data-commentid="535093" data-postid="6939" data-belowelement="comment-535093" data-respondelement="respond" data-replyto="Reply to Isaac" aria-label='Reply to Isaac'>Reply</a>
  28. Victor Yu June 9, 2020 at 11:43 pm <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-538831" title="Direct link to this comment">#</a>

    Hi Jason,

    I wonder how you apply scaling to batch data? Say we batch load from tfrecords, for each batch we fit a scaler? If so, then the final scaler is on the last batch, which will be used for test data? Also in batch data, if the batch is small, then it seems the scaler is volatile, especially for MaxMin. Would like to hear your thoughts since in a lot of practices it’s nearly impossible to load huge data into driver to do scaling.

    Thanks!


    <a rel='nofollow' class='comment-reply-link' href='#comment-538831' data-commentid="538831" data-postid="6939" data-belowelement="comment-538831" data-respondelement="respond" data-replyto="Reply to Victor Yu" aria-label='Reply to Victor Yu'>Reply</a>
  29. Hi Jason,

    In deep learning as machine learning, data should be transformed into a tabular format? if yes or no why?


    <a rel='nofollow' class='comment-reply-link' href='#comment-540105' data-commentid="540105" data-postid="6939" data-belowelement="comment-540105" data-respondelement="respond" data-replyto="Reply to Najeh" aria-label='Reply to Najeh'>Reply</a>
  30. Hello Jason,

    I used your method (i did standardized my outputs and normalized my inputs with MinMaxScaler()) but i keep having the same issue : when i train my neural network with 3200 and validate with 800 everything alright, i have R2 = 99% but when i increase the training / validation set, R2 decreases which is weird, it should be even higher ? Do you think it has something to do with the scaling of the data ?
    Thank you !


    <a rel='nofollow' class='comment-reply-link' href='#comment-540919' data-commentid="540919" data-postid="6939" data-belowelement="comment-540919" data-respondelement="respond" data-replyto="Reply to Julie" aria-label='Reply to Julie'>Reply</a>
  31. Hi sir,

    I have a NN with 6 input variables and one output , I employed minmaxscaler for inputs as well as outputs . My approach was applying the scaler to my whole dataset then splitting it into training and testing dataset, as I dont know the know-hows so is my approach wrong .
    Currently the problem I am facing is my actual outputs are positive values but after unscaling the NN predictions I am getting negative values. I tried changing the feature range, still NN predicted negative values , so how can i solve this?

    Y1=Y1.reshape(-1, 1)
    Y2=Y2.reshape(-1, 1)
    TY1=TY1.reshape(-1, 1)
    TY2=TY2.reshape(-1, 1)
    scaler1 = MinMaxScaler(feature_range=(0, 1))
    rescaledX= scaler1.fit_transform(X)
    rescaledTX=scaler1.fit_transform(TX)
    scaler2 = MinMaxScaler(feature_range=(0, 2))
    rescaledY1 = scaler2.fit_transform(Y1)

    scaler3 = MinMaxScaler(feature_range=(0, 2))

    rescaledY2 = scaler3.fit_transform(Y2)


    <a rel='nofollow' class='comment-reply-link' href='#comment-542748' data-commentid="542748" data-postid="6939" data-belowelement="comment-542748" data-respondelement="respond" data-replyto="Reply to David" aria-label='Reply to David'>Reply</a>
  32. TAMER A. FARRAG July 30, 2020 at 9:42 am <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-546517" title="Direct link to this comment">#</a>

    Thanks a lot,
    My question is:

    I finish training my model and I use normalized data for inputs and outputs.
    my problem now is when I need to use this model I do the following:
    1- I load the model
    2- normalize the inputs
    3- use model to get the outputs (predicted data)

    how to denormalized the output of the model ??? I don’t have the MinMaxScaler for the output ??


    <a rel='nofollow' class='comment-reply-link' href='#comment-546517' data-commentid="546517" data-postid="6939" data-belowelement="comment-546517" data-respondelement="respond" data-replyto="Reply to TAMER A. FARRAG" aria-label='Reply to TAMER A. FARRAG'>Reply</a>
  33. Hi Jason,

    Do you know of any textbooks or journal articles that address the input scaling issue as you’ve described it here, in addition to the Bishop textbook? I’m struggling so far in vain to find discussions of this type of scaling, when different raw input variables have much different ranges. Instead I’m finding plenty of mentions in tutorials and blog posts (of which yours is one of the clearest), and papers describing the problems of scale (size) variance in neural networks designed for image recognition.

    Thanks!


    <a rel='nofollow' class='comment-reply-link' href='#comment-549367' data-commentid="549367" data-postid="6939" data-belowelement="comment-549367" data-respondelement="respond" data-replyto="Reply to Mel" aria-label='Reply to Mel'>Reply</a>
  34. Munisha Bansal September 29, 2020 at 5:44 pm <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-565174" title="Direct link to this comment">#</a>

    Hi Jason,

    Thank you very much for the article. I wanted to understand the following scenario

    I have mix of categorical and numerical inputs. I can normalize/standardize the numerical inputs and the output numerical variable.
    But in the categorical variables I have high number of categories ~3000. So I use label encoder (not one hot coding) and then I use embedding layers. How can I achieve scaling in this case.


    <a rel='nofollow' class='comment-reply-link' href='#comment-565174' data-commentid="565174" data-postid="6939" data-belowelement="comment-565174" data-respondelement="respond" data-replyto="Reply to Munisha Bansal" aria-label='Reply to Munisha Bansal'>Reply</a>
  35. Hi Jason,

    I really enjoyed reading your article. My CNN regression network has binary image as input which the background is black, and foreground is white. The ground truth associated with each input is an image with color range from 0 to 255 which is normalized between 0 and 1.

    The network can almost detect edges and background but in foreground all the predicted values are almost same. Do you have any idea what is the solution?

    I appreciate in advance.


    <a rel='nofollow' class='comment-reply-link' href='#comment-569739' data-commentid="569739" data-postid="6939" data-belowelement="comment-569739" data-respondelement="respond" data-replyto="Reply to Hamed" aria-label='Reply to Hamed'>Reply</a>
  36. walid November 5, 2020 at 11:50 pm <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-573097" title="Direct link to this comment">#</a>

    Hi jason, how are you?

    i have data with input X (matrix with real values) and output y (matrix real values).
    i tried to normalize X and y :

    scaler1 = Normalizer()
    X = scaler1.fit_transform(X)
    scaler2 = Normalizer()
    y = scaler2.fit_transform(y)

    i get a good result with the transform normalizer as shown by: <a href="https://ibb.co/bQYCkvK" rel="nofollow ugc">https://ibb.co/bQYCkvK</a>

    at the end i tried to get the predicted values: yhat = model.predict(X_test)

    the problem here yhat is not the original data, it’s a transformed data and there is no inverse for normalizer.

    I tried to use the minmaxScalar an order to do the inverse operation (invyhat = scaler2.inverse_transform(yhat)) but i get a big numbers compared to the y_test values that i want.

    I tried to normalize just X, i get a worst result compared to the first one.

    could you please help me.

    example of X values : 1006.808362,13.335140,104.536458 …..
    289.197205,257.489613,106.245104,566.941857…..
    .

    example of y values: 0.50000, 250.0000
    0.879200,436.000000
    .
    .

    this is my code:

    X = dataset[:,0:20]
    y = dataset[:,20:22]

    scaler1 = Normalizer()
    X = scaler1.fit_transform(X)
    scaler2 = Normalizer()
    y = scaler2.fit_transform(y)

    X_train = X[90000:,:]
    X_test= X[:90000,:]
    y_train =y[90000:,:]
    y_test=y[:90000,:]

    print(X_train.shape, X_test.shape, y_train.shape, y_test.shape)

    1. define the keras model
    model = Sequential()
    1. input layer
    model.add(Dense(20, input_dim=20,activation=’relu’,kernel_initializer=’normal’))
    1. hidden layer
    model.add(Dense(7272,activation=’relu’,kernel_initializer=’normal’))
    model.add(Dropout(0.8))
    1. output layer
    model.add(Dense(2, activation=’linear’))
    opt =Adadelta(lr=0.01)
    1. compile the keras model
    model.compile(loss=’mean_squared_error’, optimizer=opt, metrics=[‘mse’])
    1. fit the keras model on the dataset
    history=model.fit(X_train, y_train, validation_data=(X_test, y_test),epochs=20,verbose=0)
    1. evaluate the model
    _, train_mse = model.evaluate(X_train, y_train, verbose=0)
    _, test_mse = model.evaluate(X_test, y_test, verbose=0)
    print(‘Train: %.3f, Test: %.3f’ % (train_mse, test_mse))
    yhat = model.predict(X_test)
    1. plot loss during training
    pyplot.title(‘Loss / Mean Squared Error’)
    pyplot.plot(history.history[‘loss’], label=’train’)
    pyplot.plot(history.history[‘val_loss’], label=’test’)
    pyplot.legend()
    pyplot.show()


    <a rel='nofollow' class='comment-reply-link' href='#comment-573097' data-commentid="573097" data-postid="6939" data-belowelement="comment-573097" data-respondelement="respond" data-replyto="Reply to walid" aria-label='Reply to walid'>Reply</a>
  37. Carlos November 17, 2020 at 9:18 am <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-575881" title="Direct link to this comment">#</a>

    Hi Jason, first thanks for the wonderful article. I have a little doubt. By normalizing my data and then dividing it into training and testing, all samples will be normalized. But in the case of a real application, where I have an input given by the user, do I need to put it together with all the data and normalize it so that it has the same pattern as the other data? What would be the best alternative?


    <a rel='nofollow' class='comment-reply-link' href='#comment-575881' data-commentid="575881" data-postid="6939" data-belowelement="comment-575881" data-respondelement="respond" data-replyto="Reply to Carlos" aria-label='Reply to Carlos'>Reply</a>
  38. <a href='http://www.iqvia.com' rel='external nofollow ugc' class='url'>Chris</a> December 3, 2020 at 2:41 am <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-580301" title="Direct link to this comment">#</a>

    Hi Jason, what is the best way to scale NANs when you need the model to generate them? I am creating a synthetic dataset where NANs are critical part. In one case we have people with no corresponding values for a field (truly missing) and in another case we have missing values but want to replicate the fact that values are missing. I tried filling the missing values with the negative sys.max value, but the model tends to spread values between the real data negative limit and the max limit, instead of treating the max value as an outlier. In another case, it seems to ignore that value and always generates values with the real data range, resulting in no generated NANs. I enjoyed your book and look forward to your response.


    <a rel='nofollow' class='comment-reply-link' href='#comment-580301' data-commentid="580301" data-postid="6939" data-belowelement="comment-580301" data-respondelement="respond" data-replyto="Reply to Chris" aria-label='Reply to Chris'>Reply</a>
  39. Luke Mao January 6, 2021 at 4:13 am <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-591809" title="Direct link to this comment">#</a>

    Thanks Jason for the blog post.
    One question:
    is it necessary to apply feature scaling for linear regression models as well as MLP’s?


    <a rel='nofollow' class='comment-reply-link' href='#comment-591809' data-commentid="591809" data-postid="6939" data-belowelement="comment-591809" data-respondelement="respond" data-replyto="Reply to Luke Mao" aria-label='Reply to Luke Mao'>Reply</a>
  40. Nisarg Patel January 25, 2021 at 1:23 pm <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-594313" title="Direct link to this comment">#</a>

    sir, i have a 1 problem

    When normalizing a dataset, the resulting data will have a minimum value of 0 and a
    maximum value of 1. However, the dataset we work with in data mining is typically a
    sample of a population. Therefore, the minimum and maximum for each of the attributes
    in the population are unknown.
    Samples from the population may be added to the dataset over time, and the attribute
    values for these new objects may then lie outside those you have seen so far. One
    possibility to handle new minimum and maximum values is to periodically renormalize
    the data after including the new values. Your task is to think of a normalization scheme
    that does not require you to renormalize all of the data. Your normalization approach has
    to fulfill all of the following requirements:
    – all values (old and new) have to lie in the range between 0 and 1
    – no transformation or renormalization of the old values is allowed
    Describe your normalization approach.


    <a rel='nofollow' class='comment-reply-link' href='#comment-594313' data-commentid="594313" data-postid="6939" data-belowelement="comment-594313" data-respondelement="respond" data-replyto="Reply to Nisarg Patel" aria-label='Reply to Nisarg Patel'>Reply</a>
  41. Hi Jason!
    Thank you so much for this great post 🙂

    I have one question I hope you could help with:
    Why do we need to conduct 30 model runs in particular? I do understand the idea, but i mean why 30 exactly?


    <a rel='nofollow' class='comment-reply-link' href='#comment-600398' data-commentid="600398" data-postid="6939" data-belowelement="comment-600398" data-respondelement="respond" data-replyto="Reply to J" aria-label='Reply to J'>Reply</a>
  42. Thanks Jason
    I have some confused questions
    If the scaling to input data done on the all data set or done to each sample of the data set seperately?

    the scalling is done after dividing data to training and test, yes?

    If I done normalizations manual to inputs and output, so I should save the max and min values to normalization inputs and denormalization outputs in future prediction?

    If I have the outputs containing two differerent range of variables , is same normalization is effective or I should do further things,for example two different normalization?

    Thanks in advance


    <a rel='nofollow' class='comment-reply-link' href='#comment-601009' data-commentid="601009" data-postid="6939" data-belowelement="comment-601009" data-respondelement="respond" data-replyto="Reply to Maha" aria-label='Reply to Maha'>Reply</a>
  43. If normalization and standarization is done of the whole data or each row of the samples , for example , in standardization , we got the mean of the whole data set and substract from each element in data set , or we treat each row in the data set separately and got its mean ,..?


    <a rel='nofollow' class='comment-reply-link' href='#comment-603221' data-commentid="603221" data-postid="6939" data-belowelement="comment-603221" data-respondelement="respond" data-replyto="Reply to Maha" aria-label='Reply to Maha'>Reply</a>
  44. Hi Jason,
    I have a question.. I hope you have time to answer it…

    If I scale/normalize the input data… The output label (calculated) will be generated “scalated/normalized” also..correct…
    and in order to calculate the output error the expected label should be scalated also..
    Correct??
    In other words.. I should scalate both..data and labels??


    <a rel='nofollow' class='comment-reply-link' href='#comment-607743' data-commentid="607743" data-postid="6939" data-belowelement="comment-607743" data-respondelement="respond" data-replyto="Reply to Carlos" aria-label='Reply to Carlos'>Reply</a>
  45. Hi Jason,

    I’m new to deep learning. I tried to implement a CNN regression model with multiple impute image chips of 31 channels(Raster image/TIFF format), and a numeric target variable. But the result I got is quite weird cos its giving me 100% accuracy (r2_score). I also noticed that during training, the loss/val loss output values were all zeros and the training was pretty fast considering feeding over 5000 images into the network. so I feel the network isn’t training anything passé.

    I want to ask if this could be as a result of data scaling? My image chips pixel values are in decimals (float) between 0 and 1 (all the image chips are less than 1), while my target variable are a continuous variable between 0 and 160 (integer).

    Do you think i need to perform some sort of normalization or standardization of my data?


    <a rel='nofollow' class='comment-reply-link' href='#comment-608235' data-commentid="608235" data-postid="6939" data-belowelement="comment-608235" data-respondelement="respond" data-replyto="Reply to Israel" aria-label='Reply to Israel'>Reply</a>
  46. <a href='https://acehl.org/' rel='external nofollow ugc' class='url'>JG</a> May 9, 2021 at 6:00 am <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-608515" title="Direct link to this comment">#</a>

    Hi Jason,

    Great Tutorial! Thank you very much.
    very clear explanation of scaling inputs and output necessity !

    I am introducing your tutorial to a friend of mine who is very interested in following you.

    regards


    <a rel='nofollow' class='comment-reply-link' href='#comment-608515' data-commentid="608515" data-postid="6939" data-belowelement="comment-608515" data-respondelement="respond" data-replyto="Reply to JG" aria-label='Reply to JG'>Reply</a>
  47. voloddia August 2, 2021 at 1:01 pm <a href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#comment-619500" title="Direct link to this comment">#</a>

    “You must ensure that the scale of your output variable matches the scale of the activation function (transfer function) on the output layer of your network.”

    I don’t understand this point.
    First, the output layer often has no activation function, or in other words, identity activation function which has arbitrary scale.
    Second, normalization and standardization are only linear transformations.
    Therefore, is it true that normalization/standardization of output is almost always unnecessary? If not, why?


    <a rel='nofollow' class='comment-reply-link' href='#comment-619500' data-commentid="619500" data-postid="6939" data-belowelement="comment-619500" data-respondelement="respond" data-replyto="Reply to voloddia" aria-label='Reply to voloddia'>Reply</a>

Leave a Reply <a rel="nofollow" id="cancel-comment-reply-link" href="/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/#respond" style="display:none;">Click here to cancel reply.</a>

<form action="https://machinelearningmastery.com/wp-comments-post.php?wpe-comment-post=mlmastery" method="post" id="commentform" class="comment-form">

<label class="hide" for="comment">Comment</label> <textarea tabindex="4" id="comment" name="comment" cols="50" rows="10" maxlength="65525" required="required"></textarea>

<input id="author" name="author" type="text" class="txt" tabindex="1" value="" size="30" aria-required='true' /><label for="author">Name (required)</label>

<input id="url" name="url" type="text" class="txt" tabindex="3" value="" size="30" /><label for="url">Website</label>

<input name="submit" type="submit" id="submit" class="submit" value="Submit Comment" /> <input type='hidden' name='comment_post_ID' value='6939' id='comment_post_ID' /> <input type='hidden' name='comment_parent' id='comment_parent' value='0' />

<input type="hidden" id="akismet_comment_nonce" name="akismet_comment_nonce" value="2ca2f8d589" />

<input type="hidden" id="ak_js" name="ak_js" value="32"/><textarea name="ak_hp_textarea" cols="45" rows="8" maxlength="100" style="display: none !important;"></textarea></form>
           </section>
               
           <aside id="sidebar">
<img alt= src='https://secure.gravatar.com/avatar/1d75d46040c28497f0dee5d8e100db37?s=88&d=mm&r=g' srcset='https://secure.gravatar.com/avatar/1d75d46040c28497f0dee5d8e100db37?s=176&d=mm&r=g 2x' class='avatar avatar-88 photo' height='88' width='88' loading='lazy'/>

Welcome!
I'm Jason Brownlee PhD
and I help developers get results with machine learning.
<a href="/about">Read more</a>

Never miss a tutorial:


<a href="https://www.linkedin.com/company/machine-learning-mastery/"><img width="30" height="30" src="/wp-content/uploads/2019/12/small_icon_blue_linkedin3.png" alt="LinkedIn"></a>     <a href="https://twitter.com/TeachTheMachine"><img width="30" height="30" src="/wp-content/uploads/2019/12/small_icon_blue_twitter3.png" alt="Twitter"></a>     <a href="https://www.facebook.com/MachineLearningMastery/"><img width="30" height="30" src="/wp-content/uploads/2019/12/small_icon_blue_facebook3.png" alt="Facebook"></a>     <a href="/newsletter/"><img width="30" height="30" src="/wp-content/uploads/2019/12/small_icon_blue_email3.png" alt="Email Newsletter"></a>     <a href="https://machinelearningmastery.com/rss-feed/"><img width="30" height="30" src="/wp-content/uploads/2019/12/small_icon_blue_rss3.png" alt="RSS Feed"></a>

Picked for you:


<a class="image" href="https://machinelearningmastery.com/learning-curves-for-diagnosing-machine-learning-model-performance/"><img width="150" height="150" src="https://machinelearningmastery.com/wp-content/uploads/2018/12/Example-of-Train-and-Validation-Learning-Curves-Showing-a-Training-Dataset-the-May-be-too-Small-Relative-to-the-Validation-Dataset-150x150.png" class="attachment-thumbnail size-thumbnail wp-post-image" alt="Example of Train and Validation Learning Curves Showing a Training Dataset That May Be too Small Relative to the Validation Dataset" loading="lazy" /></a> <a class="title" href="https://machinelearningmastery.com/learning-curves-for-diagnosing-machine-learning-model-performance/" rel="nofollow">How to use Learning Curves to Diagnose Machine Learning Model Performance</a>
<a class="image" href="https://machinelearningmastery.com/stacking-ensemble-for-deep-learning-neural-networks/"><img width="150" height="150" src="https://machinelearningmastery.com/wp-content/uploads/2018/10/Visualization-of-Stacked-Generalization-Ensemble-of-Neural-Network-Models-150x150.png" class="attachment-thumbnail size-thumbnail wp-post-image" alt="Visualization of Stacked Generalization Ensemble of Neural Network Models" loading="lazy" /></a> <a class="title" href="https://machinelearningmastery.com/stacking-ensemble-for-deep-learning-neural-networks/" rel="nofollow">Stacking Ensemble for Deep Learning Neural Networks in Python</a>
<a class="image" href="https://machinelearningmastery.com/improve-deep-learning-performance/"><img width="150" height="150" src="https://machinelearningmastery.com/wp-content/uploads/2016/09/How-To-Improve-Deep-Learning-Performance-150x150.jpg" class="attachment-thumbnail size-thumbnail wp-post-image" alt="How To Improve Deep Learning Performance" loading="lazy" /></a> <a class="title" href="https://machinelearningmastery.com/improve-deep-learning-performance/" rel="nofollow">How To Improve Deep Learning Performance</a>
<a class="image" href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/"><img width="150" height="150" src="https://machinelearningmastery.com/wp-content/uploads/2018/11/Box-and-Whisker-Plots-of-Mean-Squared-Error-With-Unscaled-Normalized-and-Standardized-Input-Variables-for-the-Regression-Problem-150x150.png" class="attachment-thumbnail size-thumbnail wp-post-image" alt="Box and Whisker Plots of Mean Squared Error With Unscaled, Normalized and Standardized Input Variables for the Regression Problem" loading="lazy" /></a> <a class="title" href="https://machinelearningmastery.com/how-to-improve-neural-network-stability-and-modeling-performance-with-data-scaling/" rel="nofollow">How to use Data Scaling Improve Deep Learning Model Stability and Performance</a>
<a class="image" href="https://machinelearningmastery.com/adam-optimization-algorithm-for-deep-learning/"><img width="150" height="150" src="https://machinelearningmastery.com/wp-content/uploads/2017/05/Comparison-of-Adam-to-Other-Optimization-Algorithms-Training-a-Multilayer-Perceptron-150x150.png" class="attachment-thumbnail size-thumbnail wp-post-image" alt="Comparison of Adam to Other Optimization Algorithms Training a Multilayer Perceptron" loading="lazy" /></a> <a class="title" href="https://machinelearningmastery.com/adam-optimization-algorithm-for-deep-learning/" rel="nofollow">Gentle Introduction to the Adam Optimization Algorithm for Deep Learning</a>

Loving the Tutorials?

The <a href="/better-deep-learning/" rel="nofollow">Better Deep Learning</a> EBook is
where you'll find the Really Good stuff.

<a href="/better-deep-learning/" class="woo-sc-button red" >>> See What's Inside</a>

</aside>


<footer id="footer" class="col-full">


<a href="/privacy/">Privacy</a> | <a href="/disclaimer/">Disclaimer</a> | <a href="/terms-of-service/">Terms</a> | <a href="/contact/">Contact</a> | <a href="/sitemap/">Sitemap</a> | <a href="/site-search/">Search</a>

</footer>


<script data-cfasync="false" type="text/javascript">

 var _dcq = _dcq || [];
 var _dcs = _dcs || {};
 _dcs.account = '9556588';
 (function() {
   var dc = document.createElement('script');
   dc.type = 'text/javascript'; dc.async = true;
   dc.src = '//tag.getdrip.com/9556588.js';
   var s = document.getElementsByTagName('script')[0];
   s.parentNode.insertBefore(dc, s);
 })();

</script>

<script type="f3886dae12b0536ad361ea93-text/javascript" id='rocket-browser-checker-js-after'> "use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){return protoProps&&defineProperties(Constructor.prototype,protoProps),staticProps&&defineProperties(Constructor,staticProps),Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}var RocketBrowserCompatibilityChecker=function(){function RocketBrowserCompatibilityChecker(options){_classCallCheck(this,RocketBrowserCompatibilityChecker),this.passiveSupported=!1,this._checkPassiveOption(this),this.options=!!this.passiveSupported&&options}return _createClass(RocketBrowserCompatibilityChecker,[{key:"_checkPassiveOption",value:function(self){try{var options={get passive(){return!(self.passiveSupported=!0)}};window.addEventListener("test",null,options),window.removeEventListener("test",null,options)}catch(err){self.passiveSupported=!1}}},{key:"initRequestIdleCallback",value:function(){!1 in window&&(window.requestIdleCallback=function(cb){var start=Date.now();return setTimeout(function(){cb({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-start))}})},1)}),!1 in window&&(window.cancelIdleCallback=function(id){return clearTimeout(id)})}},{key:"isDataSaverModeOn",value:function(){return"connection"in navigator&&!0===navigator.connection.saveData}},{key:"supportsLinkPrefetch",value:function(){var elem=document.createElement("link");return elem.relList&&elem.relList.supports&&elem.relList.supports("prefetch")&&window.IntersectionObserver&&"isIntersecting"in IntersectionObserverEntry.prototype}},{key:"isSlowConnection",value:function(){return"connection"in navigator&&"effectiveType"in navigator.connection&&("2g"===navigator.connection.effectiveType||"slow-2g"===navigator.connection.effectiveType)}}]),RocketBrowserCompatibilityChecker}(); </script> <script type="f3886dae12b0536ad361ea93-text/javascript" id='rocket-delay-js-js-after'> (function() { "use strict";var e=function(){function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}}();function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=function(){function r(e,t){n(this,r),this.attrName="data-rocketlazyloadscript",this.browser=t,this.options=this.browser.options,this.triggerEvents=e,this.userEventListener=this.triggerListener.bind(this)}return e(r,[{key:"init",value:function(){this._addEventListener(this)}},{key:"reset",value:function(){this._removeEventListener(this)}},{key:"_addEventListener",value:function(t){this.triggerEvents.forEach(function(e){return window.addEventListener(e,t.userEventListener,t.options)})}},{key:"_removeEventListener",value:function(t){this.triggerEvents.forEach(function(e){return window.removeEventListener(e,t.userEventListener,t.options)})}},{key:"_loadScriptSrc",value:function(){var r=this,e=document.querySelectorAll("script["+this.attrName+"]");0!==e.length&&Array.prototype.slice.call(e).forEach(function(e){var t=e.getAttribute(r.attrName);e.setAttribute("src",t),e.removeAttribute(r.attrName)}),this.reset()}},{key:"triggerListener",value:function(){this._loadScriptSrc(),this._removeEventListener(this)}}],[{key:"run",value:function(){RocketBrowserCompatibilityChecker&&new r(["keydown","mouseover","touchmove","touchstart","wheel"],new RocketBrowserCompatibilityChecker({passive:!0})).init()}}]),r}();t.run(); }()); </script> <script type="f3886dae12b0536ad361ea93-text/javascript" id='rocket-preload-links-js-extra'> /* <![CDATA[ */ var RocketPreloadLinksConfig = {"excludeUris":"\/register\/machine-learning-university\/|\/courses\/\/lessons\/holding-back-goals\/|\/courses\/course-get-started\/|\/courses\/course-get-started\/lessons\/holding-back-goals\/|\/courses\/course-get-started\/lessons\/why-machine-learning-does-not-have-to-be-so-hard\/|\/courses\/course-get-started\/lessons\/how-to-think-about-machine-learning\/|\/courses\/course-get-started\/lessons\/find-your-machine-learning-tribe\/|\/courses\/step-by-step-process\/|\/courses\/probability-for-machine-learning\/|\/account\/|\/register\/|\/courses\/|\/machine-learning-mastery-university-registration\/|\/register\/|\/newsletter\/|\/(.+\/)?feed\/?.+\/?|\/(?:.+\/)?embed\/|\/(index\\.php\/)?wp\\-json(\/.*|$)|\/wp-admin\/|\/logout\/|\/login\/","usesTrailingSlash":"1","imageExt":"jpg|jpeg|gif|png|tiff|bmp|webp|avif","fileExt":"jpg|jpeg|gif|png|tiff|bmp|webp|avif|php|pdf|html|htm","siteUrl":"https:\/\/machinelearningmastery.com","onHoverDelay":"100","rateThrottle":"3"}; /* ]]> */ </script> <script type="f3886dae12b0536ad361ea93-text/javascript" id='rocket-preload-links-js-after'> (function() { "use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e=function(){function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}}();function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=function(){function n(e,t){i(this,n),this.browser=e,this.config=t,this.options=this.browser.options,this.prefetched=new Set,this.eventTime=null,this.threshold=1111,this.numOnHover=0}return e(n,[{key:"init",value:function(){!this.browser.supportsLinkPrefetch()||this.browser.isDataSaverModeOn()||this.browser.isSlowConnection()||(this.regex={excludeUris:RegExp(this.config.excludeUris,"i"),images:RegExp(".("+this.config.imageExt+")$","i"),fileExt:RegExp(".("+this.config.fileExt+")$","i")},this._initListeners(this))}},{key:"_initListeners",value:function(e){-1<this.config.onHoverDelay&&document.addEventListener("mouseover",e.listener.bind(e),e.listenerOptions),document.addEventListener("mousedown",e.listener.bind(e),e.listenerOptions),document.addEventListener("touchstart",e.listener.bind(e),e.listenerOptions)}},{key:"listener",value:function(e){var t=e.target.closest("a"),n=this._prepareUrl(t);if(null!==n)switch(e.type){case"mousedown":case"touchstart":this._addPrefetchLink(n);break;case"mouseover":this._earlyPrefetch(t,n,"mouseout")}}},{key:"_earlyPrefetch",value:function(t,e,n){var i=this,r=setTimeout(function(){if(r=null,0===i.numOnHover)setTimeout(function(){return i.numOnHover=0},1e3);else if(i.numOnHover>i.config.rateThrottle)return;i.numOnHover++,i._addPrefetchLink(e)},this.config.onHoverDelay);t.addEventListener(n,function e(){t.removeEventListener(n,e,{passive:!0}),null!==r&&(clearTimeout(r),r=null)},{passive:!0})}},{key:"_addPrefetchLink",value:function(i){return this.prefetched.add(i.href),new Promise(function(e,t){var n=document.createElement("link");n.rel="prefetch",n.href=i.href,n.onload=e,n.onerror=t,document.head.appendChild(n)}).catch(function(){})}},{key:"_prepareUrl",value:function(e){if(null===e||"object"!==(void 0===e?"undefined":r(e))||!1 in e||-1===["http:","https:"].indexOf(e.protocol))return null;var t=e.href.substring(0,this.config.siteUrl.length),n=this._getPathname(e.href,t),i={original:e.href,protocol:e.protocol,origin:t,pathname:n,href:t+n};return this._isLinkOk(i)?i:null}},{key:"_getPathname",value:function(e,t){var n=t?e.substring(this.config.siteUrl.length):e;return n.startsWith("/")||(n="/"+n),this._shouldAddTrailingSlash(n)?n+"/":n}},{key:"_shouldAddTrailingSlash",value:function(e){return this.config.usesTrailingSlash&&!e.endsWith("/")&&!this.regex.fileExt.test(e)}},{key:"_isLinkOk",value:function(e){return null!==e&&"object"===(void 0===e?"undefined":r(e))&&(!this.prefetched.has(e.href)&&e.origin===this.config.siteUrl&&-1===e.href.indexOf("?")&&-1===e.href.indexOf("#")&&!this.regex.excludeUris.test(e.href)&&!this.regex.images.test(e.href))}}],[{key:"run",value:function(){"undefined"!=typeof RocketPreloadLinksConfig&&new n(new RocketBrowserCompatibilityChecker({capture:!0,passive:!0}),RocketPreloadLinksConfig).init()}}]),n}();t.run(); }()); </script>


<script type="f3886dae12b0536ad361ea93-text/javascript">window.lazyLoadOptions={elements_selector:"iframe[data-lazy-src]",data_src:"lazy-src",data_srcset:"lazy-srcset",data_sizes:"lazy-sizes",class_loading:"lazyloading",class_loaded:"lazyloaded",threshold:300,callback_loaded:function(element){if(element.tagName==="IFRAME"&&element.dataset.rocketLazyload=="fitvidscompatible"){if(element.classList.contains("lazyloaded")){if(typeof window.jQuery!="undefined"){if(jQuery.fn.fitVids){jQuery(element).parent().fitVids()}}}}}};window.addEventListener('LazyLoad::Initialized',function(e){var lazyLoadInstance=e.detail.instance;if(window.MutationObserver){var observer=new MutationObserver(function(mutations){var image_count=0;var iframe_count=0;var rocketlazy_count=0;mutations.forEach(function(mutation){for(i=0;i<mutation.addedNodes.length;i++){if(typeof mutation.addedNodes[i].getElementsByTagName!=='function'){continue} if(typeof mutation.addedNodes[i].getElementsByClassName!=='function'){continue} images=mutation.addedNodes[i].getElementsByTagName('img');is_image=mutation.addedNodes[i].tagName=="IMG";iframes=mutation.addedNodes[i].getElementsByTagName('iframe');is_iframe=mutation.addedNodes[i].tagName=="IFRAME";rocket_lazy=mutation.addedNodes[i].getElementsByClassName('rocket-lazyload');image_count+=images.length;iframe_count+=iframes.length;rocketlazy_count+=rocket_lazy.length;if(is_image){image_count+=1} if(is_iframe){iframe_count+=1}}});if(image_count>0||iframe_count>0||rocketlazy_count>0){lazyLoadInstance.update()}});var b=document.getElementsByTagName("body")[0];var config={childList:!0,subtree:!0};observer.observe(b,config)}},!1)</script><script data-no-minify="1" async src="https://machinelearningmastery.com/wp-content/plugins/wp-rocket/assets/js/lazyload/16.1/lazyload.min.js" type="f3886dae12b0536ad361ea93-text/javascript"></script><script src="https://machinelearningmastery.com/wp-content/cache/min/1/faa2bb2b045a56fea4ed2ea21d2cc719.js" data-minify="1" defer type="f3886dae12b0536ad361ea93-text/javascript"></script><script src="/cdn-cgi/scripts/7d0fa10a/cloudflare-static/rocket-loader.min.js" data-cf-settings="f3886dae12b0536ad361ea93-|49" defer=""></script></body> </html>