2017-06-05 70 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

完美的答案和很好的记录和解释。我真诚地不能够感谢你!保持良好的工作! –