如何在多标签SVM中创建训练和测试文件?我的问题是 https://www.quora.com/Can-anyone-give-me-some-pointers-for-using-SVM-for-user-recognition-using-keystroke-timing/answer/Chomba-Bupe?snid3=364610243&nsrc=1&filter=all
我的项目是动态键盘,用户对所有用户的训练。例如,如果你有三个类别A、B和C,你将有3个SVM,每个SVM都有自己的参数,即权重和偏置,以及3个分别对应于这3个类别的独立输出。在训练SVM-A时,其他两个类别B和C作为负训练集,而A作为正训练集;然后在训练SVM-B时,A和C作为负训练集;对于SVM-C,A和B是负训练集。这是所谓的“一对所有”训练过程。
我尝试过但结果出错了
我的训练文件是.csv格式,内容如下:
65 134,+1
70 98,+1
73 69,+1
82 122,+1
82 95,+1
83 127,+1
84 7,+1
85 64,+1
65 123,-1
71 115,-1
73 154,-1
73 156,-1
77 164,-1
77 144,-1
79 112,-1
83 91,-1
我的测试文件也是.csv格式,内容如下:
65 111
68 88
70 103
73 89
82 111
82 79
83 112
84 36
85 71
我的代码是
'use strict';var so = require('stringify-object');var Q = require('q');var svm = require('../lib');var trainingFile = './archivos/training/340.txt';var testingFile = './archivos/present/340.txt';var clf = new svm.CSVC({ gamma: 0.25, c: 1, // allow you to evaluate several values during training normalize: false, reduce: false, kFold: 1 // disable k-fold cross-validation});Q.all([ svm.read(trainingFile), svm.read(testingFile)]).spread(function (trainingSet, testingSet) { return clf.train(trainingSet) .progress(function(progress){ console.log('training progress: %d%', Math.round(progress*100)); }) .then(function () { return clf.evaluate(testingSet); });}).done(function (evaluationReport) { console.log('Accuracy against the testset:\n', so(evaluationReport));});enter code here
回答:
你的标签是1和-1吗?如果是的话,你也需要知道测试数据的这些类别。测试分类器的目的是看它对未见数据的预测效果如何。
作为一个小例子,你可以用你的训练数据构建分类器: x_train = [65, 134], [70,98]....... [79, 112], [83, 91]
y_train = [ 1, 1, ....-1, -1]
然后你通过传入测试数据来测试你的分类器。假设你传入了测试数据中的前三个例子,它做出了以下预测。[65, 111] --> 1
[68, 88] -->-1
[70,103] -->-1
然后你统计它正确预测的测试数据数量,但要做到这一点,你首先需要知道测试数据的类别。如果你没有这些信息,或许你可以尝试在训练数据上进行交叉验证。