日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python决策树预测模型_带决策树回归模型的负交叉值得分

發(fā)布時(shí)間:2023/12/10 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python决策树预测模型_带决策树回归模型的负交叉值得分 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

TL、DR:

1)不,除非您顯式指定,或者它是估計(jì)器的默認(rèn).score方法。因?yàn)槟鷽]有,它默認(rèn)為DecisionTreeRegressor.score,它返回決定系數(shù),即R^2。可能是負(fù)數(shù)。在

2)是的,這是個(gè)問題。這也解釋了為什么你會(huì)得到一個(gè)負(fù)的決定系數(shù)。在

細(xì)節(jié):

您使用的函數(shù)如下:scores = cross_val_score(simple_tree, df.loc[:,'system':'gwno'], df['gdp_growth'], cv=cv)

所以你沒有顯式地傳遞一個(gè)“scoring”參數(shù)。讓我們看看docs:scoring : string, callable or None, optional, default: None

A string (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y).

所以它沒有明確說明,但這可能意味著它使用了估計(jì)器的默認(rèn).score方法。在

為了證實(shí)這個(gè)假設(shè),讓我們深入研究source code。我們看到最終使用的記分器如下:

^{pr2}$

has_scoring = scoring is not None

if not hasattr(estimator, 'fit'):

raise TypeError("estimator should be an estimator implementing "

"'fit' method, %r was passed" % estimator)

if isinstance(scoring, six.string_types):

return get_scorer(scoring)

elif has_scoring:

# Heuristic to ensure user has not passed a metric

module = getattr(scoring, '__module__', None)

if hasattr(module, 'startswith') and \

module.startswith('sklearn.metrics.') and \

not module.startswith('sklearn.metrics.scorer') and \

not module.startswith('sklearn.metrics.tests.'):

raise ValueError('scoring value %r looks like it is a metric '

'function rather than a scorer. A scorer should '

'require an estimator as its first parameter. '

'Please use `make_scorer` to convert a metric '

'to a scorer.' % scoring)

return get_scorer(scoring)

elif hasattr(estimator, 'score'):

return _passthrough_scorer

elif allow_none:

return None

else:

raise TypeError(

"If no scoring is specified, the estimator passed should "

"have a 'score' method. The estimator %r does not." % estimator)

所以請(qǐng)注意,scoring=None已經(jīng)完成,所以:has_scoring = scoring is not None

暗示has_scoring == False。另外,估計(jì)器有一個(gè).score屬性,所以我們要通過這個(gè)分支:elif hasattr(estimator, 'score'):

return _passthrough_scorer

這很簡單:def _passthrough_scorer(estimator, *args, **kwargs):

"""Function that wraps estimator.score"""

return estimator.score(*args, **kwargs)

最后,我們現(xiàn)在知道scorer就是你的估計(jì)器默認(rèn)的score。讓我們檢查一下docs for the estimator,它清楚地表明:Returns the coefficient of determination R^2 of the prediction.

The coefficient R^2 is defined as (1 - u/v), where u is the regression

sum of squares ((y_true - y_pred) ** 2).sum() and v is the residual

sum of squares ((y_true - y_true.mean()) ** 2).sum(). 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.

所以看起來你的分?jǐn)?shù)實(shí)際上就是決定系數(shù)。所以,基本上,R^2為負(fù)值,意味著你的模型表現(xiàn)得很差。比我們僅僅預(yù)測每個(gè)輸入的期望值(即平均值)更糟糕。這是有道理的,因?yàn)檎缒闼f:I have a small sample of ~40 observations and ~70 variables. Might

this be the problem?

這是個(gè)問題。當(dāng)你只有40個(gè)觀測值時(shí),對(duì)一個(gè)70維的問題空間進(jìn)行有意義的預(yù)測幾乎是沒有希望的。在

總結(jié)

以上是生活随笔為你收集整理的python决策树预测模型_带决策树回归模型的负交叉值得分的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。