#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 20 18:38:58 2020

@author: Caleb

This program uses a custom KNN machine learning class that implements a KD
tree to improve efficiency
"""

from sklearn import datasets
from sklearn.model_selection import train_test_split
import numpy as np
from CustomKD import CustomKNeighbors

# Load iris data and split into testing/training
iris = datasets.load_iris()
data_train, data_test, target_train, target_test = train_test_split(iris.data, iris.target, train_size=0.3)


""" 
CUSTOM KNN
"""

custom_classifier = CustomKNeighbors(3)
custom_classifier.fit(data_train, target_train)
custom_predictions = custom_classifier.predict(data_test)
    
custom_accuracy = np.mean(custom_predictions == target_test) * 100

"""
COMPARING TO SKLEARN KNN
"""
from sklearn.neighbors import KNeighborsClassifier

classifier = KNeighborsClassifier(n_neighbors=3)
classifier.fit(data_train, target_train)
predictions = classifier.predict(data_test)

sklearn_accuracy = np.mean(predictions == target_test) * 100

"""
I only need to know if my algorithm works equally as accurately as sklearn's
"""
if (custom_accuracy == sklearn_accuracy):
    print("Success!")
