2017-06-05 28 views

回答

2

在項目採用新的統一學習API後,該文檔仍在整合,該API現在對於所有機器學習模型都很常見。其中大部分是昨天剛剛更新的,但有幾部分可能仍需要注意。

回答你的原始問題,你可以在下面找到一個多項式SV迴歸的例子。假設我們有2維輸入向量,並且我們想要學習從這些向量到單個標量值的映射。

// Declare a very simple regression problem 
// with only 2 input variables (x and y): 
double[][] inputs = 
{ 
    new[] { 3.0, 1.0 }, 
    new[] { 7.0, 1.0 }, 
    new[] { 3.0, 1.0 }, 
    new[] { 3.0, 2.0 }, 
    new[] { 6.0, 1.0 }, 
}; 

double[] outputs = 
{ 
    65.3, 
    94.9, 
    65.3, 
    66.4, 
    87.5, 
}; 

例如起見,我們將本機的複雜性參數設置爲一個很高的值,強制學習算法來尋找硬利潤率的解決方案,否則將不能一概而論很好。當現實世界的問題的訓練,離開性質UseKernelEstimation和UseComplexityHeuristic設置爲true或執行網格搜索找到自己的最佳參數:

// Create a LibSVM-based support vector regression algorithm 
var teacher = new FanChenLinSupportVectorRegression<Polynomial>() 
{ 
    Tolerance = 1e-5, 
    // UseKernelEstimation = true, 
    // UseComplexityHeuristic = true 
    Complexity = 10000, 
    Kernel = new Polynomial(degree: 1) // you can change the degree 
}; 

現在,我們已經創建了學習算法後,我們可以用它來從數據訓練SVM模型:

// Use the algorithm to learn the machine 
var svm = teacher.Learn(inputs, outputs); 

終於可以拿到機器的回答爲一組輸入,我們可以檢查機器的預測值有多好相較於預期的地面實況:

// Get machine's predictions for inputs 
double[] prediction = svm.Score(inputs); 

// Compute the error in the prediction (should be 0.0) 
double error = new SquareLoss(outputs).Loss(prediction); 
+0

完美的答案和很好的記錄和解釋。我真誠地不能夠感謝你!保持良好的工作! –

相關問題