python线性回归的置信水平小于0

2024-03-29 04:45:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我的股票价格df2[x]如下:

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)之间?你知道吗


Tags: 代码testnumpytrainarraydf2clfscale
1条回答
网友
1楼 · 发布于 2024-03-29 04:45:03

从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的期望值,而不考虑输入特征,则R^2得分为0.0。你知道吗

相关问题 更多 >