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进行绘图以查找小的错误,并获得很好的答案