{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[![Open in Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/justmarkham/scikit-learn-tips/master?filepath=notebooks%2F09_add_missing_indicator.ipynb)\n", "\n", "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/justmarkham/scikit-learn-tips/blob/master/notebooks/09_add_missing_indicator.ipynb)\n", "\n", "# 🤖⚡ scikit-learn tip #9 ([video](https://www.youtube.com/watch?v=DKmDJJzayZw&list=PL5-da3qGB5ID7YYAqireYEew2mWVvgmj6&index=9))\n", "\n", "When imputing missing values, you can preserve info about which values were missing and use THAT as a feature!\n", "\n", "Why? Sometimes there's a relationship between \"missingness\" and the target/label you are trying to predict.\n", "\n", "See example 👇" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "X = pd.DataFrame({'Age':[20, 30, 10, np.nan, 10]})" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Age | \n", "
---|---|
0 | \n", "20.0 | \n", "
1 | \n", "30.0 | \n", "
2 | \n", "10.0 | \n", "
3 | \n", "NaN | \n", "
4 | \n", "10.0 | \n", "