简体   繁体   English

Accord.Net中的多项式支持向量回归

[英]Polynomial Support Vector Regression in Accord.Net

I'm trying to learn the framework (Accord) but the documentation often comes with broken pieces of code. 我正在尝试学习框架(Accord),但是文档中经常附带一些残破的代码。
I wanted something similar to this . 我想类似的东西这个

I've tried different things and nothing seemed to work. 我尝试了不同的方法,但似乎没有任何效果。 Does anyone have a working non-lineal support vector regression example ? 有没有人有一个有效的非线性支持向量回归示例?
I also tried the official example which doesn't seem to work either. 我还尝试似乎也不起作用的官方示例

The documentation is still being put together after the project adopted a new, unified learning API that is now common for all machine learning models. 在项目采用新的,统一的学习API之后,该文档仍在整理中,该API现在对于所有机器学习模型都是通用的。 Most of it has just been updated yesterday, but a few parts might still need attention. 大部分内容昨天都已更新,但仍有一些部分仍需要注意。

Answering your original question, you can find an example for Polynomial SV regression below. 回答您的原始问题,您可以在下面找到一个多项式SV回归的示例。 Let's say that we have 2-dimensional input vectors, and we would like to learn a mapping from those vectors into a single scalar value. 假设我们有二维输入向量,我们想学习从这些向量到单个标量值的映射。

// 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,
};

For the sake of example, we will set the machine Complexity parameter to a very high value, forcing the learning algorithm to find hard-margin solutions that would otherwise not generalize very well. 为了举例说明,我们将机器复杂度参数设置为一个很高的值,从而迫使学习算法查找硬边界解决方案,否则这些解决方案将不能很好地推广。 When training in real-world problems, leave the properties UseKernelEstimation and UseComplexityHeuristic set to true or perform a grid search to find their optimal parameters: 在实际问题中进行训练时,请将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
};

Now, after we have created the learning algorithm, we can use it to train a SVM model from the data: 现在,在创建学习算法之后,我们可以使用它来从数据中训练SVM模型:

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

And finally we can get the machine's answers for the set of inputs and we can check how good the values predicted by the machine were in comparison to the expected ground-truth: 最后,我们可以得到机器对一组输入的答案,并且可以检查机器预测的值与预期的真实性相比有多好:

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

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

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