<jupyter_start><jupyter_text>There are 3 major approaches to fixing missing values1) Drop Columns with missing values (not the best approach in practice)2) Imputation - Fill missing values with some number like the mean or median of the column3) Extension to Imputation - Add column with Was_Missing and set it to True after imputing for missing ,false for non-missing<jupyter_code>import pandas as pd
from sklearn.model_selection import train_test_split

# Load the data
data = pd.read_csv('Melbourne_housing_FULL.csv')

# Select target
y = data.Price

# To keep things simple, we'll use only numerical predictors
melb_predictors = data.drop(['Price'], axis=1)
X = melb_predictors.select_dtypes(exclude=['object'])

# Divide data into training and validation subsets
X_train, X_valid, y_train, y_valid = train_test_split(X, y, train_size=0.8, test_size=0.2, random_state =0)<jupyter_output><empty_output><jupyter_text>Now lets define a function to compare the different approaches<jupyter_code>from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_absolute_error

# Function for comparing different approaches
def score_dataset(X_train, X_valid, y_train, y_valid):
    model = RandomForestRegressor(n_estimators=10, random_state=0)
    model.fit(X_train, y_train)
    preds = model.predict(X_valid)
    return mean_absolute_error(y_valid, preds)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0732574679943101, 'fraction_numerical': 0.009246088193456615, 'mean_word_length': 6.524064171122995, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '266366', 'license': 'MIT', 'n_tokens_mistral': 445, 'n_tokens_neox': 430, 'n_words': 137, 'path': 'Fixing Missing Values.ipynb', 'repo_name': 'SakibShahriar95/Machine_Learning_Python', 'size': '1406'}