May 2018
Intermediate to advanced
340 pages
7h 20m
English
Without much talking, let's take a look at the following code:
import numpy as npimport pandas as pdfrom sklearn.neighbors import KNeighborsClassifierknn = KNeighborsClassifier(n_neighbors=5)data = pd.read_csv('dataset.csv')x = np.array(data[['Time', 'Temp']])y = np.array(data[['State']]).ravel()knn.fit(x,y)time = raw_input("Enter time")temp = raw_input("Enter temp")data =. []data.append(float(time))data.append(float(temp))a = knn.predict([data])print(a[0])}
So, let's see what we are doing here:
import numpy as np
We are importing numpy to our program; this helps us handle lists and matrices:
import pandas as pd
Here, we are importing a library named pandas; this helps us read files in comma-separated values or ...