我设法优化了一条线,以便使用curve_fit获得最佳拟合线,但我似乎无法以线性回归的方式得到R平方值,这是我的代码:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
from scipy.optimize import *
from scipy.integrate import *
from scipy.interpolate import *
df=pd.read_csv('F:/Data32.csv')
df2=df['Temperature']
df3=df['CO2-Rh']
def f(x,a,b,c) :
return a*np.exp(b*x)+c
params, extras = curve_fit(f, df2, df3)
print('a=%g,b=%g, c=%g' %(params[0],df2[1],df3[2]))
plt.plot(df2,df3,'o')
plt.plot(df2,f(df2,params[0],params[1],params[2]))
plt.legend(['data','fit'],loc='best')
plt.show()