def test_mse_random_arrays_finite_values(self, y_true, y_pred): mse_value = mse(y_true, y_pred) expected_mse = self._correct_mse(y_true, y_pred) print(y_true) print(y_pred) assert expected_mse == mse_value
def test_mse_dataframe(self): y_true = pd.DataFrame([0, 1, 2, 3, 4, 5]) y_pred = pd.DataFrame([-1, 4, 5, 10, 4, 1]) mse_value = np.round(mse(y_true, y_pred), decimals=2) expected_mse = 14 assert expected_mse == mse_value
def test_mse_array(self): y_true = np.array([0, 1, 2, 3, 4, 5]) y_pred = np.array([-1, 4, 5, 10, 4, 1]) mse_value = np.round(mse(y_true, y_pred), decimals=2) expected_mse = 14 assert expected_mse == mse_value
def test_mse_list(self): y_true = [0, 1, 2, 3, 4, 5] y_pred = [-1, 4, 5, 10, 4, 1] mse_value = np.round(mse(y_true, y_pred), decimals=2) expected_mse = 14 assert expected_mse == mse_value
def _correct_log_mse(self, y_true, y_pred): y_true = np.array(y_true) y_pred = np.array(y_pred) if (np.any(y_true < 0)) or (np.any(y_pred < 0)): raise ValueError( "MSLE can not be used when inputs contain Negative values") log_y_true = np.log(y_true + 1) log_y_pred = np.log(y_pred + 1) log_mse = mse(log_y_true, log_y_pred) return log_mse
def _correct_rmse(self, y_true, y_pred): y_true = np.array(y_true) y_pred = np.array(y_pred) return np.sqrt(mse(y_true, y_pred))
def test_infinite_values(self): y_true = np.random.random(4) y_pred = [0, np.inf, 2, 3] with pytest.raises(ValueError): mse(y_true, y_pred)
def test_nan_values(self): y_true = [np.nan, 1, 2, 3] y_pred = np.random.random(4) with pytest.raises(ValueError): mse(y_true, y_pred)
def test_wrong_vector_length(self): y_true = np.random.random(5) y_pred = np.random.random(4) with pytest.raises(ValueError): mse(y_true, y_pred)