cancel
Showing results for 
Search instead for 
Did you mean: 
Machine Learning
Dive into the world of machine learning on the Databricks platform. Explore discussions on algorithms, model training, deployment, and more. Connect with ML enthusiasts and experts.
cancel
Showing results for 
Search instead for 
Did you mean: 

One-hot encoding of strong cardinality features failing, causes downstream issues

rtreves
New Contributor II

Hi Databricks support,

I'm training an ML model using mlflow on DBR 13.3 LTS ML, Spark 3.4.1 using databricks.automl_runtime 0.2.17 and databricks.automl 1.20.3, with shap 0.45.1. My training data has two float-type columns with three or fewer unique values, which automl flags for one-hot encoding. My training experiment finishes without error. When I examined the notebook of the best-performing model, I toggled `shap_enabled` to `True` to see the shap values. However, in the cell that produces shap values, the following error is produced: "TypeError: no supported conversion for types: (dtype('O'),)" (full traceback attached). 

From my debugging, I believe the error occurs because the one-hot encoding of the two aforementioned columns fails, leading to object columns being passed to `scipy.sparse.csr_matrix` within the shap package. Indeed, when I go into the training notebook and try to fit the one-hot encoder to the two columns, I get the message "Warning: No categorical columns found. Calling 'transform' will only return input data."

Let me know if a full reprex is needed, and the best way to supply it.

Thanks in advance!

4 REPLIES 4

NandiniN
Honored Contributor
Honored Contributor

Hi @rtreves ,

TypeError: no supported conversion for types: (dtype('O'),)

error means you passed some data type that it doesn’t support, like categorical values (strings probably).

The function expects numeric values, and you provided non-numeric leading to this.

 

rtreves
New Contributor II

@NandiniN I've confirmed the features in question are passed in as pandas series with dtype float. Automl flags these features as potentially categorical precisely because they are passed in as numeric types but have few unique values.

NandiniN
Honored Contributor
Honored Contributor

You earlier mentioned you could share a repro. Can you please do that so that I can check further?

rtreves
New Contributor II

Hi @NandiniN , thanks for taking a look! I'm linking below a reprex notebook in two formats: .py for running as a databricks notebook on DBR LTS, and a .ipynb notebook for running as a jupyter notebook natively (though I haven't tested this format). Let me know if you have issues getting it running.

https://drive.google.com/drive/folders/1V5hMzGlP3-nxXQUc-g8Y2qhZ3hs40ENs?usp=sharing 

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!