【问题标题】:Why is my Linear Regression Score so low?为什么我的线性回归分数这么低?
【发布时间】:2020-02-05 01:57:47
【问题描述】:

浏览了定期更新统计数据的 Pgatour.com 网站。他们有可以追溯到 2010 年的历史数据,这些数据被抓取到一个平面 csv 文件中。 用 pd.read_csv(filename) 成功读入。这次刮是 2010-2019 年。

SG_P SG_T SG_TTG SG_OTT SG_ATG 点 7 0.243 1.195 0.952 0.338 0.168 718.0 8 0.098 1.192 1.091 0.724 0.260 445.0 9 -0.147 1.001 1.151 0.185 0.738 843.0 11 0.054 0.984 0.927 0.151 0.507 718.0 12 0.137 1.156 1.014 0.403 0.642 500.0

在重组一个新的数据框后,我只保留“SG”统计数据或“Strokes-Gained”,它们与高尔夫球手的“积分”有非线性关系,我们对测试数据运行了 0.33% 的 train_test_split。目标变量是“POINTS”。

在其他Kaggle runs of this project 中,结果通常在 0.70 精度范围内。

对于来自 Scikitlearn 的直线线性回归,我的数据在 .25-.30 范围内,这会产生非常欠拟合的数据,当使用 Seaborn 绘制时,结果会很差。

training set r^2 score = 0.2601442196444287
testing set r^2 score = 0.2602966900574226

线性回归代码如下:

from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split

# Split features and target

X = df2.iloc[: ,:-1] # Get the features minus OWGR which is the target
y = df2.iloc[:,-1:]  # Just get the target

# Train test split

X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.33,random_state=12)

lr = LinearRegression(n_jobs = -1,normalize=True)
lr.fit(X_train, y_train)

training set r^2 score = 0.2601442196444287
testing set r^2 score = 0.2602966900574226

这里是多边形版本:

from sklearn.preprocessing import PolynomialFeatures

degree = 2 # Start with 2
poly = PolynomialFeatures(degree, include_bias=False)

X_poly = poly.fit_transform(X) # No longer a pandas dataframe
y_poly = y # Still a pandas dataframe

X_poly_train, X_poly_test, y_poly_train, y_poly_test = train_test_split(X_poly, y_poly, random_state=12)

lr_poly = LinearRegression()
lr_poly.fit(X_poly_train, y_poly_train)

training set r^2 score = 0.2902297270799855
testing set r^2 score = 0.1746156333412796

在 Kaggle 的基准笔记本中,我看到了如下结果:

线性:

training set r^2 score = 0.5540673510136147
testing set r^2 score = 0.510807136771844

聚:

training set r^2 score = 0.7466513181026075
testing set r^2 score = 0.6325248963195537

【问题讨论】:

  • 欢迎来到机器学习,没有一个解决方案可以解决这个问题!这是你现在的任务,你可以选择不同的特征,改变回归方法等。是时候读一本关于机器学习的书了!
  • 是的,我们都在不断学习。谢谢!

标签: python machine-learning scikit-learn linear-regression prediction


【解决方案1】:

数据预处理是训练之前非常重要的一步。在这一步中,为了减少无关和冗余信息,处理无效值等,对数据进行转换。有关数据预处理的一些操作可能包括空值处理,数据降维,数据标准化等。不执行此过程,您可能最终拥有强大的精心设计的分类器,但对您的实际数据表现不佳。试试吧,也许你的结果会有所改善!

【讨论】:

  • 亚历克斯,这就是我难过的原因。提到的 Kaggle 内核中完全相同范围内的相同数据,除了删除列和使用 NaN 删除观察值外,没有进行任何转换或预处理。我试图通过使用与他们使用的不同的刮板来重现它。这真的是唯一的区别。感谢您的建议。干杯。
  • 在这个小组的一些催促下,我发现了我的问题并解决了。我所做的是重新编写刮板以从 PGA.com 捕获 AVG POINTS 并将其包含在数据集中。除了投篮得分和 AVG 分数之外,我放弃了所有统计数据,我重新运行了两个回归,并能够从 Kaggle 内核重现结果。事实证明,这确实是一个与数据相关的问题,需要重新考虑该项目的扩展性和数据相关性。干杯!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-08-27
  • 2020-01-02
  • 2021-08-01
  • 1970-01-01
  • 2012-01-18
  • 2020-01-28
  • 2019-06-11
相关资源
最近更新 更多