我正在嘗試繪制觀察和建模的資料。這是資料框的示例,位于代碼下方。我收到此錯誤#### ValueError:傳遞值的長度為 2,索引意味著 9####。我不知道如何繪制建模資料。
all = [treatment1, treatment2]
[ x y intercept
0 25 0.171144 1.6
1 50 1.859164 1.6
2 100 4.407867 1.6
x y intercept
14 25 0.997440 1.3
15 50 1.823077 1.3
16 100 4.412220 1.3]
def model(x, slope):
return (slope*x) intercept
def func_fit(x):
return model(x,
popt)
from scipy.optimize import curve_fit
for g in all: #this loop allows to fit the model for each treatment
popt = curve_fit(model, g['x'], g['y'])
new_row = {'treatment':treatment, 'slope': popt[0], 'intercept':intercept}
results=results.append(new_row, ignore_index=True)
plt.plot(g['x'], g['y'], '.', label='data')
plt.plot(g['x'], func_fit(g['x']), 'r-', tuple(popt)) # this is the line that gives the error.
#### ValueError: Length of passed values is 2, index implies 9####
#I tried to overcome the error but what I get with these lines below is no line
#t= np.linspace(0,200,1)
#a = model(t,results.iloc[0,1])
#plt.plot(t, a, 'r') # plotting t, a separately
這些是觀察結果,我也想繪制建模資料:


uj5u.com熱心網友回復:
我假設您想繪制模型學習的功能?
如果是這種情況,這里是使用
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/444546.html
標籤:Python 熊猫 matplotlib 线性回归 曲线拟合
