Skip to content

Commit

Permalink
fix some metrics feature types (#867)
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoestq authored Nov 19, 2020
1 parent e983e49 commit 7478935
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 12 deletions.
21 changes: 18 additions & 3 deletions metrics/accuracy/accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,37 @@
accuracy: Accuracy score.
"""

_CITATION = """\
@article{scikit-learn,
title={Scikit-learn: Machine Learning in {P}ython},
author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.
and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.
and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and
Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},
journal={Journal of Machine Learning Research},
volume={12},
pages={2825--2830},
year={2011}
}
"""


class Accuracy(datasets.Metric):
def _info(self):
return datasets.MetricInfo(
description=_DESCRIPTION,
citation=_CITATION,
inputs_description=_KWARGS_DESCRIPTION,
features=datasets.Features(
{
"predictions": datasets.Value("int"),
"references": datasets.Value("int"),
"predictions": datasets.Value("int32"),
"references": datasets.Value("int32"),
}
),
reference_urls=["https://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html"],
)

def _compute(self, predictions, references, normalize=True, sample_weight=None):
return {
"accuracy": accuracy_score(references, predictions, normalize, sample_weight),
"accuracy": accuracy_score(references, predictions, normalize=normalize, sample_weight=sample_weight),
}
28 changes: 25 additions & 3 deletions metrics/f1/f1.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,44 @@
f1: F1 score.
"""

_CITATION = """\
@article{scikit-learn,
title={Scikit-learn: Machine Learning in {P}ython},
author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.
and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.
and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and
Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},
journal={Journal of Machine Learning Research},
volume={12},
pages={2825--2830},
year={2011}
}
"""


class F1(datasets.Metric):
def _info(self):
return datasets.MetricInfo(
description=_DESCRIPTION,
citation=_CITATION,
inputs_description=_KWARGS_DESCRIPTION,
features=datasets.Features(
{
"predictions": datasets.Value("int"),
"references": datasets.Value("int"),
"predictions": datasets.Value("int32"),
"references": datasets.Value("int32"),
}
),
reference_urls=["https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html"],
)

def _compute(self, predictions, references, labels=None, pos_label=1, average="binary", sample_weight=None):
return {
"f1": f1_score(references, predictions, labels, pos_label, average, sample_weight),
"f1": f1_score(
references,
predictions,
labels=labels,
pos_label=pos_label,
average=average,
sample_weight=sample_weight,
),
}
28 changes: 25 additions & 3 deletions metrics/precision/precision.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,44 @@
precision: Precision score.
"""

_CITATION = """\
@article{scikit-learn,
title={Scikit-learn: Machine Learning in {P}ython},
author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.
and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.
and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and
Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},
journal={Journal of Machine Learning Research},
volume={12},
pages={2825--2830},
year={2011}
}
"""


class Precision(datasets.Metric):
def _info(self):
return datasets.MetricInfo(
description=_DESCRIPTION,
citation=_CITATION,
inputs_description=_KWARGS_DESCRIPTION,
features=datasets.Features(
{
"predictions": datasets.Value("int"),
"references": datasets.Value("int"),
"predictions": datasets.Value("int32"),
"references": datasets.Value("int32"),
}
),
reference_urls=["https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html"],
)

def _compute(self, predictions, references, labels=None, pos_label=1, average="binary", sample_weight=None):
return {
"precision": precision_score(references, predictions, labels, pos_label, average, sample_weight),
"precision": precision_score(
references,
predictions,
labels=labels,
pos_label=pos_label,
average=average,
sample_weight=sample_weight,
),
}
28 changes: 25 additions & 3 deletions metrics/recall/recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,44 @@
recall: Recall score.
"""

_CITATION = """\
@article{scikit-learn,
title={Scikit-learn: Machine Learning in {P}ython},
author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.
and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.
and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and
Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},
journal={Journal of Machine Learning Research},
volume={12},
pages={2825--2830},
year={2011}
}
"""


class Recall(datasets.Metric):
def _info(self):
return datasets.MetricInfo(
description=_DESCRIPTION,
citation=_CITATION,
inputs_description=_KWARGS_DESCRIPTION,
features=datasets.Features(
{
"predictions": datasets.Value("int"),
"references": datasets.Value("int"),
"predictions": datasets.Value("int32"),
"references": datasets.Value("int32"),
}
),
reference_urls=["https://scikit-learn.org/stable/modules/generated/sklearn.metrics.recall_score.html"],
)

def _compute(self, predictions, references, labels=None, pos_label=1, average="binary", sample_weight=None):
return {
"recall": recall_score(references, predictions, labels, pos_label, average, sample_weight),
"recall": recall_score(
references,
predictions,
labels=labels,
pos_label=pos_label,
average=average,
sample_weight=sample_weight,
),
}

1 comment on commit 7478935

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show benchmarks

PyArrow==0.17.1

Show updated benchmarks!

Benchmark: benchmark_array_xd.json

metric read_batch_formatted_as_numpy after write_array2d read_batch_formatted_as_numpy after write_flattened_sequence read_batch_formatted_as_numpy after write_nested_sequence read_batch_unformated after write_array2d read_batch_unformated after write_flattened_sequence read_batch_unformated after write_nested_sequence read_col_formatted_as_numpy after write_array2d read_col_formatted_as_numpy after write_flattened_sequence read_col_formatted_as_numpy after write_nested_sequence read_col_unformated after write_array2d read_col_unformated after write_flattened_sequence read_col_unformated after write_nested_sequence read_formatted_as_numpy after write_array2d read_formatted_as_numpy after write_flattened_sequence read_formatted_as_numpy after write_nested_sequence read_unformated after write_array2d read_unformated after write_flattened_sequence read_unformated after write_nested_sequence write_array2d write_flattened_sequence write_nested_sequence
new / old (diff) 0.017844 / 0.011353 (0.006491) 0.015536 / 0.011008 (0.004528) 0.042503 / 0.038508 (0.003995) 0.030153 / 0.023109 (0.007044) 0.200827 / 0.275898 (-0.075071) 0.213049 / 0.323480 (-0.110431) 0.008681 / 0.007986 (0.000695) 0.003938 / 0.004328 (-0.000390) 0.006112 / 0.004250 (0.001861) 0.045354 / 0.037052 (0.008301) 0.205079 / 0.258489 (-0.053410) 0.221404 / 0.293841 (-0.072437) 0.156206 / 0.128546 (0.027660) 0.120418 / 0.075646 (0.044772) 0.444253 / 0.419271 (0.024982) 0.533487 / 0.043533 (0.489954) 0.204176 / 0.255139 (-0.050963) 0.212229 / 0.283200 (-0.070971) 0.090419 / 0.141683 (-0.051264) 1.710184 / 1.452155 (0.258029) 1.800692 / 1.492716 (0.307976)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.037277 / 0.037411 (-0.000134) 0.020510 / 0.014526 (0.005985) 0.107140 / 0.176557 (-0.069417) 0.473643 / 0.737135 (-0.263492) 0.185162 / 0.296338 (-0.111176)

Benchmark: benchmark_iterating.json

metric read 5000 read 50000 read_batch 50000 10 read_batch 50000 100 read_batch 50000 1000 read_formatted numpy 5000 read_formatted pandas 5000 read_formatted tensorflow 5000 read_formatted torch 5000 read_formatted_batch numpy 5000 10 read_formatted_batch numpy 5000 1000 shuffled read 5000 shuffled read 50000 shuffled read_batch 50000 10 shuffled read_batch 50000 100 shuffled read_batch 50000 1000 shuffled read_formatted numpy 5000 shuffled read_formatted_batch numpy 5000 10 shuffled read_formatted_batch numpy 5000 1000
new / old (diff) 0.244638 / 0.215209 (0.029429) 2.034887 / 2.077655 (-0.042767) 1.212993 / 1.504120 (-0.291127) 1.101550 / 1.541195 (-0.439645) 1.148735 / 1.468490 (-0.319755) 6.874241 / 4.584777 (2.289464) 5.875137 / 3.745712 (2.129425) 8.175592 / 5.269862 (2.905731) 7.095605 / 4.565676 (2.529928) 0.682402 / 0.424275 (0.258126) 0.011246 / 0.007607 (0.003639) 0.225467 / 0.226044 (-0.000577) 2.352654 / 2.268929 (0.083725) 1.637370 / 55.444624 (-53.807254) 1.519935 / 6.876477 (-5.356541) 1.495942 / 2.142072 (-0.646130) 6.855903 / 4.805227 (2.050676) 8.474638 / 6.500664 (1.973974) 8.574949 / 0.075469 (8.499480)

Benchmark: benchmark_map_filter.json

metric filter map fast-tokenizer batched map identity map identity batched map no-op batched map no-op batched numpy map no-op batched pandas map no-op batched pytorch map no-op batched tensorflow
new / old (diff) 11.579421 / 1.841788 (9.737633) 13.610418 / 8.074308 (5.536110) 15.672732 / 10.191392 (5.481340) 0.487766 / 0.680424 (-0.192658) 0.287504 / 0.534201 (-0.246697) 0.842991 / 0.579283 (0.263708) 0.667814 / 0.434364 (0.233451) 0.839785 / 0.540337 (0.299448) 1.645435 / 1.386936 (0.258499)
PyArrow==1.0
Show updated benchmarks!

