Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ Machine learning in Action; Chapter 2.
- Seems as though I can't get matplotlib up and running I wrote one of these for gnuplot which is my
- grapher and plotter of choice. :)
- -lolamontes69
- """
- import Gnuplot as Gnuplot
- import Gnuplot, Gnuplot.funcutils
- from numpy import *
- import knn as knn
- def scatterplot(datingDataMat,datingLabels,x,y):
- listm,listn,listo=[],[],[]
- for a in range(len(datingLabels)):
- if datingLabels[a]=='largeDoses':
- dep=(datingDataMat[a][x],datingDataMat[a][y])
- listm.append(dep)
- elif datingLabels[a]=='smallDoses':
- dep=(datingDataMat[a][x],datingDataMat[a][y])
- listn.append(dep)
- elif datingLabels[a]=='didntLike':
- dep=(datingDataMat[a][x],datingDataMat[a][y])
- listo.append(dep)
- g = Gnuplot.Gnuplot(debug=1)
- plot1 = Gnuplot.PlotItems.Data(listm, with_="points 3", title="Large doses") # blue
- plot2 = Gnuplot.PlotItems.Data(listn, with_="points 1", title="Small doses") # red
- plot3 = Gnuplot.PlotItems.Data(listo, with_="points 2", title="Didnt Like") # green
- if x==0:
- g.xlabel('Frequent flier miles earned per year')
- g.ylabel('Percentage of time spent playing Video Games')
- elif x==1:
- g.xlabel('Percentage of time spent playing Video Games')
- g.ylabel('Liters of Ice Cream consumed per week')
- else:
- g.xlabel('Frequent flier miles earned per year')
- g.ylabel('Liters of Ice Cream consumed per week')
- g.title('Dating Test Set Scatterplot')
- g.plot(plot1,plot2,plot3)
- wait=raw_input('Press <ENTER> to continue')
- if __name__ == "__main__":
- datingDataMat, datingLabels = knn.file2matrix('datingTestSet.txt')
- scatterplot(datingDataMat,datingLabels,1,2)
- scatterplot(datingDataMat,datingLabels,0,1)
- scatterplot(datingDataMat,datingLabels,0,2)
Add Comment
Please, Sign In to add comment