如何在去掉空数据及如何在matplotlib中显示数据线性拟合
来源:互联网 发布:淘宝乔丹是真的吗 编辑:程序博客网 时间:2024/04/29 15:56
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
def error(f,x,y):
return sp.sum((f(x)-y)**2)
data = sp.genfromtxt('web_traffic.tsv',delimiter='\t')
x = data[:,0]
y = data[:,1]
x = x[~sp.isnan(y)]
y = y[~sp.isnan(y)]
plt.scatter(x,y)
plt.title('Web traffic over the last month')
plt.xlabel('Time')
plt.ylabel('Hits/hour')
plt.xticks([w*7*24 for w in range(10)],['week %i' %w for w in range(10)])
plt.autoscale(tight = True)
plt.grid()
fp1,residuals,rank,sv,rcond= sp.polyfit(x,y,1,full=True)
print("残差:",residuals)
print('Model parameter:',fp1)
f1 = sp.poly1d(fp1)
print(error(f1,x,y))
fx = sp.linspace(0,x[-1],1000)
plt.plot(fx,f1(fx),linewidth=4,color='red')
plt.legend(['d=%i' %f1.order],loc = 'upper left')
plt.show()
import scipy as sp
import matplotlib.pyplot as plt
def error(f,x,y):
return sp.sum((f(x)-y)**2)
data = sp.genfromtxt('web_traffic.tsv',delimiter='\t')
x = data[:,0]
y = data[:,1]
x = x[~sp.isnan(y)]
y = y[~sp.isnan(y)]
plt.scatter(x,y)
plt.title('Web traffic over the last month')
plt.xlabel('Time')
plt.ylabel('Hits/hour')
plt.xticks([w*7*24 for w in range(10)],['week %i' %w for w in range(10)])
plt.autoscale(tight = True)
plt.grid()
fp1,residuals,rank,sv,rcond= sp.polyfit(x,y,1,full=True)
print("残差:",residuals)
print('Model parameter:',fp1)
f1 = sp.poly1d(fp1)
print(error(f1,x,y))
fx = sp.linspace(0,x[-1],1000)
plt.plot(fx,f1(fx),linewidth=4,color='red')
plt.legend(['d=%i' %f1.order],loc = 'upper left')
plt.show()
阅读全文
0 0
- 如何在去掉空数据及如何在matplotlib中显示数据线性拟合
- 如何在数据窗口中显示图片
- 如何在ASP.NET中显示数据库中的数据
- 如何在ASP.NET中显示数据库中的数据
- 查看如何在一个 HTML 表格中显示 XML 数据。
- 如何在数据窗口中显示编码的名称
- 如何在DataGrid中显示来自不同DataTable的数据
- 如何将查询到的数据显示在DataGridView中
- 如何在rdlc中显示12个月的数据
- 如何在网页中显示数据图表--Echarts入门教程
- 如何在matplotlib里显示中文
- 如何通过DropDownList在GridView显示数据
- 在应用中如何去掉hoem键及statusbar
- 在ASP.NET中如何在DataGrid中实现数据嵌套显示
- 如何在数据窗口中加入一列空列做为选中一行的标志?
- 在winfrom中,如何将数据库的数据显示在datagridview控件上。
- 如何在HTML中引用XML数据
- 如何在SQL Server中恢复数据
- Android推送
- Andoroid进阶--底部图片选择Dialog
- java文件传输基础:OutputStream类及实现文件的复制
- JavaWeb-Listener2-在线用户统计
- 【JavaWeb】SpringMvc返回json
- 如何在去掉空数据及如何在matplotlib中显示数据线性拟合
- pg用户角色密码默认使用md5加密
- Excel 向程序发送命令时出现问题
- C3P0连接池
- mysql 链表查询(合计总数)
- dedecms中无法直接在arctype数据表中直接调取栏目链接
- pg(HGDB)在非默认位置创建表空间
- 平摊就是沼泽,除非你是金箍棒
- 关于如何方便使用枚举