Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于参数优化的Scikit Learn或其他Python工具_Python_Pandas_Optimization_Scikit Learn - Fatal编程技术网

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

用于参数优化的Scikit Learn或其他Python工具,python,pandas,optimization,scikit-learn,Python,Pandas,Optimization,Scikit Learn,我有一个简单的模型,有两个参数需要“调整”。使用参数“a”和“b”,模型方程为: model = (a * temp) + (b * rad) temp和rad是测量数据集(在本例中,是温度和辐射)。这些数据集是以一天(24小时)为频率的时间索引序列 temp数据如下所示: TIMESTAMP 2014-07-17 1.399556 2014-07-18 1.492743 2014-07-19 1.865306 2014-07-20 2.478098

我有一个简单的模型,有两个参数需要“调整”。使用参数“a”和“b”,模型方程为:

model = (a * temp) + (b * rad)
temp
rad
是测量数据集(在本例中,是温度和辐射)。这些数据集是以一天(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
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
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
rad
数据如下所示:

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
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
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
我还有一个测量数据集,模型正试图对其进行近似。测量的
数据集如下所示:

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
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
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
我已经使用标准回归技术对模型参数进行了初步优化:最小化
模型
测量值
之间的平方差(误差)之和。我测试了
a
b
的一系列参数空间,运行了10000个唯一参数组合的模型(其中
a
b
的数组长度都是100)

我只是编写数学代码来进行分析,我想通过使用适当库中的包方法独立优化参数来再次检查我的结果

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

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

就代码而言,您可以使用scikit learn的
线性回归
估计器:

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


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

是的,我认为这是一个简单的线性回归问题。我想我正在测试一组不必要的大参数组合,但我应该得到一个接近分析的解决方案(受我在
np.arange()
中的步长限制)。我会试试你的代码。对于
y=measured#模型的输出
,我不确定评论是否准确。在我的示例中,变量“model”是模型的输出。。。。然而,我认为您就在这里,我们想要使用
y=measured
。注释更恰当地称为“测量数据”,代表模型的理想近似值。使用您的答案计算的
a
b
,我得到的值与我原来的方法非常相似。之前,我对a和b的优化值(使用值的范围)分别为0.0121和4.99e-06。你的方法给出了0.0108和2.59e-06。尽管解析解应该是最精确的,但使用新参数的模型结果给出的建模/测量结果之间的平方误差总和略高。我不知道该怎么解释,但你的答案正是我想要的。谢谢