|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 没有土豆的洋芋 于 2017-4-15 11:22 编辑
import urllib2
url = 'http://aima.cs.berkeley.edu/data/iris.csv'
u = urllib2.urlopen(url)
localFile = open('iris.csv'', 'w')
localFile.write(u.read())
localFile.close()
from numpy import genfromtxt, zeros
data = genfromtxt('iris.csv',delimiter=',',usecols=(0,1,2,3))
target = genfromtxt('iris.csv',delimiter=',',usecols=(4),dtype=str)
from pylab import figure, subplot, hist, xlim, show
xmin = min(data[:,0])
xmax = max(data[:,0])
figure()
subplot(411)
hist(data[target='setosa',0],color='b',alpha=.7)
xlim(xmin,xmax)
subplot(412)
hist(data[target=='versicolor',0],color='r',alpha=.7)
xlim(xmin,xmax)
subplot(413)
hist(data[target=='virginica',0],color='g',alpha=.7)
xlim(xmin,xmax)
subplot(414)
hist(data[:,0],color='y',alpha=.7)
xlim(xmin,xmax)
show()
显示错误:invalid syntax
源程序 网址http://chuansong.me/n/2675694
谢谢
- import urllib
- import requests
- # from urllib import request
- url = 'http://aima.cs.berkeley.edu/data/iris.csv'
- u = requests.get(url)
- localFile = open('iris.csv', 'w')
- localFile.write(u.text)
- localFile.close()
- from numpy import genfromtxt, zeros
- data = genfromtxt('iris.csv',delimiter=',',usecols=(0,1,2,3))
- target = genfromtxt('iris.csv',delimiter=',',usecols=(4),dtype=str)
- from pylab import figure, subplot, hist, xlim, show
- xmin = min(data[:,0])
- xmax = max(data[:,0])
- figure()
- subplot(411)
- hist(data[target=='setosa',0],color='b',alpha=.7)
- xlim(xmin,xmax)
- subplot(412)
- hist(data[target=='versicolor',0],color='r',alpha=.7)
- xlim(xmin,xmax)
- subplot(413)
- hist(data[target=='virginica',0],color='g',alpha=.7)
- xlim(xmin,xmax)
- subplot(414)
- hist(data[:,0],color='y',alpha=.7)
- xlim(xmin,xmax)
- show()
复制代码
给你改了下,
- hist(data[target='setosa',0],color='b',alpha=.7)
复制代码
少个=
|
-
|