4.6 KiB
4.6 KiB
In [3]:
## import libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
## load data
datapath = '../3_data'
from os import chdir; chdir(datapath)
data = pd.read_csv('bank_data_prep.csv')
#data.shape ## check
## features - target - split
X = data.drop('y', axis=1)
y = data['y']
## test - train - split
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test, = train_test_split(X,
y,
train_size=2 / 3,
random_state=1234)In [5]:
## standardiz features (lead: train data)
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler().fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)In [6]:
## Tune über n_neighbors
from sklearn.neighbors import KNeighborsClassifier
model = KNeighborsClassifier()
params = range(1, 11)
scores = [] ## scores ohne Standardisieren
scores_sc = [] ## scores mit Standardisieren
for param in params:
print(param)
## tbd
1 2 3 4 5 6 7 8 9 10
In [7]:
## Tune über p
params = range(1, 4) ## dasselbe wie [1, 2, 3]
## tbd