摘要:本文主要向大家介绍了机器学习入门之机器学习(2)—— matplotlib,通过具体的内容向大家展现,希望对大家学习机器学习入门有所帮助。
本文主要向大家介绍了机器学习入门之机器学习(2)—— matplotlib,通过具体的内容向大家展现,希望对大家学习机器学习入门有所帮助。
python34 中绘图基本是matplotlib库,基于matplotlib库可以绘制基本的图形。 1、基本绘图
(1)点图(data://pan.baidu.com/s/1i3L0UDB)
1 import matplotlib.pyplot as plt
2 import math
3 from numpy import *
4 def file2matrix(filename):
5 fr = open(filename)
6 numberOfLines = len(fr.readlines()) #get the number of lines in the file
7 returnMat = zeros((numberOfLines,3)) #prepare matrix to return
8 classLabelVector = [] #prepare labels return
9 fr = open(filename)
10 index = 0
11 for line in fr.readlines():
12 line = line.strip()
13 listFromLine = line.split(‘\t‘)
14 returnMat[index,:] = listFromLine[0:3]
15 classLabelVector.append(int(listFromLine[-1]))
16 index += 1
17 return returnMat,classLabelVector
18 # return returnMat
19
20
21
22 datingDataMat,datingLabels = file2matrix(‘datingTestSet2.txt‘)
23 fig = plt.figure()
24 ax = fig.add_subplot(111)
25 ax.scatter(datingDataMat[:,1],datingDataMat[:,2],15.0*array(datingLabels),15.0*array(datingLabels))
26 plt.show()
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标人工智能机器学习频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号