gpt4 book ai didi

python-3.x - 置信度分数太低

转载 作者:行者123 更新时间:2023-11-30 09:02:48 24 4
gpt4 key购买 nike

我想知道为什么模型得分非常低,只有 0.13,我已经确保数据是干净的、缩放的,并且每个特征之间也具有很高的相关性,但是使用线性回归的模型得分非常低,为什么会发生这种情况以及如何解决这个问题?这是我的代码

import numpy as np 
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn import preprocessing


path = r"D:\python projects\avocado.csv"
df = pd.read_csv(path)
df = df.reset_index(drop=True)
df.set_index('Date', inplace=True)
df = df.drop(['Unnamed: 0','year','type','region','AveragePrice'],1)
df.rename(columns={'4046':'Small HASS sold',
'4225':'Large HASS sold',
'4770':'XLarge HASS sold'},
inplace=True)
print(df.head)

sns.heatmap(df.corr())
sns.pairplot(df)
df.plot()
_=plt.xticks(rotation=20)

forecast_line = 35
df['target'] = df['Total Volume'].shift(-forecast_line)

X = np.array(df.drop(['target'], 1))
X = preprocessing.scale(X)
X_lately = X[-forecast_line:]
X = X[:-forecast_line]
df.dropna(inplace=True)


y = np.array(df['target'])

X_train, X_test, y_train, y_test = train_test_split(X, y,test_size=0.2)
lr = LinearRegression()
lr.fit(X_train,y_train)
confidence = lr.score(X_test,y_test)
print(confidence)

这是我使用的数据集的链接

https://www.kaggle.com/neuromusic/avocado-prices

最佳答案

所以您使用的评分函数是:

Return the coefficient of determination R^2 of the prediction.

The coefficient R^2 is defined as (1 - u/v), where u is the residual sum of squares ((y_true - y_pred) ** 2).sum() and v is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The 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.

因此,当您意识到自己已经超出了持续的预测时。

我的建议是尝试绘制数据,看看应该使用哪种回归。您可以在此处查看可用的线性回归类型的概述: https://scikit-learn.org/stable/modules/linear_model.html

如果您的数据具有逻辑曲线,则逻辑回归有意义,这意味着您的点要么接近 0 要么接近 1,并且中间没有那么多点。

关于python-3.x - 置信度分数太低,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59639749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com