diff --git a/README.md b/README.md index 3c36b23..d3f1277 100644 --- a/README.md +++ b/README.md @@ -84,24 +84,24 @@ Possible kernels are: Possible parameters/options are: -| Name | Default value(s) | Description | -|------------------|----------------------------------|-------------------------------------------------------------------------------------------------------| -| svmType | `C_SVC` | Used classifier | -| kernelType | `RBF` | Used kernel | -| c | `[0.01, 0.125, 0.5, 2]` | Cost for `C_SVC`, `EPSILON_SVR` and `NU_SVR`. Can be a `Number` or an `Array` of numbers | -| nu | `[0.01, 0.125, 0.5, 1]` | For `NU_SVC`, `ONE_CLASS` and `NU_SVR`. Can be a `Number` or an `Array` of numbers | -| epsilon | `[0.01, 0.125, 0.5, 1]` | For `EPSILON_SVR`. Can be a `Number` or an `Array` of numbers | -| degree | `[2,3,4]` | For `POLY` kernel. Can be a `Number` or an `Array` of numbers | -| gamma | `[0.001, 0.01, 0.125, 0.5]` | For `POLY`, `RBF` and `SIGMOID` kernels. Can be a `Number` or an `Array` of numbers | -| r | `[0.125, 0.5, 0, 1, 2]` | For `POLY` and `SIGMOID` kernels. Can be a `Number` or an `Array` of numbers | -| kFold | `4` | `k` parameter for [k-fold cross validation]( http://en.wikipedia.org/wiki/Cross-validation_(statistics)#k-fold_cross-validation). `k` must be >= 1. If `k===1` then entire dataset is use for both testing and training. | -| normalize | `true` | Whether to use [mean normalization](http://en.wikipedia.org/wiki/Normalization_(statistics)) during data pre-processing | -| reduce | `true` | Whether to use [PCA](http://en.wikipedia.org/wiki/Principal_component_analysis) to reduce dataset's dimensions during data pre-processing | -| retainedVariance | `0.99` | Define the acceptable impact on data integrity (require `reduce` to be `true`) | -| eps | `1e-3` | Tolerance of termination criterion | -| cacheSize | `1e2` | Cache size in MB. | -| shrinking | `true` | Whether to use the shrinking heuristics | -| probability | `false` | Whether to train a SVC or SVR model for probability estimates | +| Name | Default value(s) | Description | +|------------------|------------------------|-------------------------------------------------------------------------------------------------------| +| svmType | `C_SVC` | Used classifier | +| kernelType | `RBF` | Used kernel | +| c | `[0.01,0.125,0.5,1,2]` | Cost for `C_SVC`, `EPSILON_SVR` and `NU_SVR`. Can be a `Number` or an `Array` of numbers | +| nu | `[0.01,0.125,0.5,1]` | For `NU_SVC`, `ONE_CLASS` and `NU_SVR`. Can be a `Number` or an `Array` of numbers | +| epsilon | `[0.01,0.125,0.5,1]` | For `EPSILON_SVR`. Can be a `Number` or an `Array` of numbers | +| degree | `[2,3,4]` | For `POLY` kernel. Can be a `Number` or an `Array` of numbers | +| gamma | `[0.001,0.01,0.5]` | For `POLY`, `RBF` and `SIGMOID` kernels. Can be a `Number` or an `Array` of numbers | +| r | `[0.125,0.5,0,1]` | For `POLY` and `SIGMOID` kernels. Can be a `Number` or an `Array` of numbers | +| kFold | `4` | `k` parameter for [k-fold cross validation]( http://en.wikipedia.org/wiki/Cross-validation_(statistics)#k-fold_cross-validation). `k` must be >= 1. If `k===1` then entire dataset is use for both testing and training. | +| normalize | `true` | Whether to use [mean normalization](http://en.wikipedia.org/wiki/Normalization_(statistics)) during data pre-processing | +| reduce | `true` | Whether to use [PCA](http://en.wikipedia.org/wiki/Principal_component_analysis) to reduce dataset's dimensions during data pre-processing | +| retainedVariance | `0.99` | Define the acceptable impact on data integrity (require `reduce` to be `true`) | +| eps | `1e-3` | Tolerance of termination criterion | +| cacheSize | `1e2` | Cache size in MB. | +| shrinking | `true` | Whether to use the shrinking heuristics | +| probability | `false` | Whether to train a SVC or SVR model for probability estimates | The example below shows how to use them: @@ -128,7 +128,9 @@ var clf = new svm.SVM({ }); ``` -__Note__ : If at least one parameter has multiple values, [node-svm](https://github.com/nicolaspanel/node-svm/) will go through all possible combinations to see which one gives the best predictions (it performs grid-search to maximize [f-score](http://en.wikipedia.org/wiki/F1_score) for classification and minimize [Mean Squared Error](http://en.wikipedia.org/wiki/Mean_squared_error) for regression). +__Notes__ : + * If at least one parameter has multiple values, [node-svm](https://github.com/nicolaspanel/node-svm/) will go through all possible combinations to see which one gives the best predictions (it performs grid-search to maximize [f-score](http://en.wikipedia.org/wiki/F1_score) for classification and minimize [Mean Squared Error](http://en.wikipedia.org/wiki/Mean_squared_error) for regression). + * You can override default values using an `.nodesvmrc` file (JSON). ##Training diff --git a/lib/core/default-options.js b/lib/core/default-options.js index 6634f04..879501d 100644 --- a/lib/core/default-options.js +++ b/lib/core/default-options.js @@ -10,11 +10,11 @@ module.exports = { // kernels parameters 'kernel-type': kernels.RBF, 'degree': [2,3,4], // for POLY kernel - 'gamma': [0.001, 0.01, 0.125, 0.5], // for POLY, RBF and SIGMOID kernels - 'r': [0.125, 0.5, 0, 1, 2], // for POLY and SIGMOID kernels + 'gamma': [0.001, 0.01, 0.5], // for POLY, RBF and SIGMOID kernels + 'r': [0.125, 0.5, 0, 1], // for POLY and SIGMOID kernels // SVM specific parameters - 'c': [0.01, 0.125, 0.5, 2], // cost for C_SVC, EPSILON_SVR and NU_SVR + 'c': [0.01, 0.125, 0.5, 1, 2], // cost for C_SVC, EPSILON_SVR and NU_SVR 'nu': [0.01, 0.125, 0.5, 1], // for NU_SVC, ONE_CLASS and NU_SVR 'epsilon': [0.01, 0.125, 0.5, 1], // for EPSILON-SVR diff --git a/test/core/config.spec.js b/test/core/config.spec.js index 21d4ec7..b84ae55 100644 --- a/test/core/config.spec.js +++ b/test/core/config.spec.js @@ -19,9 +19,9 @@ describe('Config', function () { expect(config.svmType).to.be(svmTypes.C_SVC); expect(config.kernelType).to.be(kernelTypes.RBF); expect(config.degree).to.eql([]); - expect(config.gamma).to.eql([0.001, 0.03125, 0.125, 0.5, 1]); + expect(config.gamma).to.eql([ 0.001, 0.01, 0.5 ]); expect(config.r).to.eql([]); - expect(config.c).to.eql([0.03125, 0.125, 0.5, 2, 8]); + expect(config.c).to.eql([ 0.01, 0.125, 0.5, 1, 2 ]); expect(config.nu).to.eql([]); expect(config.epsilon).to.eql([]); }); @@ -55,10 +55,10 @@ describe('Config', function () { expect(config.svmType).to.be(svmTypes.NU_SVC); expect(config.kernelType).to.be(kernelTypes.RBF); expect(config.degree).to.eql([]); - expect(config.gamma).to.eql([0.001, 0.03125, 0.125, 0.5, 1]); + expect(config.gamma).to.eql([ 0.001, 0.01, 0.5 ]); expect(config.r).to.eql([]); expect(config.c).to.eql([]); - expect(config.nu).to.eql([0.03125, 0.125, 0.5, 0.75, 1]); + expect(config.nu).to.eql([ 0.01, 0.125, 0.5, 1 ]); expect(config.epsilon).to.eql([]); }); @@ -76,11 +76,11 @@ describe('Config', function () { expect(config.svmType).to.be(svmTypes.EPSILON_SVR); expect(config.kernelType).to.be(kernelTypes.RBF); expect(config.degree).to.eql([]); - expect(config.gamma).to.eql([0.001, 0.03125, 0.125, 0.5, 1]); + expect(config.gamma).to.eql([ 0.001, 0.01, 0.5 ]); expect(config.r).to.eql([]); - expect(config.c).to.eql([0.03125, 0.125, 0.5, 2, 8]); + expect(config.c).to.eql([ 0.01, 0.125, 0.5, 1, 2 ]); expect(config.nu).to.eql([]); - expect(config.epsilon).to.eql([0.03125, 0.125, 0.5, 2, 8]); + expect(config.epsilon).to.eql([ 0.01, 0.125, 0.5, 1 ]); }); }); @@ -98,10 +98,10 @@ describe('Config', function () { expect(config.svmType).to.be(svmTypes.NU_SVR); expect(config.kernelType).to.be(kernelTypes.RBF); expect(config.degree).to.eql([]); - expect(config.gamma).to.eql([0.001, 0.03125, 0.125, 0.5, 1]); + expect(config.gamma).to.eql([ 0.001, 0.01, 0.5 ]); expect(config.r).to.eql([]); - expect(config.c).to.eql([0.03125, 0.125, 0.5, 2, 8]); - expect(config.nu).to.eql([0.03125, 0.125, 0.5, 0.75, 1]); + expect(config.c).to.eql([ 0.01, 0.125, 0.5, 1, 2 ]); + expect(config.nu).to.eql([ 0.01, 0.125, 0.5, 1 ]); expect(config.epsilon).to.eql([]); }); @@ -122,7 +122,7 @@ describe('Config', function () { expect(config.degree).to.eql([]); expect(config.gamma).to.eql([]); expect(config.r).to.eql([]); - expect(config.c).to.eql([0.03125, 0.125, 0.5, 2, 8]); + expect(config.c).to.eql([ 0.01, 0.125, 0.5, 1, 2 ]); expect(config.nu).to.eql([]); expect(config.epsilon).to.eql([]); }); @@ -141,9 +141,9 @@ describe('Config', function () { expect(config.svmType).to.be(svmTypes.C_SVC); expect(config.kernelType).to.be(kernelTypes.POLY); expect(config.degree).to.eql([2,3,4]); - expect(config.gamma).to.eql([0.001, 0.03125, 0.125, 0.5, 1]); - expect(config.r).to.eql([0.125, 0.5, 0, 1, 2, 8]); - expect(config.c).to.eql([0.03125, 0.125, 0.5, 2, 8]); + expect(config.gamma).to.eql([ 0.001, 0.01, 0.5 ]); + expect(config.r).to.eql([0.125, 0.5, 0, 1]); + expect(config.c).to.eql([ 0.01, 0.125, 0.5, 1, 2 ]); expect(config.nu).to.eql([]); expect(config.epsilon).to.eql([]); }); @@ -162,9 +162,9 @@ describe('Config', function () { expect(config.svmType).to.be(svmTypes.C_SVC); expect(config.kernelType).to.be(kernelTypes.SIGMOID); expect(config.degree).to.eql([]); - expect(config.gamma).to.eql([0.001, 0.03125, 0.125, 0.5, 1]); - expect(config.r).to.eql([0.125, 0.5, 0, 1, 2, 8]); - expect(config.c).to.eql([0.03125, 0.125, 0.5, 2, 8]); + expect(config.gamma).to.eql([ 0.001, 0.01, 0.5 ]); + expect(config.r).to.eql([0.125, 0.5, 0, 1]); + expect(config.c).to.eql([ 0.01, 0.125, 0.5, 1, 2 ]); expect(config.nu).to.eql([]); expect(config.epsilon).to.eql([]); });