Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use both AUCPR and AUC as metric for 'deeptable.fit' #81

Open
Jwenyi opened this issue Dec 15, 2022 · 1 comment
Open

How to use both AUCPR and AUC as metric for 'deeptable.fit' #81

Jwenyi opened this issue Dec 15, 2022 · 1 comment

Comments

@Jwenyi
Copy link

Jwenyi commented Dec 15, 2022

Hi there,
I'm trying to use AUCPR and AUC as metrics, so I defined the param of ModelConfig like metrics=[keras.metrics.AUC(name="AUCPR", curve='PR', num_thresholds=1000),keras.metrics.AUC(name="AUC", curve='ROC', num_thresholds=1000)] . However, it did not work and raised a error 'AttributeError: 'AUC' object has no attribute 'name''.
Besides, I would like to know how to input pre-defined validation data to DeepTable.fit. I read its source code and found no related description. Is it correct if I set validation_data = (val_x, val_y)?

I would be grateful for any suggestions!

Best,
Wenyi Jin

@oaksharks
Copy link
Collaborator

Hi @Jwenyi ,
Before, DeepTables accepts str or a callable function as metrics, that is why you encountered an error "'AttributeError: 'AUC' object has no attribute 'name'.", but now, it can also accept an instance of keras.metrics.Metric as the example:

def test_multiple_metrics(self):
from tensorflow import keras
# loading data
df = dsutils.load_bank()
df_train, df_test = train_test_split(df, test_size=0.9, random_state=42)
y = df_train.pop('y')
y_test = df_test.pop('y')
# training
config = deeptable.ModelConfig(earlystopping_patience=5, apply_class_weight=True,
metrics=[keras.metrics.AUC(name="AUCPR", curve='PR', num_thresholds=1000),
keras.metrics.AUC(name="AUC", curve='ROC', num_thresholds=1000)])
dt = deeptable.DeepTable(config=config)
model, history = dt.fit(df_train, y, batch_size=128, epochs=10)
# evaluation
result = dt.evaluate(df_test, y_test, verbose=0)
names = list(map(lambda m: m.upper(), result.keys()))
print('score:', result)
assert "AUCPR" in names
assert "AUC" in names

For the second question, you can really set validation data in this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants