Skip to content

Commit

Permalink
fix: do not error on empty array (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
micha-lmxt authored Oct 18, 2020
1 parent d3c4945 commit 2e88dee
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function giniImpurity(array) {
*/
export function getNumberOfClasses(array) {
return array
.filter(function(val, i, arr) {
.filter(function (val, i, arr) {
return arr.indexOf(val) === i;
})
.map((val) => val + 1)
Expand Down Expand Up @@ -85,6 +85,7 @@ export function giniGain(array, splitted) {
*/
export function squaredError(array) {
let l = array.length;
if (l === 0) { return 0.0; }

let m = meanArray(array);
let error = 0.0;
Expand Down

0 comments on commit 2e88dee

Please sign in to comment.