diff --git a/docs/glossary.rst b/docs/glossary.rst index 3633ae83..3b0782d8 100644 --- a/docs/glossary.rst +++ b/docs/glossary.rst @@ -225,6 +225,32 @@ Check Multiple Choice "That's a clown who likes burgers.", "Correct! Head over to the next exercise!"]) +Recommended approach for testing train test splits +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code:: + + # solution + # Perform the train-test split + X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) + + # sct + Ex().check_correct( + multi( + check_object("X_train").has_equal_value(), + check_object("X_test").has_equal_value(), + check_object("y_train").has_equal_value(), + check_object("y_test").has_equal_value() + ), + check_function("sklearn.model_selection.train_test_split").multi( + check_args(["arrays", 0]).has_equal_value("Did you correctly pass in the feature variable to `train_test_split()`?"), + check_args(["arrays", 1]).has_equal_value("Did you correctly pass in the target variable to `train_test_split()`?"), + check_args(["options", "test_size"]).has_equal_value("Did you specify the correct train test split?"), + check_args(["options", "random_state"]).has_equal_value("Don't change the `random_state` argument we set for you.") + ) + ) + + Check import ~~~~~~~~~~~~ diff --git a/pythonwhat/checks/check_object.py b/pythonwhat/checks/check_object.py index a3890d02..371e8c23 100644 --- a/pythonwhat/checks/check_object.py +++ b/pythonwhat/checks/check_object.py @@ -204,7 +204,7 @@ def is_instance(state, inst, not_instance_msg=None): used to 'zoom in' on the object of interest. Args: - inst (class): The class that the object should have. + inst (str): The class that the object should have as a string. not_instance_msg (str): When specified, this overrides the automatically generated message in case the object does not have the expected class. state (State): The state that is passed in through the SCT chain (don't specify this). @@ -220,7 +220,7 @@ def is_instance(state, inst, not_instance_msg=None): # Verify the class of arr import numpy - Ex().check_object('arr').is_instance(numpy.ndarray) + Ex().check_object('arr').is_instance('numpy.ndarray') """ state.assert_is(["object_assignments"], "is_instance", ["check_object"])