【发布时间】: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