from sklearn.metrics import classification_report
import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier

#Importing of the dataset and slicing it into independent and dependent variables
dataset = pd.read_csv('Social_Network_Ads.csv')
X = dataset.iloc[:, [1, 2, 3]].values #input features #dataset.iloc[rows, columns]
y = dataset.iloc[:, -1].values #output/target

#Since our dataset contains character variables we have to encode it using LabelEncoder
le = LabelEncoder()
X[:,0] = le.fit_transform(X[:,0])

#We are performing a train test split on the dataset
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 1)

#Next, we are doing feature scaling for reducing the size to smaller values
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

#we have to create and train the K Nearest Neighbor model with the training set
classifier = KNeighborsClassifier(n_neighbors = 5)
classifier.fit(X_train, y_train)

#prediction
y_pred = classifier.predict(X_test)

#evaluation
print(classification_report(y_test, y_pred))