当前位置: 首页 > wzjs >正文

中国住房和建设部网站首页链家地产二手房网

中国住房和建设部网站首页,链家地产二手房网,域名买卖交易平台,方又圆网站建设机器学习核心问题:过拟合 vs 欠拟合 图示作者:Chris Albon 1. 什么是拟合(Fit)? 拟合(Fit)是指模型对数据的学习效果。 理想目标: 在训练集上效果好 在测试集上效果也好 不复杂、…

机器学习核心问题:过拟合 vs 欠拟合

图示作者:Chris Albon


1. 什么是拟合(Fit)?

拟合(Fit)是指模型对数据的学习效果。

理想目标:

  • 在训练集上效果好

  • 在测试集上效果也好

  • 不复杂、不简单,恰到好处


2. 什么是过拟合(Overfitting)?

定义

过拟合是指模型在训练集上表现很好,但在测试集或新数据上效果很差。模型学到了“噪声”或“异常值”的特征。


特征

特征表现
方差很大对数据过度敏感
决策边界复杂曲折、震荡
泛化能力差新数据易失败

图示(来自图片左侧)

特征2 ↑● ○   ○○ ○○ ● ● ○  ← 决策边界很曲折
特征1 →

 


3. 什么是欠拟合(Underfitting)?

定义

欠拟合是指模型太简单,无法捕捉数据的有效规律,无论在训练集还是测试集上效果都不好。


特征

特征表现
偏差很大无法拟合数据规律
决策边界简单接近直线
泛化能力弱无法有效学习

图示(来自图片右侧)

特征2 ↑● ○   ○○ ○○ ● ● ○  ← 决策边界几乎是直线
特征1 →

 


4. 理想拟合(Best Fit)

状态

  • 偏差(Bias)适中

  • 方差(Variance)适中

  • 决策边界恰好捕捉规律

  • 泛化能力强


图示(图片中间)

特征2 ↑● ○   ○○ ○○ ● ● ○  ← 决策边界几乎是直线
特征1 →

 


5. 数学公式:偏差-方差分解(Bias-Variance Tradeoff)

理论公式

机器学习期望误差可以分解为:

名称含义
Bias偏差,模型简单
Variance方差,模型敏感
Irreducible Error无法消除的随机误差

6. Python实操示例

构造数据

import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error# 真实函数
def true_func(x):return np.sin(2 * np.pi * x)np.random.seed(0)
x = np.sort(np.random.rand(30))
y = true_func(x) + np.random.normal(scale=0.3, size=x.shape)x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3)

 


欠拟合(低阶多项式)

poly1 = PolynomialFeatures(degree=1)
x1_train = poly1.fit_transform(x_train.reshape(-1, 1))
x1_test = poly1.transform(x_test.reshape(-1, 1))model1 = LinearRegression().fit(x1_train, y_train)
print('欠拟合 MSE:', mean_squared_error(y_test, model1.predict(x1_test)))
欠拟合 MSE: 0.418206083278207

 


过拟合(高阶多项式)

poly15 = PolynomialFeatures(degree=15)
x15_train = poly15.fit_transform(x_train.reshape(-1, 1))
x15_test = poly15.transform(x_test.reshape(-1, 1))model15 = LinearRegression().fit(x15_train, y_train)
print('过拟合 MSE:', mean_squared_error(y_test, model15.predict(x15_test)))
过拟合 MSE: 2.732472745353921

 


理想情况(适中阶)

poly4 = PolynomialFeatures(degree=4)
x4_train = poly4.fit_transform(x_train.reshape(-1, 1))
x4_test = poly4.transform(x_test.reshape(-1, 1))model4 = LinearRegression().fit(x4_train, y_train)
print('理想拟合 MSE:', mean_squared_error(y_test, model4.predict(x4_test)))
理想拟合 MSE: 0.1546713133312227

 


7. 如何避免过拟合与欠拟合?

问题类型解决思路
过拟合- 降低模型复杂度
- 增加正则化(L1/L2)
- 增加数据量
- Dropout
- 提前停止
欠拟合- 增加特征
- 增强模型复杂度
- 降低正则化
- 使用更强模型

8. 可视化偏差-方差关系(效果示意)

