Coder Social home page Coder Social logo

zemlyansky / random-forest Goto Github PK

View Code? Open in Web Editor NEW
19.0 4.0 3.0 352 KB

Random forests ported to Javascript with WebAssembly and WebWorkers

Makefile 3.42% JavaScript 82.63% HTML 0.60% C++ 10.40% C 2.96%
random-forest ensembles webassembly webworker multithreading

random-forest's People

Contributors

zemlyansky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

random-forest's Issues

Loaded Model - TypeError: Cannot read properties of undefined (reading 'transform')

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.

Poor Performance Compared to SciKit Learn

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

RuntimeError: memory access out of bounds

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 },
    ];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.