{"id":498,"date":"2020-10-31T18:54:42","date_gmt":"2020-10-31T17:54:42","guid":{"rendered":"http:\/\/www.labo.mathieurella.fr\/?p=498"},"modified":"2022-06-26T15:40:26","modified_gmt":"2022-06-26T13:40:26","slug":"working-with-missing-values","status":"publish","type":"post","link":"https:\/\/www.labo.mathieurella.fr\/?p=498","title":{"rendered":"Working with Missing Values"},"content":{"rendered":"\n<p>Data cleansing accounts for 80% of the work of scientists, and in my experience, that&#8217;s true.<\/p>\n\n\n\n<p>Although I always recommend cleaning these missing valuers, sometimes it is not necessary, however there is a case where it is essential :<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong>During the Creation of Statistical Models<\/strong><\/p>\n\n\n\n<p>And guess what, there&#8217;s not only one way around it. So here are 3 ways to work with missing values.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">I.  Remove Missing Values<\/h4>\n\n\n\n<p>The first of these methods is to remove rows or column holding those missing values.<\/p>\n\n\n\n<p>First, you&#8217;ll have to ask yourself why those value are missing ?<\/p>\n\n\n\n<p>Because most of the time dropping data from your dataset will lead to bias model (it&#8217;s also true with imputing data points) .<\/p>\n\n\n\n<p>There isn&#8217;t a best universal way to work with missing data, that&#8217;s why you&#8217;ll have to explore different option to help you determine what best for your situation.<\/p>\n\n\n\n<p>For Instance, missing data can sometimes help you obtain better forecasts, Let&#8217;s imagine a survey of individuals, removing the missing data could bias the results of our model. We could use this missing information to enrich our perception and moreover our model.<\/p>\n\n\n\n<p>For Data entry errors, mechanical errors or because missing data isn&#8217;t useful for our question of interest are acceptables cases for dropping our missing values.<\/p>\n\n\n\n<p>A. Drop any row with a missing value.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df.dropna()<\/code><\/pre>\n\n\n\n<p>B. &nbsp;Drop only the row with all missing values.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df.dropna(how=\"all\")<\/code><\/pre>\n\n\n\n<p>C. &nbsp;&nbsp;Drop only the rows with missing values in column 3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df.dropna(how='any', subset=&#91;'col3'])<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">II. Imputing Values<\/h4>\n\n\n\n<p>Imputing values into a dataset is certainly the most common ways professionnal work with missing data. <\/p>\n\n\n\n<p>You commonly fill the missing value by the mean, the median or the mode.<\/p>\n\n\n\n<p>The pros is that you are not directly removing rows or columns associated with missing.<\/p>\n\n\n\n<p><strong>The cons is that you are diluting the power of your features to predict well by reducing variability in those features<\/strong><\/p>\n\n\n\n<p>By removing or imputing missing value we should be very cautious about the impact this will have in our model.<\/p>\n\n\n\n<p>It is very common to impute in the following ways:<\/p>\n\n\n\n<ol><li>Impute the <strong>mean<\/strong> of a column.<br><\/li><li>If you are working with categorical data or a variable with outliers, then use the <strong>mode<\/strong> of the column.<br><\/li><li>Impute 0, a very small number, or a very large number to differentiate missing values from other values.<br><\/li><li>Use knn to impute values based on features that are most similar.<\/li><\/ol>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Data cleansing accounts for 80% of the work of scientists, and in my experience, that&#8217;s true. Although I always recommend &#8230;<\/p>\n","protected":false},"author":1,"featured_media":552,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/www.labo.mathieurella.fr\/index.php?rest_route=\/wp\/v2\/posts\/498"}],"collection":[{"href":"https:\/\/www.labo.mathieurella.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.labo.mathieurella.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.labo.mathieurella.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.labo.mathieurella.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=498"}],"version-history":[{"count":6,"href":"https:\/\/www.labo.mathieurella.fr\/index.php?rest_route=\/wp\/v2\/posts\/498\/revisions"}],"predecessor-version":[{"id":504,"href":"https:\/\/www.labo.mathieurella.fr\/index.php?rest_route=\/wp\/v2\/posts\/498\/revisions\/504"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.labo.mathieurella.fr\/index.php?rest_route=\/wp\/v2\/media\/552"}],"wp:attachment":[{"href":"https:\/\/www.labo.mathieurella.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.labo.mathieurella.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.labo.mathieurella.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}