Skip to content

Instantly share code, notes, and snippets.

@YohanObadia
YohanObadia / knn_impute_example.py
Created February 4, 2017 13:00
Example of use for the knn_impute function
knn_impute(target=df['Age'], attributes=df.drop(['Age', 'PassengerId'], 1),
aggregation_method="median", k_neighbors=10, numeric_distance='euclidean',
categorical_distance='hamming', missing_neighbors_threshold=0.8)
@YohanObadia
YohanObadia / knn_impute_example.py
Created February 4, 2017 13:00
Example of use for the knn_impute function
knn_impute(target=df['Age'], attributes=df.drop(['Age', 'PassengerId'], 1),
aggregation_method="median", k_neighbors=10, numeric_distance='euclidean',
categorical_distance='hamming', missing_neighbors_threshold=0.8)
@YohanObadia
YohanObadia / knn_impute.py
Last active January 25, 2024 14:23
Imputation of missing values with knn.
import numpy as np
import pandas as pd
from collections import defaultdict
from scipy.stats import hmean
from scipy.spatial.distance import cdist
from scipy import stats
import numbers
def weighted_hamming(data):