tensorflow / lattice

Lattice methods in TensorFlow

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

more than two classes in CannedClassifier

bjoernpiepenburg opened this issue · comments

Hi
I want to use a DLN to classify one label with 18 features. The label has more than two classes (something near to 30). If I set the n-classes parameter of the CannedClassifier-estimator to a number higher than 2 and start the training of the estimator I get the message "ValueError: Only 1-dimensional output is supported." (but I use just one label-column). If I reduce the number of classes in the data to two an set the n-classes parameter also to two, the training runs without any errors. Could the CannedClassifier-estimator just handle one label with two classes?
Thanks for your help...

Multi-class estimators typically have to have a separate logit output per class, and the predicted class is taken to be the highest value among them. We do not directly support multi-output models since the effect of monotonicity constraints are not well defined for such cases. You probably want the output for one class to be monotonically increasing in a feature while all other outputs should be decreasing in that feature.

A couple of things you can try:

  • Create a separate keras premade model for each class (with its own corresponding monotonicity constrains as explained above), and concatenate the outputs in a wrapper model. Then you can use a standard multi-class cross-entropy loss to train the combined model. This can be a bit tricky, but it's probably the "correct" way to create monotonic multi-class classifiers.
  • If your class labels have some ordinal meaning, maybe you can just use a regression model. Monotonicity constraints would then follow the label ordering logic.