Open lnicola opened 3 years ago
I suppose the problem is that CohenKappa doesn't work with one-hot vectors
It actually does. The only case where the current codebase doesn't work with OHE is when you convert OHE in case of a binary classification problem. Can you please confirm the number of labels in your data?
I have 49 labels, from 0 to 48.
Would a smaller example you could try help here?
Here's an example you can run:
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.utils import to_categorical
import tensorflow_addons
from tensorflow_addons.metrics import CohenKappa
x_training = np.array([[1, 1], [2, 2], [3, 3]])
x_validation = np.array([[4, 4], [5, 5], [6, 6]])
y_training = np.array([0, 1, 2])
y_validation = np.array([2, 2, 2])
model = Sequential([
Dense(5, input_shape=(2, )),
Dense(3, activation='softmax'),
])
model.compile(
loss='categorical_crossentropy',
#metrics=['categorical_accuracy'],
metrics=['categorical_accuracy', CohenKappa(3)],
)
model.fit(
x_training,
to_categorical(y_training),
epochs=10,
batch_size=64,
validation_data=(x_validation, to_categorical(y_validation))
)
I tried the code example and it works albeit with Cohen Kappa score as 0.
Maybe I'm running a different version? tensorflow-addons 0.13.0.dev0
from . EDIT: It's not from pip
pip
, for some reason that one didn't build for me. I built it from source.
Apologies, this might actually be my egregious lack of experience in this domain.
I've set up a little network to play with:
This works if I only use
accuracy
as a metric, but if I addCohenKappa
I get:I suppose the problem is that
CohenKappa
doesn't work with one-hot vectors (Accuracy
somehow detects them and callsCategoricalAccuracy
, doesn't it?).