首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >accord.net支持向量机增量训练

accord.net支持向量机增量训练
EN

Stack Overflow用户
提问于 2017-04-22 14:19:31
回答 1查看 509关注 0票数 1

我正在使用Accord.net中的支持向量机进行时间序列建模。我用可用的数据(比如5000)训练它一次。在那之后,我每秒都会得到新的数据,我想以增量的方式更新我的SVM机器,每秒钟使用一个数据,这可能吗?

EN

回答 1

Stack Overflow用户

发布于 2017-08-23 03:44:54

虽然现在可以在Accord.NET中增量地学习支持向量机,但不幸的是,此功能仅适用于线性机器。由于您使用的是时间序列,因此我假设您使用的是使用动态时间扭曲内核的内核SVM。

如果您能够从您的序列中提取固定长度的特征,那么如果您将这些特征提供给线性机器,并使用随机梯度下降或Averaged Stochastic Gradient Descent对其进行训练,则您所要求的可能是可能的,如下所示:

代码语言:javascript
复制
// In this example, we will learn a multi-class SVM using the one-vs-one (OvO)
// approach. The OvO approacbh can decompose decision problems involving multiple 
// classes into a series of binary ones, which can then be solved using SVMs.

// Ensure we have reproducible results
Accord.Math.Random.Generator.Seed = 0;

// We will try to learn a classifier
// for the Fisher Iris Flower dataset
var iris = new Iris();
double[][] inputs = iris.Instances; // get the flower characteristics
int[] outputs = iris.ClassLabels;   // get the expected flower classes

// We will use mini-batches of size 32 to learn a SVM using SGD
var batches = MiniBatches.Create(batchSize: 32, maxIterations: 1000,
   shuffle: ShuffleMethod.EveryEpoch, input: inputs, output: outputs);

// Now, we can create a multi-class teaching algorithm for the SVMs
var teacher = new MulticlassSupportVectorLearning<Linear, double[]>
{
    // We will use SGD to learn each of the binary problems in the multi-class problem
    Learner = (p) => new StochasticGradientDescent<Linear, double[], LogisticLoss>()
    {
        LearningRate = 1e-3, 
        MaxIterations = 1 // so the gradient is only updated once after each mini-batch
    }
};

// The following line is only needed to ensure reproducible results. Please remove it to enable full parallelization
teacher.ParallelOptions.MaxDegreeOfParallelism = 1; // (Remove, comment, or change this line to enable full parallelism)

// Now, we can start training the model on mini-batches:
foreach (var batch in batches)
{
    teacher.Learn(batch.Inputs, batch.Outputs);
}

// Get the final model:
var svm = teacher.Model;

// Now, we should be able to use the model to predict 
// the classes of all flowers in Fisher's Iris dataset:
int[] prediction = svm.Decide(inputs);

// And from those predictions, we can compute the model accuracy:
var cm = new GeneralConfusionMatrix(expected: outputs, predicted: prediction);
double accuracy = cm.Accuracy; // should be approximately 0.973
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43555950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档