有谁知道如何在ridge_regression函数中使用ILMath吗?我试着阅读这些文档并在几个网站上搜索,但是我找不到例子。
以下是一种方法:
public static ILMath..::..ILRidgeRegressionResult<double> ridge_regression(
ILInArray<double> X,
ILInArray<double> Y,
ILBaseArray Degree,
ILBaseArray Regularization
)单击此处查看函数的详细信息。
我有点混淆了“正规化”。
发布于 2014-05-19 13:00:44
ILNumerics.ILMath.ridge_regression
基本上,ridge_regression从一些测试数据中学习多项式模型。它分两步工作:
1)在学习阶段,您创建了一个模型。模型由ILRidgeRegressionResult类的一个实例表示,该实例从ridge_regression返回:
using (var result = ridge_regression(Data,Labels,4,0.01)) {
// the model represented by 'result' is used within here
// to apply it to some unseen data... See step 2) below.
L.a = result.Apply(X + 0.6);
}这里,X是一些数据集,Y是与那些X数据相对应的“标签”集。在本例中,X是一个线性向量,Y是该向量上sin()函数的结果。因此,ridge_regression结果表示一个模型,该模型产生与sin()函数类似的结果--在一定的范围内。在实际应用中,X可以是任意维数的。
2)应用模型:回归结果用于估计新的、未见的数据对应的值。我们将该模型应用于与原始数据相同维数的数据。但是有些数据点在这个范围内,有些在我们用来学习数据的范围之外。因此,回归结果对象的apply()函数允许我们插值和外推数据。
完整的例子:
private class Computation : ILMath {
public static void Fit(ILPanel panel) {
using (ILScope.Enter()) {
// just some data
ILArray<double> X = linspace(0, 30, 20) / pi / 4;
// the underlying function. Here: sin()
ILArray<double> Y = sin(X);
// learn a model of 4th order, representing the sin() function
using (var result = ridge_regression(X, Y, 4, 0.002)) {
// the model represented by 'result' is used within here
// to apply it to some unseen data... See step 2) below.
ILArray<double> L = result.Apply(X + 0.6);
// plot the stuff: create a plotcube + 2 line XY-plots
ILArray<double> plotData = X.C; plotData["1;:"] = Y;
ILArray<double> plotDataL = X + 0.6; plotDataL["1;:"] = L;
panel.Scene.Add(new ILPlotCube() {
new ILLinePlot(tosingle(plotData), lineColor: Color.Black, markerStyle:MarkerStyle.Dot),
new ILLinePlot(tosingle(plotDataL), lineColor: Color.Red, markerStyle:MarkerStyle.Circle),
new ILLegend("Original", "Ridge Regression")
});
}
}
}
}这将产生以下结果:

若干注记
1)在“使用”块中使用ridge_regression (C#)。这就保证了模型数据的正确处理。
2)当你尝试从数据中学习一个模型时,正则化变得更加重要,这可能会带来一些稳定性问题。您需要尝试正则化项,并将实际数据考虑在内。
3)在本例中,您可以看到插值结果非常符合原始函数。然而,底层模型是基于多项式的。对于(所有/多项式)模型来说,估计值可能反映的基础模型越来越少,与学习阶段使用的原始值的距离越远。
https://stackoverflow.com/questions/23729696
复制相似问题