"""Utils used in the preprocessing stage"""

import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler


def one_hot_encoding(data, categorical_features):
    """Encode a list of categorical features using a one-hot scheme.

    Parameters
    ----------
    data :
    categorical_features :

    Returns
    -------
    data : DataFrame
        Returns a pandas DataFrame with new binary columns.
    """
    for feature in categorical_features:
        data_dummy = pd.get_dummies(data[feature], prefix=feature)
        data = data.drop([feature], axis=1)
        data = pd.concat((data, data_dummy), axis=1)

    return data


def input_missing_values(data, column, model, scale=True):
    """Input missing values into the DataFrame using SVM.

    Parameters
    ----------
    data :
    column :

    Returns
    -------
    data : DataFrame
        Returns a pandas DataFrame with the feature column filled with
        predictions.
    """
    df = data
    null_values = df[column].isnull()

    if scale:
        X = df.columns.tolist()
        X.remove(column)

        df[X] = StandardScaler().fit_transform(df[X])

    model.fit(
        df[~null_values].drop(column, axis=1),
        df[~null_values][column]
    )

    predicted_values = model.predict(df[null_values].drop(column, axis=1))

    data.loc[null_values, column] = np.around(predicted_values)

    return data

@@ -49,88 +49,20 @@
 ort 
-numpy as np%0Aimport pandas as pd%0Afrom sklearn.preprocessing import StandardScaler
+pandas as pd
 %0A%0A%0Ad
@@ -224,168 +224,58 @@
 ta :
-%0A    categorical_features :%0A%0A    Returns%0A    -------%0A    data : DataFrame%0A        Returns a pandas DataFrame with new binary columns.%0A    %22%22%22%0A    for feature in
+ Pandas DataFrame%0A        DataFrame containing the
  cat
@@ -282,25 +282,25 @@
 egorical
-_
+ 
 features
 :%0A      
@@ -295,931 +295,428 @@
 ures
-:%0A 
+.%0A
     
-   data_dummy = pd.get_dummies(data%5Bfeature%5D, prefix=feature)%0A        data = data.drop(%5Bfeature%5D, axis=1)%0A        data = pd.concat((data, data_dummy), axis=1)%0A%0A    return data%0A%0A%0Adef input_missing_values(data, column, model, scale=True):%0A    %22%22%22Input missing values into the DataFrame using SVM.%0A%0A    Parameters%0A    ----------%0A    data :%0A    column :%0A%0A    Returns%0A    -------%0A    data : DataFrame%0A        Returns a pandas DataFrame with the feature column filled with%0A        predictions.%0A    %22%22%22%0A    df = data%0A    null_values = df%5Bcolumn%5D.isnull()%0A%0A    if scale:%0A        X = df.columns.tolist()%0A        X.remove(column)%0A%0A        df%5BX%5D = StandardScaler().fit_transform(df%5BX%5D)%0A%0A    model.fit(%0A        df%5B~null_values%5D.drop(column, axis=1),%0A        df%5B~null_values%5D%5Bcolumn%5D
+categorical_features : list%0A        Names of the categorial features to encode%0A%0A    Returns%0A    -------%0A    data : DataFrame%0A        Returns a pandas DataFrame with one-hot scheme binary columns.%0A    %22%22%22%0A    for feature in categorical_features:%0A        data_dummy = pd.get_dummies(data%5Bfeature%5D, prefix=feature)%0A        data.drop(%5Bfeature%5D, axis=1, inplace=True)
 %0A    
-)%0A%0A
     
-predicted_values = model.predict(df%5Bnull_values%5D.drop(column, axis=1))%0A%0A    data.loc%5Bnull_values, column%5D = np.around(predicted_values
+data = pd.concat((data, data_dummy), axis=1
 )%0A%0A 

Clean file