We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
def check_target_logical_type(y, problem_type): if problem_type in [ ProblemTypes.REGRESSION, ProblemTypes.TIME_SERIES_REGRESSION, ] and not any( isinstance(y.ww.schema.logical_type, x) for x in [ Integer, IntegerNullable, Double, ] ): raise ValueError( "Regression problem type requires a Integer, IntegerNullable or Double target", ) elif problem_type == ProblemTypes.MULTICLASS and not isinstance( y.ww.schema.logical_type, Categorical, ): y = y.ww.set_logical_type("Categorical") elif problem_type == ProblemTypes.BINARY and not any( isinstance(y.ww.schema.logical_type, x) for x in [ Boolean, BooleanNullable, Categorical, ] ): raise ValueError( "Binary problem type requires a Boolean, BooleanNullable or Categorical target", ) return y
def test_check_target_logical_type(): y = pd.Series([1, 2, 2, 3, 3, 1], dtype="int64") y.ww.init(logical_type="Integer") check_target_logical_type(y, ProblemTypes.REGRESSION) check_target_logical_type(y, ProblemTypes.TIME_SERIES_REGRESSION) with pytest.raises(ValueError, match="Binary problem type requires a"): check_target_logical_type(y, ProblemTypes.BINARY) new_y = check_target_logical_type(y, ProblemTypes.MULTICLASS) assert new_y.ww.schema.logical_type.__class__ == Categorical y = pd.Series(["red", "blue", "blue"], dtype="category") y.ww.init(logical_type="Categorical") with pytest.raises(ValueError, match="Regression problem type requires a"): check_target_logical_type(y, ProblemTypes.REGRESSION)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Tests
The text was updated successfully, but these errors were encountered: