![](/img/trans.png)
[英]What does obs confidence interval in statsmodels linear regression in Python
[英]Confidence level smaller than 0 with python linear regression
我的以下股價df2 [x]為Y:
2018-09-05 6.22
2018-09-06 6.19
2018-09-07 6.22
2018-09-10 6.24
2018-09-11 6.24
...
2018-12-05 4.65
2018-12-14 0.00
將csvReader5 [x]賣空作為X:
2018-09-06 1.11
2018-09-07 1.04
2018-09-10 1.61
2018-09-11 1.52
2018-09-12 1.61
..
2018-12-05 0.98
2018-12-14 7.00
這是我用來計算置信度的代碼
y = numpy.array(csvReader5[x]).reshape(-1,1)
X=numpy.array(df2[x]).reshape(-1,1)
X = preprocessing.scale(X)
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, y, test_size=0.2)
clf = LinearRegression()
clf.fit(X_train, y_train)
confidence = clf.score(X_test, y_test)
Out :-1.08
每次運行時,我得到的置信度都會改變,並且始終小於1。我認為置信度與R方差相同,因此應該始終在(0,1)之間嗎?
從sklearn文檔中:
score(X, y, sample_weight=None)
返回預測的確定系數R ^ 2。
系數R^2
定義為(1 - u/v)
,其中u是平方的殘差和((y_true - y_pred) ** 2).sum()
,v是平方的總和((y_true - y_true.mean()) ** 2).sum()
。 最佳可能分數是1.0, 並且可能為負(因為模型可能會更糟) 。 不管輸入特征如何,始終預測y的期望值的恆定模型將獲得0.0的R ^ 2分數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.