Skip to content

Commit

Permalink
Merge pull request #44 from all-contributors/dev
Browse files Browse the repository at this point in the history
feat: custom classes and easier plotting/charting time
  • Loading branch information
Berkmann18 authored Aug 18, 2020
2 parents 37bfe27 + 7a7abbf commit ba93072
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 38 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ NodeJS Classification-based learner.
- `opts.pastTrainingSamples`
**[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>**
Past training samples for the classifier (optional, default `[]`)
- `opts.classes`
**[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
List of classes (categories) (optional, default `require('./categories')`)

#### Examples

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"doc:lint": "documentation lint src/index.js",
"doc:gen": "documentation readme src/index.js -s Documentation",
"doc": "yarn doc:lint && yarn doc:gen",
"prepare": "snyk protect"
"prepare": "snyk protect",
"open": "concurrently \"serve -d .\" \"xdg-open http://localhost:5000/public/\""
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -55,6 +56,7 @@
"devDependencies": {
"anychart-nodejs": "^1.3.8",
"codecov": "^3.7.2",
"concurrently": "^5.3.0",
"cz-conventional-changelog": "^3.2.0",
"documentation": "^13.0.2",
"eslint-config-kentcdodds": "^14.14.2",
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const spinner = new Spinner('Loading...', [
* @param {number} [opts.splits=[.7, .15]] Dataset split percentage for the training/validation set (default: 70%/15%/15%)
* @param {function(): Object} [opts.classifier=classifierBuilder] Classifier builder function
* @param {Object[]} [opts.pastTrainingSamples=[]] Past training samples for the classifier
* @param {string[]} [opts.classes=require('./categories')] List of classes (categories)
* @example <caption>Using pre-defined data</caption>
* const learner = new Learner()
* @example <caption>Using a custom dataset</caption>
Expand All @@ -54,6 +55,7 @@ class Learner {
splits = [0.7, 0.15],
classifier = classifierBuilder,
pastTrainingSamples = [],
classes = categories,
} = {}) {
this.dataset = dataset
const [train, validation, _test] = tvts(dataset, ...splits)
Expand All @@ -64,6 +66,7 @@ class Learner {
this.classifier = classifier(pastTrainingSamples)
this.classifierBuilder = classifier
this.confusionMatrix = null //new ConfusionMatrix(categories)
this.classes = classes
}

/**
Expand Down Expand Up @@ -115,7 +118,7 @@ class Learner {
this.confusionMatrix = ConfusionMatrix.fromData(
actual,
predicted,
categories,
this.classes,
)

const completeMsg = 'Evaluation complete'
Expand Down Expand Up @@ -321,7 +324,7 @@ class Learner {
spinner.message('Generating category partitions...')
spinner.start()
const res = {}
categories.forEach(cat => {
this.classes.forEach(cat => {
res[cat] = {
overall: 0,
test: 0,
Expand Down
43 changes: 8 additions & 35 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4401,7 +4401,7 @@ concat-stream@~1.5.0:
readable-stream "~2.0.0"
typedarray "~0.0.5"

concurrently@^5.2.0:
concurrently@^5.2.0, concurrently@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-5.3.0.tgz#7500de6410d043c912b2da27de3202cb489b1e7b"
integrity sha512-8MhqOB6PWlBfA2vJ8a0bSFKATOdWlHiQlk11IfmQBPaHVP8oP2gsh2MObE6UR3hqDHqvaIvLTyceNW6obVuFHQ==
Expand Down Expand Up @@ -4899,7 +4899,7 @@ debug@^3.1.0, debug@^3.2.5, debug@^3.2.6:
dependencies:
ms "^2.1.1"

debuglog@*, debuglog@^1.0.1:
debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
Expand Down Expand Up @@ -7412,7 +7412,7 @@ import-local@^3.0.2:
pkg-dir "^4.2.0"
resolve-cwd "^3.0.0"

imurmurhash@*, imurmurhash@^0.1.4:
imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
Expand Down Expand Up @@ -9317,11 +9317,6 @@ lockfile@^1.0.4:
dependencies:
signal-exit "^3.0.2"

lodash._baseindexof@*:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=

lodash._baseuniq@~4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
Expand All @@ -9330,33 +9325,11 @@ lodash._baseuniq@~4.6.0:
lodash._createset "~4.0.0"
lodash._root "~3.0.0"

lodash._bindcallback@*:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4=

lodash._cacheindexof@*:
version "3.0.2"
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=

lodash._createcache@*:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
dependencies:
lodash._getnative "^3.0.0"

lodash._createset@~4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=

lodash._getnative@*, lodash._getnative@^3.0.0:
version "3.9.1"
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=

lodash._root@~3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._root/-/lodash._root-3.0.1.tgz#fba1c4524c19ee9a5f8136b4609f017cf4ded692"
Expand Down Expand Up @@ -9492,11 +9465,6 @@ lodash.reduce@^4.6.0:
resolved "https://registry.yarnpkg.com/lodash.reduce/-/lodash.reduce-4.6.0.tgz#f1ab6b839299ad48f784abbf476596f03b914d3b"
integrity sha1-8atrg5KZrUj3hKu/R2WW8DuRTTs=

lodash.restparam@*:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=

lodash.set@^4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
Expand Down Expand Up @@ -10097,6 +10065,11 @@ minimist-options@^3.0.1:
arrify "^1.0.1"
is-plain-obj "^1.1.0"

[email protected]:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=

[email protected], minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
Expand Down

0 comments on commit ba93072

Please sign in to comment.