从一些数据生成二次多项式
我尝试了两种不同的代码,但多项式只是试图遍历所有点。
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
data = pd.read_csv('TESTEXskelet.csv', sep=",")
x = data.Gennemsnitlig_hastighed
y1 = data.Sum_VSP
np.polyfit(x,y1,2)
plt.grid()
plt.title("VSP sum/hastighed")
plt.ylabel('VSP - kW/ton')
plt.xlabel('Hastighed - km/t')
plt.scatter(x,y1,s=5) # Definere selve plottet
plt.plot(x, y1)
我也尝试过使用 sklearn,如果需要的话我可以上传。
I have some data which I want to generate a 2nd degree polyfit like this as example:
I have tried two different codes but the polynomial just trying to go through all points.
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
data = pd.read_csv('TESTEXskelet.csv', sep=",")
x = data.Gennemsnitlig_hastighed
y1 = data.Sum_VSP
np.polyfit(x,y1,2)
plt.grid()
plt.title("VSP sum/hastighed")
plt.ylabel('VSP - kW/ton')
plt.xlabel('Hastighed - km/t')
plt.scatter(x,y1,s=5) # Definere selve plottet
plt.plot(x, y1)
But then it plots it through every point.
I have also tried with sklearn, and I can upload that if requested.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正确拟合了二次多项式。你只是在那之后的情节中没有使用它。
plt.scatter(x,y1,s=5)
绘制原始数据的散点图,plt.plot(x, y1)
绘制一条穿过所有数据的线数据。要绘制多项式,您需要将多项式拟合到变量中。然后定义要绘制的 x 轴范围并根据多项式拟合预测 y 值:
You correctly fitted a 2nd degree polynomial. You are just not using it in the plot you do after that.
plt.scatter(x,y1,s=5)
does a scatter plot of your original data, andplt.plot(x, y1)
plots a line through all your data.To plot the polynomial you need to catch the polynomial fit into a variable. Then define a range for the x-axis you want to plot over and predict y values based on the polynomial fit:
polyfit
将参数返回到您的多项式,尝试polyfit
returns the parameters to your polynomial, try