{"id":1056,"hash":"d3087650dd90ec507a50b1b99b09b96d3a9fbed73d1c31423960e26f61449342","pattern":"scikit-learn cross validation, negative values with mean squared error","full_message":"When I use the following code with Data matrix X of size (952,144) and output vector y of size (952), mean_squared_error metric returns negative values, which is unexpected. Do you have any idea?\n\nfrom sklearn.svm import SVR\nfrom sklearn import cross_validation as CV\n\nreg = SVR(C=1., epsilon=0.1, kernel='rbf')\nscores = CV.cross_val_score(reg, X, y, cv=10, scoring='mean_squared_error')\n\nall values in scores are then negative.","ecosystem":"pypi","package_name":"regression","package_version":null,"solution":"Trying to close this out, so am providing the answer that David and larsmans have eloquently described in the comments section:\n\nYes, this is supposed to happen. The actual MSE is simply the positive version of the number you're getting.\n\nThe unified scoring API always maximizes the score, so scores which need to be minimized are negated in order for the unified scoring API to work correctly.  The score that is returned is therefore negated when it is a score that should be minimized and left positive if it is a score that should be maximized.  \n\nThis is also described in sklearn GridSearchCV with Pipeline.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/21443865/scikit-learn-cross-validation-negative-values-with-mean-squared-error","votes":72,"created_at":"2026-04-19T04:52:13.807914+00:00","updated_at":"2026-04-19T04:52:13.807914+00:00"}