-
-
Notifications
You must be signed in to change notification settings - Fork 260
model.score() returns MSE but the docstring states that it returns R2 #507
Copy link
Copy link
Closed
Description
In dask_ml linear_models LinearRegression. If you use model.score(X_test, y_test) then you get back the Mean Squared Error instead of the R2 which is how sklearn's implementation does it.
On top of that the score method defined has a docstring that states that it returns the r2 score instead of the MSE.
We can see in the code here
dask-ml/dask_ml/linear_model/glm.py
Lines 304 to 328 in e1b21e6
| def score(self, X, y): | |
| """Returns the coefficient of determination R^2 of the prediction. | |
| The coefficient R^2 is defined as (1 - u/v), where u is the residual | |
| sum of squares ((y_true - y_pred) ** 2).sum() and v is the total | |
| sum of squares ((y_true - y_true.mean()) ** 2).sum(). | |
| The best possible score is 1.0 and it can be negative (because the | |
| model can be arbitrarily worse). A constant model that always | |
| predicts the expected value of y, disregarding the input features, | |
| would get a R^2 score of 0.0. | |
| Parameters | |
| ---------- | |
| X : array-like, shape = (n_samples, n_features) | |
| Test samples. | |
| y : array-like, shape = (n_samples) or (n_samples, n_outputs) | |
| True values for X. | |
| Returns | |
| ------- | |
| score : float | |
| R^2 of self.predict(X) wrt. y. | |
| """ | |
| return mean_squared_error(y, self.predict(X)) |
That the docstring says r2 score, but the method returns the mean_squared_error from dask_ml.utils.
Either the docstring should be changed to reflect the real return value. Or the r2_score method should be defined and then use that on the rerturn statement of the score method
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels