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
View knn_impute_example.py
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
View knn_impute_example.py
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 May 28, 2023 23:38
Imputation of missing values with knn.
View knn_impute.py
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):