File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -502,6 +502,18 @@ class NeuralNetworkData {
502
502
} ;
503
503
504
504
const uniqueVals = _uniqueValuesArray ; // [...new Set(this.data.raw.map(obj => obj.xs[prop]))]
505
+
506
+ // Validate that we have at least 2 classes for classification
507
+ if ( uniqueVals . length < 2 ) {
508
+ throw new Error (
509
+ `🟪 ml5.js classification error: Classification requires at least 2 different classes, but only found ${
510
+ uniqueVals . length
511
+ } class: "${
512
+ uniqueVals [ 0 ] || "undefined"
513
+ } ". Please add training data with multiple different output values.`
514
+ ) ;
515
+ }
516
+
505
517
// get back values from 0 to the length of the uniqueVals array
506
518
const onehotValues = uniqueVals . map ( ( item , idx ) => idx ) ;
507
519
// oneHot encode the values in the 1d tensor
You can’t perform that action at this time.
0 commit comments