【问题标题】:Confidence level smaller than 0 with python linear regressionpython线性回归的置信度小于0
【发布时间】:2019-05-16 17:44:34
【问题描述】:

我的股价 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] as 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) 之间?

【问题讨论】:

    标签: python numpy dataframe scikit-learn linear-regression


    【解决方案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 分数。

    【讨论】:

    • 任意更糟是什么意思?如系数为负?
    • @Candice 如果您的 y_preds 比 y_true.mean() 差,您将获得负分。 y_preds 与 y_true 的差异越大,得分越小。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-18
    • 2020-08-01
    • 2010-11-13
    • 2019-08-29
    • 1970-01-01
    • 1970-01-01
    • 2018-04-07
    相关资源
    最近更新 更多