-
Notifications
You must be signed in to change notification settings - Fork 46
Description
The Problem:
I am getting the same predictions no matter what input data I am giving..
Input Data:
The input data files are attached as zip.
testfat.zip
I have ried with the fat dataset published in libsvm site.
https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/regression/bodyfat
I have used the last 19 records are test records and rest of them as train records.
Below is the result. You can note that all the 19 records produced the same '1.05195' as the result.
Code:
var fs = require("fs");
async function xor() {
var trainDataString = fs.readFileSync('../src/assets/bp/trainfat.csv')+"";
var testDataString = fs.readFileSync('../src/assets/bp/testfat.csv')+"";
testNodeSVM(trainDataString.split('\n').splice(1),testDataString.split('\n').splice(1));
}
async function testNodeSVM(trainData,testData){
var svm = require('node-svm');
// initialize a new predictor
var fatSVM = new svm.EpsilonSVR({gamma:0.01,cost:1,epsilon:0.1});
let nodeSVMFatArray = [];
for(let i=0;i<trainData.length;i++){
let line = trainData[i];
let trainingRecord = line.split(",").map(data => parseFloat(data));
if(trainingRecord.length === 15){
let inputParams = trainingRecord.splice(1);
nodeSVMFatArray.push([inputParams,trainingRecord[0]]);
}
}
// console.log(nodeSVMSysArray);
// console.log(testData);
await fatSVM.train(nodeSVMFatArray);
testData.forEach(element => {
if(element.length > 0){
// console.log(element);
let dataArrayStr = element.split(",");
let testDataArray = dataArrayStr.map(data => parseFloat(data));
values = [];
values.push(fatSVM.predictSync(testDataArray.splice(1)));
console.log(values);
}
});
}
xor().then(() => console.log('done!'));
Result:
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
[ 1.05195 ]
I have tested the same fat files on R also..Below are the commands and the final result..
fatTest<-read.csv("C:\Code\WearableVitals\src/assets/bp/testfat.csv")
fat<-read.csv("C:\Code\WearableVitals\src/assets/bp/trainfat.csv")
fatFitRadialEsp<-svm(Fat~.,data=fat,type="eps-regression",kernel="radial")
predFat<-predict(fatFitRadialEsp,fatTest)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1.042609 1.042513 1.053037 1.043323 1.031655 1.068895 1.033243 1.064847 1.026723 1.032486 1.036302 1.032156 1.064235 1.036778 1.069251 1.033492 1.034420 1.044378 1.038295
Other trials:
I have tried without any parameters and with various options and it has no effect.
I also tried all the types of classifiers and regression types, with each
of the type the prediction is different but it is the the same prediction
for any input.
Even of I give all 1s as the test input the prediction is still same.
Please help me to solve this issue. I am stuck.