简体   繁体   English

ILNumerics:ILMath.ridge_regression

[英]ILNumerics: ILMath.ridge_regression

is there anyone know how to use ridge_regression in ILMath function? 有谁知道如何在ILMath函数中使用ridge_regression吗? I try to read the documents and search in several website, but I can't find the example. 我尝试阅读文档并在多个网站中搜索,但找不到该示例。

Here is the method: 方法如下:

public static ILMath..::..ILRidgeRegressionResult<double> ridge_regression(
     ILInArray<double> X,
     ILInArray<double> Y,
     ILBaseArray Degree,
     ILBaseArray Regularization
)

click here to see the details of the function 点击此处查看该功能的详细信息

I had a bit confuse with the "Regularization". 我对“正则化”有些困惑。

ILNumerics.ILMath.ridge_regression ILNumerics.ILMath.ridge_regression

Basically, ridge_regression learns a polynomial model from some test data. 基本上,ridge_regression从一些测试数据中学习多项式模型。 It works in a two step process: 它分两步运行:

1) In the learning phase you create a model. 1)在学习阶段,您将创建一个模型。 The model is represented by an instance of the ILRidgeRegressionResult class which is returned from ridge_regression: 该模型由从ridge_regression返回的ILRidgeRegressionResult类的实例表示:

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); 
}

Here, X is some data set and Y is the set of 'labels' which corresponds to those X data. 这里,X是一些数据集,而Y是与那些X数据相对应的“标签”集。 In this example, X is a linear vector and Y is the result of the sin() function on that vector. 在此示例中,X是线性向量,Y是该向量上sin()函数的结果。 So the ridge_regression result represents a model which produces similar results as the sin() function - in certain limits. 因此,ridge_regression结果表示一个模型,该模型在一定范围内产生与sin()函数相似的结果。 In real applications, X may be of any dimensionality. 在实际应用中,X可以是任何尺寸。

2) Apply the model: the regression result is than used to estimate values corresponding to new, unseen data. 2)应用模型:然后将回归结果用于估计与新的看不见的数据相对应的值。 We apply the model to data, which have the same number of dimensions as the original data. 我们将模型应用于数据,这些数据具有与原始数据相同的维数。 But some of the data points lay within the range, some outside of the range we used to learn the data from. 但是有些数据点在范围内,有些超出了我们用来从中学习数据的范围。 The apply() function of the regression result object therefore allows us to interpolate as well as extrapolate data. 因此,回归结果对象的apply()函数允许我们对数据进行内插和外推。

The complete example: 完整的示例:

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")
                }); 
            }
        }
    }
}

This produces the following result: 这将产生以下结果: 用于插值的岭回归

Some Notes 一些注意事项

1) Use ridge_regression in a 'using' block (C#). 1)在“使用”块(C#)中使用ridge_regression。 This ensures that the data of the model which can be quite large are disposed off correctly. 这样可以确保正确放置可能很大的模型数据。

2) The Regularization becomes more important, once you try to learn a model from data which may introduce some stability problems. 2)一旦尝试从数据中学习模型,正则化就变得更加重要,这可能会带来一些稳定性问题。 You need to experiment with the regularization term and take the actual data into account. 您需要试验正则项并考虑实际数据。

3) In this example, you see the interpolation result fitting very nicely the original function. 3)在此示例中,您将看到插值结果非常适合原始函数。 However, the underlying model is based on a polynomial. 但是,基础模型基于多项式。 As common for (all/polynomial) models, the estimated values may reflect the underlying model less and less, the far you get from the original range of values used in the learning phase. 与(所有/多项式)模型一样,估计值可能会越来越少地反映基础模型,这与您在学习阶段使用的原始值范围相去甚远。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM