Refefer / fastxml

FastXML / PFastXML / PFastreXML - Implementation of Extreme Multi-label Classification
Other
149 stars 47 forks source link

ValueError: Buffer dtype mismatch, expected 'float32_t' but got 'double' #35

Closed pankaj-kvhld closed 3 years ago

pankaj-kvhld commented 3 years ago

Using the code below I succeeded in training and saving the model:

trainer = Trainer(n_trees=64, n_jobs=-1)
trainer.fit(X_tr, y)
trainer.save("../models/model_64_trees")

However when I try to predict, even on the very set it was trained (X_tr), by running the code below:

clf = Inferencer("../models/model_64_trees")
y_train_preds = clf.predict(X_tr, fmt='dict')

I get the following error (with traceback):

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-21-19b6d12937ec> in <module>
----> 1 y_train_preds = clf.predict(X_tr, fmt='dict')

c:\pankaj\projects\00-learning\python\fastxml\fastxml\fastxml\fastxml.py in predict(self, X, fmt)
     37             Xi = X[i]
     38             mean = self.predictor.predict(Xi.data, Xi.indices, 
---> 39                     self.blend, self.gamma, self.leaf_probs)
     40 
     41             if fmt == 'sparse':

c:\pankaj\projects\00-learning\python\fastxml\fastxml\fastxml\inferencer.pyx in fastxml.inferencer.IForestBlender.predict()

ValueError: Buffer dtype mismatch, expected 'float32_t' but got 'double'

Environment:

numpy                     1.19.2                   pypi_0    pypi
numpy-base                1.19.1           py36ha3acd2a_0
scipy                     1.5.3                    pypi_0    pypi
scikit-learn              0.23.2                   pypi_0    pypi
cython                    0.29.21                  pypi_0    pypi

How to fix this error?

Refefer commented 3 years ago

FastXML uses 32-bit floats to keep the model size in check; try casting your X to 'float32' and see if that solves the problem.

On Tue, Oct 20, 2020 at 12:52 PM pankaj-kvhld notifications@github.com wrote:

Using the code below I succeeded in training and saving the model:

trainer = Trainer(n_trees=64, n_jobs=-1) trainer.fit(X_tr, y) trainer.save("../models/model_64_trees")

However when I try to predict, even on the very set it was trained (X_tr), by running the code below:

clf = Inferencer("../models/model_64_trees") y_train_preds = clf.predict(X_tr, fmt='dict')

I get the following error (with traceback):


ValueError Traceback (most recent call last)

in ----> 1 y_train_preds = clf.predict(X_tr, fmt='dict') c:\pankaj\projects\00-learning\python\fastxml\fastxml\fastxml\fastxml.py in predict(self, X, fmt) 37 Xi = X[i] 38 mean = self.predictor.predict(Xi.data, Xi.indices, ---> 39 self.blend, self.gamma, self.leaf_probs) 40 41 if fmt == 'sparse': c:\pankaj\projects\00-learning\python\fastxml\fastxml\fastxml\inferencer.pyx in fastxml.inferencer.IForestBlender.predict() ValueError: Buffer dtype mismatch, expected 'float32_t' but got 'double' Environment: numpy 1.19.2 pypi_0 pypi numpy-base 1.19.1 py36ha3acd2a_0 scipy 1.5.3 pypi_0 pypi scikit-learn 0.23.2 pypi_0 pypi cython 0.29.21 pypi_0 pypi How to fix this error? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or unsubscribe .
pankaj-kvhld commented 3 years ago

Wonderful, I was not casting the training data as float32. Thank you very much.