Benchmark: benchmark_array_xd.json

metric read_batch_formatted_as_numpy after write_array2d read_batch_formatted_as_numpy after write_flattened_sequence read_batch_formatted_as_numpy after write_nested_sequence read_batch_unformated after write_array2d read_batch_unformated after write_flattened_sequence read_batch_unformated after write_nested_sequence read_col_formatted_as_numpy after write_array2d read_col_formatted_as_numpy after write_flattened_sequence read_col_formatted_as_numpy after write_nested_sequence read_col_unformated after write_array2d read_col_unformated after write_flattened_sequence read_col_unformated after write_nested_sequence read_formatted_as_numpy after write_array2d read_formatted_as_numpy after write_flattened_sequence read_formatted_as_numpy after write_nested_sequence read_unformated after write_array2d read_unformated after write_flattened_sequence read_unformated after write_nested_sequence write_array2d write_flattened_sequence write_nested_sequence
new / old (diff) 0.018084 / 0.011353 (0.006731) 0.015602 / 0.011008 (0.004594) 0.045598 / 0.038508 (0.007090) 0.034831 / 0.023109 (0.011722) 0.328479 / 0.275898 (0.052581) 0.377573 / 0.323480 (0.054093) 0.009331 / 0.007986 (0.001345) 0.004331 / 0.004328 (0.000003) 0.006272 / 0.004250 (0.002021) 0.052895 / 0.037052 (0.015843) 0.342183 / 0.258489 (0.083694) 0.380292 / 0.293841 (0.086451) 0.150968 / 0.128546 (0.022422) 0.121087 / 0.075646 (0.045440) 0.409753 / 0.419271 (-0.009519) 0.407848 / 0.043533 (0.364315) 0.351795 / 0.255139 (0.096656) 0.367297 / 0.283200 (0.084097) 0.082070 / 0.141683 (-0.059613) 1.669801 / 1.452155 (0.217647) 1.717758 / 1.492716 (0.225042)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.042684 / 0.037411 (0.005272) 0.026039 / 0.014526 (0.011513) 0.033030 / 0.176557 (-0.143526) 0.089693 / 0.737135 (-0.647443) 0.049508 / 0.296338 (-0.246831)

Benchmark: benchmark_iterating.json

metric read 5000 read 50000 read_batch 50000 10 read_batch 50000 100 read_batch 50000 1000 read_formatted numpy 5000 read_formatted pandas 5000 read_formatted tensorflow 5000 read_formatted torch 5000 read_formatted_batch numpy 5000 10 read_formatted_batch numpy 5000 1000 shuffled read 5000 shuffled read 50000 shuffled read_batch 50000 10 shuffled read_batch 50000 100 shuffled read_batch 50000 1000 shuffled read_formatted numpy 5000 shuffled read_formatted_batch numpy 5000 10 shuffled read_formatted_batch numpy 5000 1000
new / old (diff) 0.266033 / 0.215209 (0.050824) 2.931874 / 2.077655 (0.854220) 1.946439 / 1.504120 (0.442319) 1.749709 / 1.541195 (0.208515) 1.732648 / 1.468490 (0.264157) 6.681099 / 4.584777 (2.096323) 5.736920 / 3.745712 (1.991208) 8.024776 / 5.269862 (2.754914) 7.023963 / 4.565676 (2.458287) 0.668430 / 0.424275 (0.244155) 0.011841 / 0.007607 (0.004234) 0.300809 / 0.226044 (0.074764) 2.922510 / 2.268929 (0.653582) 2.190529 / 55.444624 (-53.254095) 2.037535 / 6.876477 (-4.838941) 2.044548 / 2.142072 (-0.097524) 6.741624 / 4.805227 (1.936396) 6.041890 / 6.500664 (-0.458774) 6.865497 / 0.075469 (6.790028)

Benchmark: benchmark_map_filter.json

metric filter map fast-tokenizer batched map identity map identity batched map no-op batched map no-op batched numpy map no-op batched pandas map no-op batched pytorch map no-op batched tensorflow
new / old (diff) 11.925014 / 1.841788 (10.083226) 13.939065 / 8.074308 (5.864757) 17.441761 / 10.191392 (7.250369) 1.096450 / 0.680424 (0.416026) 0.552846 / 0.534201 (0.018645) 0.790178 / 0.579283 (0.210895) 0.596488 / 0.434364 (0.162124) 0.771404 / 0.540337 (0.231067) 1.590631 / 1.386936 (0.203695)

CML watermark

Please sign in to comment.