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
I am encountering a TypeError when trying to use a deserialized RandomForestClassifier. The error occurs when calling predictProbability on the rehydrated classifier, specifically in the DecisionTreeClassifier:
DecisionTreeClassifier.js:58 Uncaught (in promise) TypeError: this.root.classify(...).maxRowIndex is not a function
at _DecisionTreeClassifier.predict (DecisionTreeClassifier.js:58:10)
at _RandomForestClassifier.predictionValues (RandomForestBase.js:288:48)
at _RandomForestClassifier.predictProbability (RandomForestClassifier.js:111:35)
Steps to Reproduce:
Serialize a RandomForestClassifier using toJSON():
The deserialized RandomForestClassifier should properly function, and the estimators (decision trees) should be rehydrated as instances of DecisionTreeClassifier, allowing predict() to work correctly.
Actual Behavior:
The estimators array contains objects but they do not have the predict() method, and calling predictProbability throws the following error:
TypeError: this.root.classify(...).maxRowIndex is not a function
Cause:
It seems that during deserialization, the estimators (which are instances of DecisionTreeClassifier) are being restored as plain JSON objects, losing their methods such as predict() and classify(). This leads to the failure when the classifier tries to call methods on these objects.
Possible Fix:
To fix this, each estimator in the estimators array needs to be rehydrated as an instance of DecisionTreeClassifier after deserialization. For example:
classifier.estimators=classifierModel.baseModel.estimators.map(estimator=>{returnDecisionTreeClassifier.load(estimator);// Rehydrate each estimator});
Environment:
Package: ml-random-forest
Version: 2.1.0
Additional Context:
The deserialization works fine up to the point where it reaches the estimators. The issue arises when trying to call methods on these deserialized objects, which are missing their expected methods.
The text was updated successfully, but these errors were encountered:
Description:
I am encountering a
TypeError
when trying to use a deserializedRandomForestClassifier
. The error occurs when callingpredictProbability
on the rehydrated classifier, specifically in theDecisionTreeClassifier
:Steps to Reproduce:
Serialize a
RandomForestClassifier
usingtoJSON()
:Deserialize the
RandomForestClassifier
usingload()
:Call
predictProbability()
on the deserializedRandomForestClassifier
:Expected Behavior:
The deserialized
RandomForestClassifier
should properly function, and theestimators
(decision trees) should be rehydrated as instances ofDecisionTreeClassifier
, allowingpredict()
to work correctly.Actual Behavior:
The
estimators
array contains objects but they do not have thepredict()
method, and callingpredictProbability
throws the following error:Cause:
It seems that during deserialization, the
estimators
(which are instances ofDecisionTreeClassifier
) are being restored as plain JSON objects, losing their methods such aspredict()
andclassify()
. This leads to the failure when the classifier tries to call methods on these objects.Possible Fix:
To fix this, each estimator in the
estimators
array needs to be rehydrated as an instance ofDecisionTreeClassifier
after deserialization. For example:Environment:
ml-random-forest
2.1.0
Additional Context:
The deserialization works fine up to the point where it reaches the
estimators
. The issue arises when trying to call methods on these deserialized objects, which are missing their expected methods.The text was updated successfully, but these errors were encountered: