Numpy and polyfit, fit polynomials

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import set_matplotlib_formats
import numpy as np

x,y = np.loadtxt(“mystery1.csv”,delimiter=",",unpack=True)
plt.scatter(x,y, label = " the value x and y “) 点状图
plt.legend() 图例
plt.xlabel(“x”) x坐标
plt.ylabel(“y”) y坐标
plt.title(” the relationship between x and y ") 标题

polyfit and polyld 1

x,y = np.loadtxt(“mystery1.csv”,delimiter=",",unpack=True)
parameters = np.polyfit( x, y, 1)
my_poly_function = np.poly1d(parameters)
I should used plot to have picture , it is must continuous in the picture
this is the new define list , if not using this one , we just use the scatter

x_model = np.linspace(-4,4,200)
y_model = my_poly_function(x_model)

plt.scatter(x,y, label = “the picture from data “)
plt.plot(x_model,y_model , label = " fit picture of the data”, color = “green”)
plt.legend()
plt.xlabel(“x”)
plt.ylabel(“y”)
plt.title(” the realtionship between x and y “)
print(” first order polynomials " , parameters)

polyfit and polyld 2

parameters1 = np.polyfit( x, y, 2)
my_poly_function1 = np.poly1d(parameters1)

x_model = np.linspace(-4,4,200)
y_model1 = my_poly_function1(x_model)

plt.subplots()
plt.scatter(x,y, label = “the picture from data “)
plt.plot(x_model,y_model1 , label = " fit picture of the data”, color = “purple”)
plt.legend()
plt.xlabel(“x”)
plt.ylabel(“y”)
plt.title(” the realtionship between x and y “)
print(” second order polynomials" , parameters1)

根据对3多项式的观察,我认为第三个ia最适合原始散点图

它也应该有一条线,将实点(蓝色的点)与代表预测误差的预测点(绿色或紫色,绿色x的点)连接起来,或者称为残差,我们可以使用numpy计算的绝对误差 价值。 因此,我们得到三个设定的数字。 我将对.histograms进行绘图以查找小的错误,并获得很好的答案

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值