random-forest
random-forest copied to clipboard
RuntimeError: memory access out of bounds
trafficstars
ERROR [ExceptionsHandler] memory access out of bounds
RuntimeError: memory access out of bounds
at null.<anonymous> (wasm://wasm/00020232:0:27521)
at null.<anonymous> (wasm://wasm/00020232:0:31175)
at null.<anonymous> (wasm://wasm/00020232:0:27022)
at m (wasm://wasm/00020232:0:25267)
.
.
.
My code
const data = [
{ value: 0, score: 0 },
{ value: 100, score: 10 },
{ value: 500, score: 20 },
{ value: 1000, score: 30 },
{ value: 5000, score: 40 },
{ value: 10000, score: 50 },
{ value: 20000, score: 60 },
{ value: 50000, score: 70 },
{ value: 70000, score: 80 },
{ value: 100000, score: 90 },
{ value: 150000, score: 100 },
{ value: 200000, score: 100 },
{ value: 300000, score: 100 },
{ value: 400000, score: 100 },
{ value: 500000, score: 100 },
];
// * train model
const rf = new RandomForestClassifier({
nEstimators: 100,
maxDepth: 10,
maxFeatures: 'auto',
minSamplesLeaf: 5,
minInfoGain: 0,
});
rf.train(
data.map((obj) => [obj.value]),
data.map((obj) => [obj.score]),
);
const ypred = rf.predict([value]);
return ypred;
Everything works fine if I change the score values to something like
const data = [
{ value: 0, score: 0 },
{ value: 100, score: 1 },
{ value: 500, score: 2 },
{ value: 1000, score: 3 },
{ value: 5000, score: 4 },
{ value: 10000, score: 5 },
{ value: 20000, score: 6 },
{ value: 50000, score: 7 },
{ value: 70000, score: 8 },
{ value: 100000, score: 9 },
{ value: 150000, score: 10 },
{ value: 200000, score: 10 },
{ value: 300000, score: 10 },
{ value: 400000, score: 10 },
{ value: 500000, score: 10 },
];
Perhaps, because you are using:
rf.train(
data.map((obj) => [obj.value]),
data.map((obj) => [obj.score]),
);
instead of
rf.train(
data.map((obj) => [obj.value]),
data.map((obj) => obj.score),
);
?