Skip to content

model.score() returns MSE but the docstring states that it returns R2 #507

@daguito81

Description

@daguito81

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions