zemlyansky / random-forest Goto Github PK
View Code? Open in Web Editor NEWRandom forests ported to Javascript with WebAssembly and WebWorkers
Random forests ported to Javascript with WebAssembly and WebWorkers
TypeError: Cannot read properties of undefined (reading 'transform')
at RandomForestClassifier.predict (/Users/alasdairbarrie/tradingBots/fantomSimulator/node_modules/random-forest/src/base.js:66:25)
at module.exports (/Users/alasdairbarrie/tradingBots/fantomSimulator/fun/randomForestClassifier.js:218:32)
at module.exports (/Users/alasdairbarrie/tradingBots/fantomSimulator/fun/strategyBuilder.js:312:19)
at module.exports (/Users/alasdairbarrie/tradingBots/fantomSimulator/fun/simulator.js:28:28)
at signals (/Users/alasdairbarrie/tradingBots/fantomSimulator/index.js:39:11)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
TypeError: Cannot read properties of undefined (reading 'length')
TypeError: Cannot read properties of undefined (reading 'length')
My Data:
I am using BTCUSDT price data for this. I have added technical indicator features and removed the OHLCV.
I am using Danfo.js (js version of Pandas) to convert my data into a dataframe so its easier to manipulate it. It is then extracted back into data arrays before being used in the model.
The same dataset that was used to train the saved model is now being using on the loaded model...just a different section of the time series.
My Code:
/* ------------------------------ Define the train and test samples ----------------------------- */
let XTrain_Cols=[], XTest_Cols=[], yTrain_Cols=[], yTest_Cols=[];
XTrain_Cols = traindf.loc({ columns: ["ema0","ema1","rsi2","stochk0","stochd0","williamsR0","xBarHigh","xBarLow","historicalReturn1","historicalReturn5","distanceFromEma0","distanceFromEma1"]})['$data']; //
XTest_Cols = testdf.loc({ columns: ["ema0","ema1","rsi2","stochk0","stochd0","williamsR0","xBarHigh","xBarLow","historicalReturn1","historicalReturn5","distanceFromEma0","distanceFromEma1"]})['$data']; //
yTrain_Cols = traindf['Prediction']['$data'];
yTest_Cols = testdf['Prediction']['$data'];
/* -------------------------- Define new random forest classifier model ------------------------- */
const rfClassifier = new RandomForestClassifier({nEstimators: 400, maxDepth: 20, maxFeatures: 'auto', minSamplesLeaf: 10, minInfoGain: 0});
/* -------------------------------- Load a previously saved model ------------------------------- */
var modelName = `./models/rf-BTCUSDT-tf60m-acc0.8603871361073007-epoch1653977716111-ema90-ema140-rsi2-stochk9-stochd3-willr10-pb5-histret1-histret5-forret3-target0.02.model`
const modelLoaded = new Uint8Array(fs.readFileSync(modelName));
rfClassifier.load(modelLoaded);
/* --------------------------------------- Run predictions -------------------------------------- */
var yPred = rfClassifier.predict(XTest_Cols);
Behaviour:
Everything works completely fine when I save and load the model in the same run. It's when I dont train the model first and just try to load in the saved model I get this error.
Hello!
I am using this library to train a model on bit vectors of small molecules. However, I have had poor performance with similar hyperparameters. Any ideas as to how I could improve?
Regards,
Z
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 },
];
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.