5 WAYS TO HANDLE MISSING VALUES IN PYTHON (2024)

5 WAYS TO HANDLE MISSING VALUES IN PYTHON (3)

NAN NAN NAN NAN NAN NAN NAN

….Ok you are stuck now😢

How do I handle this columns with missing values?

In this post I will be sharing with you 5 proven ways you can apply to handle columns with missing values in your dataset.

Lets dive in!!

What are the causes of missing values: Missing values occur as a result of incomplete extraction, lack of information, corrupt data, incomplete data from engineers or due to confidentiality of some data. Let’s look at different ways of imputing missing values.

To understand better we will be using titanic data set and some python libraries like pandas, numpy and Scikit learn

5 WAYS TO HANDLE MISSING VALUES IN PYTHON (4)
5 WAYS TO HANDLE MISSING VALUES IN PYTHON (5)
  1. Deleting Rows or Columns:

In this method, we delete rows and columns that have missing values. This method is commonly used in Data science but should only be used when you have rows and columns with more than 50% of missing values and when they are enough sample in the dataset. Though it is not always advisable to delete columns with missing values because sometimes it may lead to loss of information or data.

5 WAYS TO HANDLE MISSING VALUES IN PYTHON (6)

2. Replacing with Mean/Mode/Median:

This measures of Central Tendency can save your life 😍 😊…

This method is applied on columns that have numerical values but mode can work on columns with categorical values as well. We can calculate the mean, median or mode of the feature and replace it with the missing values(don’t worry pandas can handle that)

This way, you’re not dropping these columns from the dataset, and you’re also not skewing the salary values.

While not perfect, this method allows you to introduce values that don’t impact the overall dataset, since no matter how many averages you add, the average stays the same.

5 WAYS TO HANDLE MISSING VALUES IN PYTHON (7)
5 WAYS TO HANDLE MISSING VALUES IN PYTHON (8)

3. Filling missing value with a Constant:

You could also decide to fill the NA-marked values with a constant value. For example, you can put in a special string or numerical value

5 WAYS TO HANDLE MISSING VALUES IN PYTHON (9)
5 WAYS TO HANDLE MISSING VALUES IN PYTHON (10)

4. Predicting the missing values:

Using the features which do not have missing values, we can predict the nulls with the help of a machine learning algorithm. This method may result in better accuracy, unless a missing value is expected to have a very high variance. We will be using linear regression to replace the nulls in the feature ‘age’, using other available features. One can experiment with different algorithms and check which gives the best accuracy instead of sticking to a single algorithm.

5 WAYS TO HANDLE MISSING VALUES IN PYTHON (11)

5. Using Algorithms which support missing values:

They are many machine learning models that can work with missing values effectively without need to remove the missing values.

  1. KNN: KNN is a machine learning algorithm which works on the principle of distance measure. This algorithm can be used when there are nulls present in the dataset. While the algorithm is applied, KNN considers the missing values by taking the majority of the K nearest values. In this particular dataset, taking into account the person’s age, sex, class etc, we will assume that people having same data for the above mentioned features will have the same kind of fare. You can take a look at the KNN DOCUMENTATION
  2. Random Forest Model: This model produces a robust result because it works well on non-linear and the categorical data. It adapts to the data structure taking into consideration of the high variance or the bias, producing better results on large datasets. You can take a look at the RANDOM FOREST DOCUMENTATION
  3. LIGHTGBM: lightGBM will ignore missing values during a split, then allocate them to whichever side reduces the loss the most. You can take a look at the LIGHTGBM DOCUMENTATION

Handling missng variables while working on datasets can really help in improving your model performance and most importantly help you in getting the best of your dataset.

I hope this solves your problem? 😍 😊…

5 WAYS TO HANDLE MISSING VALUES IN PYTHON (2024)
Top Articles
Updated Drone Assist app to propel responsible flying - NATS
What Does A Blog Post Actually Cost? - okwrite
Katie Pavlich Bikini Photos
Gamevault Agent
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
Things To Do In Atlanta Tomorrow Night
Non Sequitur
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Rogold Extension
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Weekly Math Review Q4 3
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Free Carnival-themed Google Slides & PowerPoint templates
Otter Bustr
Selly Medaline
Latest Posts
Article information

Author: Kelle Weber

Last Updated:

Views: 6233

Rating: 4.2 / 5 (53 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Kelle Weber

Birthday: 2000-08-05

Address: 6796 Juan Square, Markfort, MN 58988

Phone: +8215934114615

Job: Hospitality Director

Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.