Scikit Learn或其他用于参数优化的Python工具



我有一个简单的模型,其中有两个参数需要"调优"。使用参数"a"one_answers"b",模型方程为:

model = (a * temp) + (b * rad)

temprad是测量数据集(在这种情况下是温度和辐射)。这些数据集是Pandas DateTime索引系列,频率为一天(24小时)。

temp数据如下:

TIMESTAMP
2014-07-17    1.399556
2014-07-18    1.492743
2014-07-19    1.865306
2014-07-20    2.478098
...   
2016-08-23    2.327437
2016-08-24    3.065250
2016-08-25    2.427021
2016-08-26    1.365833
Name: AirTC_2, Length: 213, dtype: float64

rad数据如下:

TIMESTAMP
2014-07-17    2292.717541
2014-07-18    2228.255459
2014-07-19    2166.962811
2014-07-20    2803.802975
...     
2016-08-23     696.327810
2016-08-24    1431.858289
2016-08-25    1083.182916
2016-08-26     542.908838
Name: CNR_Wm2, Length: 213, dtype: float64

我还有一个测量数据集,模型正试图对其进行近似。measured数据集如下所示:

TIMESTAMP
2014-07-17    0.036750
2014-07-18    0.045892
2014-07-19    0.041919
2014-07-20    0.044640
...   
2016-08-23    0.029696
2016-08-24    0.033997
2016-08-25    0.032872
2016-08-26    0.012204
Name: melt_sonic, Length: 213, dtype: float64

我使用标准回归技术对模型参数进行了初步优化:最小化modelmeasured之间的平方差(误差)之和。我测试了ab的一系列参数空间,运行了10000个唯一参数组合的模型(其中ab的数组长度都是100)。

a = np.arange(0.00000009,0.00001,0.0000001)   
b = np.arange(0.0115,0.0125,0.00001)

我只是简单地对数学进行编码来进行分析,我想通过使用适当库中的包方法独立优化参数来仔细检查我的结果。

使用Scikit Learn或其他Python库优化这些参数的最合适方法是什么?

这被称为"线性回归",您不需要尝试不同的参数组合来找到好的参数。应用直接的数学公式可以解析地解决这个问题,所以你甚至不需要猜测好参数的范围。

在代码方面,您可以使用scikit learn的LinearRegression估计器:

from sklearn.linear_model import LinearRegression
X = pd.concat([rad, temp], axis=1)  # the input of the model
y = measured  # the output of the model
estimator = LinearRegression()  # create the estimator object
estimator.fit(X, y)  # optimize the parameters of the model on the data
a, b = estimator.coef_  # the obtained parameters

有关更多信息,请参见本例中的线性回归教程。

最新更新