sklearn.metrics.mean_squared_error?

sklearn.metrics.mean_squared_error(y_true, y_pred, *, sample_weight=None, multioutput='uniform_average', squared=True)

均方誤差回歸損失

用戶指南中閱讀更多內容。

參數 說明
y_true array-like of shape (n_samples,) or (n_samples, n_outputs)
真實目標值。
y_pred array-like of shape (n_samples,) or (n_samples, n_outputs)
預測目標值。
sample_weight array-like of shape (n_samples,), optional
樣本權重。
multioutput string in [‘raw_values’, ‘uniform_average’] or array-like of shape (n_outputs)
定義多個輸出值的匯總。類似數組的值定義了用于平均誤差的權重。
- ‘raw_values’:
如果是多輸出格式的輸入,則返回完整的錯誤集。
- ‘uniform_average’:
所有輸出的誤差均以相同的權重平均。
squared boolean value, optional (default = True)
如果為True,則返回MSE值;如果為False,則返回RMSE值。
返回值 說明
loss float or ndarray of floats
非負浮點值(最佳值為0.0)或浮點值數組,每個目標對應一個浮點值。

示例

>>> from sklearn.metrics import mean_squared_error
>>> y_true = [3-0.527]
>>> y_pred = [2.50.028]
>>> mean_squared_error(y_true, y_pred)
0.375
>>> y_true = [3-0.527]
>>> y_pred = [2.50.028]
>>> mean_squared_error(y_true, y_pred, squared=False)
0.612...
>>> y_true = [[0.51],[-11],[7-6]]
>>> y_pred = [[02],[-12],[8-5]]
>>> mean_squared_error(y_true, y_pred)
0.708...
>>> mean_squared_error(y_true, y_pred, multioutput='raw_values')
array([0.416666671.        ])
>>> mean_squared_error(y_true, y_pred, multioutput=[0.30.7])
0.825...