[英]ILNumerics: ILMath.ridge_regression
有誰知道如何在ILMath函數中使用ridge_regression嗎? 我嘗試閱讀文檔並在多個網站中搜索,但找不到該示例。
方法如下:
public static ILMath..::..ILRidgeRegressionResult<double> ridge_regression(
ILInArray<double> X,
ILInArray<double> Y,
ILBaseArray Degree,
ILBaseArray Regularization
)
我對“正則化”有些困惑。
基本上,ridge_regression從一些測試數據中學習多項式模型。 它分兩步運行:
1)在學習階段,您將創建一個模型。 該模型由從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);
}
這里,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)在“使用”塊(C#)中使用ridge_regression。 這樣可以確保正確放置可能很大的模型數據。
2)一旦嘗試從數據中學習模型,正則化就變得更加重要,這可能會帶來一些穩定性問題。 您需要試驗正則項並考慮實際數據。
3)在此示例中,您將看到插值結果非常適合原始函數。 但是,基礎模型基於多項式。 與(所有/多項式)模型一樣,估計值可能會越來越少地反映基礎模型,這與您在學習階段使用的原始值范圍相去甚遠。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.