Reader small image

You're reading from  Python Robotics Projects

Product typeBook
Published inMay 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788832922
Edition1st Edition
Languages
Concepts
Right arrow
Author (1)
Prof. Diwakar Vaish
Prof. Diwakar Vaish
author image
Prof. Diwakar Vaish

Prof. Diwakar Vaish is a robotics scientist and the inventor of Manav (India's first indigenous humanoid robot), the world's first mind-controlled wheelchair, brain cloning, and the world's cheapest ventilator. He has also been a guest lecturer at over 13 IITs and various other institutions. He is the founder of A-SET Robotics, a leading robotics research company based in New Delhi.
Read more about Prof. Diwakar Vaish

Right arrow

Predicting using a dataset


Without much talking, let's take a look at the following code:

import numpy as np
import pandas as pd
from sklearn.neighbors import KNeighborsClassifier

knn = 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 in other words, CSV files. We will be using CSV files to store our data and access it for learning process:

from sklearn.neighbors import KNeighborsClassifier

Here, we are importing KneighborsClassifier from the library sklearnsklearn itself...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Python Robotics Projects
Published in: May 2018Publisher: PacktISBN-13: 9781788832922

Author (1)

author image
Prof. Diwakar Vaish

Prof. Diwakar Vaish is a robotics scientist and the inventor of Manav (India's first indigenous humanoid robot), the world's first mind-controlled wheelchair, brain cloning, and the world's cheapest ventilator. He has also been a guest lecturer at over 13 IITs and various other institutions. He is the founder of A-SET Robotics, a leading robotics research company based in New Delhi.
Read more about Prof. Diwakar Vaish