import matplotlib.pyplot as plt import csv import numpy as np from knn import KNN f = open('iris.csv') csv_f = csv.reader(f) print(1) knn = KNN() knn.Load_Dataset('iris.csv') knn.Determine_Data_Shape('iris.csv') print(knn.numColumnsOfData) print(knn.numRowsOfData) sp0 = 0 sp1 = 0 sp2 = 0 #for row in csv_f: # if (int(row[4]) == 0): # count += 1 # #print("There are %s samples of Iris setosa in the sample." % count) x = knn.data[:, 0:1] y = knn.data[:, 1:2] # Switched from 0:2 to :
import matplotlib.pyplot as plt import numpy as np from knn import KNN import os knn = KNN() path = os.getcwd( ) + "/Downloads/LeapDeveloperKit_2.3.1+31549_mac/LeapSDK/lib/Del 4/iris.csv" knn.Load_Dataset(path) trainX = knn.data[::2, 1:3] trainy = knn.target[::2] testX = knn.data[1::2, 1:3] testy = knn.target[1::2] knn.Use_K_Of(15) knn.Fit(trainX, trainy) colors = np.zeros((3, 3), dtype='f') colors[0, :] = [1, 0.5, 0.5] colors[1, :] = [0.5, 1, 0.5] colors[2, :] = [0.5, 0.5, 1] plt.figure() [numItems, numFeatures] = knn.data.shape for i in range(0, numItems / 2): itemClass = int(trainy[i]) currColor = colors[itemClass, :]