"""
# KNN Algorithm

The K-NN (K-Nearest Neighbor) algorithm is one of the simplest and most widely used classification algorithms. K-NN is a non-parametric, lazy learning algorithm. If we try to understand the concept of lazy, unlike eager learning, lazy learning does not have a training phase. It does not learn the training data, instead it “memorizes” the training data set. When we want to make an estimate, it looks for the nearest neighbors in the whole dataset.

# instagram:cuneytaykac_
"""
# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import matplotlib.pyplot as plt

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
data=pd.read_csv("/kaggle/input/biomechanical-features-of-orthopedic-patients/column_2C_weka.csv")
data.head()
data.info()
"""
* Normal=1
* Abnormal=0
"""
data["class"]=[1 if i=="Normal"else 0 for i in data["class"]]
data.head()
y=data["class"].values
x_train=data.drop(["class"],axis=1)
"""
# Normalization

Normalization is very important. It is applied so that large numbers in the data do not destroy small numbers during drawing.
"""
#Normalization
x=(x_train-np.min(x_train))/(np.max(x_train)-np.min(x_train))
#Train test split 
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x,y,test_size = 0.2,random_state=1)
"""
# KNN ALGORİTHM

"""
from sklearn.neighbors import KNeighborsClassifier
knn=KNeighborsClassifier(n_neighbors=1) #k=1
knn.fit(x_train,y_train)
#Predict
prediction=knn.predict(x_test)

print(" {} nn score: {} ".format(1,knn.score(x_test,y_test)))

"""
 k=5 degeri için knn score
"""
"""
 5 nn score: 0.7741935483870968 
"""
"""
# KNN Model
"""
score_list=[]
for i in range(1,20):
    knn2=KNeighborsClassifier(n_neighbors=i)
    knn2.fit(x_train,y_train)
    score_list.append(knn2.score(x_test,y_test))
    
#Visualization

plt.plot(range(1,20),score_list)
plt.xlabel("k values")
plt.ylabel("accuracy")
plt.show()
"""
k yaklaşık olarak 4 de accuracy en yüksek degerine sahip
"""