Scikit-learn is returning coefficient of determination (R^2) values less than -1

前端 未结 4 1020
陌清茗
陌清茗 2021-01-30 18:12

I\'m doing a simple linear model. I have

fire = load_data()
regr = linear_model.LinearRegression()
scores = cross_validation.cross_val_score(regr, fire.data, fir         


        
4条回答
  •  你的背包
    2021-01-30 18:44

    R² = 1 - RSS / TSS, where RSS is the residual sum of squares ∑(y - f(x))² and TSS is the total sum of squares ∑(y - mean(y))². Now for R² ≥ -1, it is required that RSS/TSS ≤ 2, but it's easy to construct a model and dataset for which this is not true:

    >>> x = np.arange(50, dtype=float)
    >>> y = x
    >>> def f(x): return -100
    ...
    >>> rss = np.sum((y - f(x)) ** 2)
    >>> tss = np.sum((y - y.mean()) ** 2)
    >>> 1 - rss / tss
    -74.430972388955581
    

提交回复
热议问题