text_plain_output_1.png
from collections import Counter

from sklearn.model_selection import train_test_split

from sklearn.model_selection import train_test_split

import numpy as np

import numpy as np # linear algebra

import pandas as pd

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

import pandas as pd
import numpy as np
import math
import operator
df = pd.read_csv('../input/Iris.csv')
df.shape
from collections import Counter

from sklearn.model_selection import train_test_split
x = df[['SepalLengthCm']]
y = df['Species']
x_train, x_test, y_train, y_test = train_test_split(x, y, train_size=0.33)
len(y_train)

def predict(x_train, y_train, x_test, k):
    distances = []
    targets = []
    for i in range(len(x_train)):
        distance = np.sqrt(np.sum(np.square(x_test - x_train.values[i, :])))
        distances.append([distance, i])
    distances = sorted(distances)
    for i in range(k):
        index = distances[i][1]
        targets.append(y_train.values[index])
    return Counter(targets).most_common(1)[0][0]

from sklearn.model_selection import train_test_split
x = df[['SepalLengthCm']]
y = df['PetalLengthCm']
x_train, x_test, y_train, y_test = train_test_split(x, y, train_size=0.33)
len(y_train)