Machine Learning Practical Notes (1)

Python 2.7
install Numpy function library
Install Matplotlib function library

kNN1.py
Run Module F5

>>> from numpy import *
>>> group,labels=createDataSet()
>>> classify0([0,0],group,labels,3)
>>> datingDataMat,datingLabels=file2matrix('datingTestSet2.txt')
>>> import matplotlib
>>> import matplotlib.pyplot as plt
>>> fig=plt.figure()
>>> ax = fig.add_subplot(111)
>>> ax.scatter(datingDataMat[:,1],datingDataMat[:,2],15.0*array(datingLabels),15.0*array(datingLabels))
>>> plt.show()

write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325948451&siteId=291194637