text_plain_output_1.png
from sklearn.impute import KNNImputer

from sklearn.impute import SimpleImputer

import pandas as pd

train = pd.read_csv('/kaggle/input/e-commerce-shoppers-behaviour-understanding/train_data_v2.csv')
test = pd.read_csv('/kaggle/input/e-commerce-shoppers-behaviour-understanding/test_data_v2.csv')

train.shape

train.columns

train.isna().sum()

var = train.corr()

target = train['Made_Purchase']
features = train.drop('Made_Purchase', axis=1)

col_float = []
col_str = []
for i in features.columns:
    if features[i].dtype == 'float64':
        col_float.append(i)
    else:
        col_str.append(i)

from sklearn.impute import SimpleImputer
si = SimpleImputer(strategy='most_frequent')
features[col_str] = si.fit_transform(features[col_str])
features.isna().sum()

from sklearn.impute import KNNImputer
knn = KNNImputer(n_neighbors=7, weights='distance')
features[col_float] = knn.fit_transform(features[col_float])
features.isna().sum()