libsvm-wasm
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -1,2 +0,2 @@ | ||
import { SVM } from '../src/'; | ||
import { SVM, ISVMParam, SVM_TYPE, KERNEL_TYPE, SVMParam } from '../src/'; | ||
import { readFileSync } from 'fs'; | ||
@@ -13,3 +13,2 @@ import { join } from 'path'; | ||
const label = rawData.map(it => parseInt(it[0])); | ||
@@ -19,18 +18,36 @@ const data = rawData.map(it => it.slice(1).map(it => parseFloat(it))); | ||
async function ml(data: any, label: any){ | ||
const svm = new SVM(); | ||
svm.feedSamples(data, label); | ||
const param: ISVMParam = { | ||
svm_type: SVM_TYPE.EPSILON_SVR, | ||
kernel_type: KERNEL_TYPE.RBF, | ||
degree: 3, | ||
gamma: 1/(2*6.75), | ||
coef0: 0, | ||
cache_size: 100, | ||
C: 1, | ||
nr_weight: 0, | ||
weight_label: [], | ||
weight: [], | ||
nu: 0.5, | ||
p: 0.1, | ||
shrinking: 1, | ||
probability: 0 | ||
}; | ||
const aParam: SVMParam = new SVMParam(param, 1e-3); | ||
const svm = new SVM(aParam); | ||
await svm.feedSamples([[1,1,1], [-2,-2,2]], [0, 1]); | ||
await svm.train(); | ||
let pred_data: Array<number> = []; | ||
for(let i in data){ | ||
let pred = await svm.predict(data[i]) | ||
pred_data.push(pred); | ||
const pred = [[1,1,1], [-2,-2,-2]]; | ||
for(let i in pred){ | ||
let p = await svm.predict(data[i]) | ||
pred_data.push(p); | ||
} | ||
const evaluate = svm.evaluate(label, pred_data); | ||
console.log(evaluate) | ||
console.log(pred_data); | ||
// const evaluate = svm.evaluate(label, pred_data); | ||
// console.log(evaluate) | ||
} | ||
ml(data,label) |
{ | ||
"name": "libsvm-wasm", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -40,6 +40,6 @@ import svmFactory, { LibsvmModlue } from '../dist/libsvm'; | ||
public param: ISVMParam = { | ||
svm_type: SVM_TYPE.C_SVC, | ||
svm_type: SVM_TYPE.EPSILON_SVR, | ||
kernel_type: KERNEL_TYPE.RBF, | ||
degree: 3, | ||
gamma: 0, | ||
gamma: 1/(2*6.75), | ||
coef0: 0, | ||
@@ -53,3 +53,3 @@ cache_size: 100, | ||
p: 0.1, | ||
shrinking: 0, | ||
shrinking: 1, | ||
probability: 0 | ||
@@ -249,2 +249,3 @@ }; | ||
SVM, | ||
ISVMParam, | ||
SVM_TYPE, | ||
@@ -251,0 +252,0 @@ KERNEL_TYPE, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
333174
15
1275