text_html_output_1.png
from sklearn.neighbors import KNeighborsClassifier

from sklearn.preprocessing import StandardScaler

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

train = pd.read_csv('/kaggle/input/ods-mlclass-dubai-2019-03-lecture3-hw/train.csv')
test = pd.read_csv('/kaggle/input/ods-mlclass-dubai-2019-03-lecture3-hw/test.csv')

test['target'] = np.nan
df = pd.concat([train, test])

df.dtypes

df = df.select_dtypes(exclude=['object'])
df

zero_not_accepted = ['age', 'fnlwgt', 'education-num', 'capital-gain', 'capital-loss', 'hours-per-week']
for columns in zero_not_accepted:
    df[columns] = df[columns].replace(0, np.NaN)
    mean = int(df[columns].mean(skipna=True))
    df[columns] = df[columns].replace(np.NaN, mean)

sc_X = StandardScaler()
X_train = sc_X.fit_transform(X_train)
X_test = sc_X.fit_transform(X_test)

y_train.notna()

classifier = KNeighborsClassifier(n_neighbors=97, p=2, metric='euclidean')
classifier.fit(X_train.loc[X_train['target'].notna()][zero_not_accepted], y_train[y_train.notna()])