-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): implement type_of_target utility function in sklearn …
…frontend utils along with example based test. This function has repeated use in implementations
- Loading branch information
Showing
4 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import multiclass | ||
from .multiclass import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import ivy | ||
|
||
|
||
# reapeated utility function | ||
def type_of_target(y, input_name='y'): | ||
# purely utility function | ||
# TODO: implement multilabel-indicator, ...-multioutput, unknown | ||
if y.ndim not in (1, 2): | ||
return "unknown" | ||
if ivy.is_float_dtype(y) and ivy.any(ivy.not_equal(y, y.astype('int64'))): | ||
return "continuous" | ||
else: | ||
vals = ivy.unique_values(y) | ||
if len(vals) > 2: | ||
return "multiclass" | ||
else: | ||
return "binary" |
Empty file.
17 changes: 17 additions & 0 deletions
17
ivy_tests/test_ivy/test_frontends/test_sklearn/test_utils/test_multiclass.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
import ivy | ||
from ivy.functional.frontends.sklearn.utils.multiclass import type_of_target | ||
|
||
|
||
# not suitable for usual frontend testing | ||
@pytest.mark.parametrize("y, label", [([1.2], "continuous"), | ||
([1], "binary"), | ||
([1, 2], "binary"), | ||
([1, 2, 3], "multiclass"), | ||
([1, 2, 3, 4], "multiclass"), | ||
([1, 2, 3, 4, 5], "multiclass"), | ||
([1, 2, 2], "binary"), | ||
([1, 2., 2, 3], "multiclass"), | ||
([1., 2., 2.], "binary")]) | ||
def test_sklearn_type_of_target(y, label): | ||
assert type_of_target(ivy.array(y)) == label |