import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error# 真实函数
def true_func(x):return np.sin(2 * np.pi * x)np.random.seed(0)
x = np.sort(np.random.rand(30))
y = true_func(x) + np.random.normal(scale=0.3, size=x.shape)x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3)complexity = np.arange(1, 15)
train_errors = []
test_errors = []for d in complexity:poly = PolynomialFeatures(degree=d)x_tr = poly.fit_transform(x_train.reshape(-1, 1))x_te = poly.transform(x_test.reshape(-1, 1))model = LinearRegression().fit(x_tr, y_train)train_errors.append(mean_squared_error(y_train, model.predict(x_tr)))test_errors.append(mean_squared_error(y_test, model.predict(x_te)))plt.plot(complexity, train_errors, label='Train Error')
plt.plot(complexity, test_errors, label='Test Error')
plt.xlabel('Model Complexity (degree)')
plt.ylabel('MSE')
plt.legend()
plt.show()

 

 


9. 总结

项目过拟合欠拟合
决策边界复杂简单
偏差Bias
方差Variance
表现训练好,测试差训练差,测试差

10. 最佳实践

寻找偏差和方差的平衡,是机器学习调参的艺术。
合理的特征工程 + 模型复杂度控制 + 正则化技术,是最佳组合。

 


文章转载自:

http://QqYKTkYz.hbkkc.cn
http://mr76cqFP.hbkkc.cn
http://ec9mFF4Z.hbkkc.cn
http://dE80jBIk.hbkkc.cn
http://Qqr0wZUh.hbkkc.cn
http://twX7ub7d.hbkkc.cn
http://75OFjBZD.hbkkc.cn
http://qI8yKzzz.hbkkc.cn
http://trtPWXSr.hbkkc.cn
http://9DP5N9KH.hbkkc.cn
http://8cRPrJmS.hbkkc.cn
http://snYTJhXu.hbkkc.cn
http://m0U5pPLz.hbkkc.cn
http://8km2mXMb.hbkkc.cn
http://FHOvMgHc.hbkkc.cn
http://Gj9bVTsO.hbkkc.cn
http://qM1ZFtXb.hbkkc.cn
http://Tf8aqzgv.hbkkc.cn
http://uGfPkyHX.hbkkc.cn
http://4LzBHYF0.hbkkc.cn
http://NFSZetEe.hbkkc.cn
http://QeZfK3NV.hbkkc.cn
http://wf8xVTIK.hbkkc.cn
http://MPzHpPTT.hbkkc.cn
http://0GXVWFY6.hbkkc.cn
http://pNRiLocg.hbkkc.cn
http://nQqDjn8H.hbkkc.cn
http://wTJ6RILL.hbkkc.cn
http://N0M9BHfC.hbkkc.cn
http://kvmlIEQe.hbkkc.cn
http://www.dtcms.com/wzjs/779733.html

相关文章:

  • 中信银行门户网站系统做网站开发考什么研
  • 深圳网站建设号互联网公司的招聘要求
  • 网站备案填写网站名称黄石网站建设方案
  • 中山市网站建站公司wordpress如何使用dplayer
  • 定制高端网站建设报价做临时工有哪些网站
  • 网站后台管理系统如何安装装修设计图包括哪些图纸
  • 免费代刷网站推广南坪网站建设哪里好
  • 建设读书网站的意义ionic Wordpress
  • 做网站的项目策划书免费的软件下载网站
  • 石家庄建站平台企业宣传ppt案例欣赏
  • 站长工具怎么关闭好网站建设公司的网站
  • 怎样开自己的网站网站建设的实训总结
  • 思科中国网站开发案例wordpress的数据库在哪里设置
  • 西安做网站设计公司做网站管理员需要哪些知识
  • 谷歌地图网站代码对外贸易电商平台
  • 简单的方法搭建网站源美网站建设
  • 有哪个网站教人做美食网站建设技术课程设计
  • 广东网站设计哪家专业域名格式正确的是
  • o2o网站建设机构网站开发需要会的东西
  • 模板网站建设一条龙小程序登录不上去
  • 百度双站和响应式网站的区别网站建设有用吗
  • 淘宝 做网站空间 条件怎样用自己的pid做搜索网站
  • 电商网站前端源码内蒙古高等级公路建设开发有限责任公司网站
  • 做网站点击率赚钱企业网站那几点重要
  • 潍坊公司网站模板建站做烘培的网站有哪些
  • 金华高端网站建设网站设计侵权
  • 明星个人网站建设需求分析自己做的网站怎么推广
  • 盐城seo网站优化软件手机网站制作器
  • 南昌做网站比较好的公司有哪些怎么做网站营销
  • 重庆市建设工程信息网官网网址seo查询5118