You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
const{Encoder}=require("random-forest/src/util");// .../* -------------------------------- Load a previously saved model ------------------------------- */varmodelName=`./models/rf-BTCUSDT-tf60m-acc0.8603871361073007-epoch1653977716111-ema90-ema140-rsi2-stochk9-stochd3-willr10-pb5-histret1-histret5-forret3-target0.02.model`constmodelLoaded=newUint8Array(fs.readFileSync(modelName));rfClassifier.load(modelLoaded);rfClassifier.Xencoder=newEncoder();rfClassifier.yencoder=newEncoder();// ...
Currently, Xencoder and yencoder are only initialized in train function, so if you never call it these fields will be undefined. I think the issue can be resolved if these fields are also initialized in constructor (and not in train anymore ?).
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:
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.
The text was updated successfully, but these errors were encountered: