当前位置:网站首页>机器学习理论基础篇--关于机器学习的一些术语
机器学习理论基础篇--关于机器学习的一些术语
2022-04-23 18:35:00 【夺笋123】
本篇博客参考书籍:scikit-learn机器学习–常用算法原理及编程实战
成本函数(误差)
衡量模型与训练样本的符合程度
成本是针对所有训练样本,模型拟合出来的值与训练样本真实值的误差平均值
成本函数就是成本与模型参数的函数关系
J t r a i n ( θ ) = 1 2 m ∑ i = 1 m ( h θ ( x i ) − t i ) 2 J_{train}(\theta)=\frac{1}{2m}\sum_{i=1}^{m}(h_{\theta}(x^i)-t^i)^2 Jtrain(θ)=2m1i=1∑m(hθ(xi)−ti)2
其中 h ( x i ) h(x^i) h(xi)表示模型对于每个样本值的预测标签, t i t^i ti表示每个样本的真实标签
模型的训练过程就是要找到合适的模型参数使得成本函数的值最小
模型准确性
针对一个数据集可能会使用多个模型对其拟合(比如使用一阶多项式、二阶多项式、…、多阶多项式),我们往往会从这些模型中选出表现最好的那个,那么如何评价一个模型的表现好坏?
我们往往使用测试集的成本函数值作为指标, J t e s t ( θ ) J_{test}(\theta) Jtest(θ)值越小说明模型预测出来的值与样本实际值之间的误差越小,即对新数据的预测准确性越好
J t e s t ( θ ) = 1 2 m ∑ i = 1 m ( h θ ( x i ) − t i ) 2 J_{test}(\theta)=\frac{1}{2m}\sum_{i=1}^{m}(h_{\theta}(x^i)-t^i)^2 Jtest(θ)=2m1i=1∑m(hθ(xi)−ti)2
在sklearn中常使用接口score(x,y)来评价一个模型的性能
交叉验证数据集
如果现在有一个数据集,我们想要从中得到一些信息,有多个模型供选择,那么我们就需要做下面三个事情
1.使用可能的多个模型训练模型参数
2.从多个模型中选择最优秀的模型
3.评价这个模型的预测准确性
测试数据集的主要目的是测试模型的准确性,而这一过程需要模型使用没有“见到过”的数据,如果步骤2使用了测试数据,那么数据就被“见过了”,为解决这一问题,我们可以将数据集分为3部分,多出来的那个就是交叉验证数据集
很多时候我们并没有使用到交叉验证数据集,这是因为大多数时候对于一个数据集,我们知道要使用什么模型
学习曲线
以训练数据集和测试数据集的成本函数值作为纵轴,训练数据集大小作为横轴,画出曲线
使用sklearn中提供的接口绘制学习曲线
from sklearn.model_selection import learning_curve,ShuffleSplit
def plot_learning_curve(estimator,x,y,cv=None,n_jobs=1,train_size=np.linspace(.1,1.0,5)):
train_size,train_score,test_score=learning_curve(estimator,x,y,cv=cv,n_jobs=n_jobs,train_sizes=train_size)
# 求均值,方差
train_score_mean=np.mean(train_score,axis=1)
train_score_std=np.std(train_score,axis=1)
test_score_mean=np.mean(test_score,axis=1)
test_score_std=np.std(test_score,axis=1)
plt.plot(train_size,train_score_mean,'o-',c='r')
plt.plot(train_size,test_score_mean,'o-',c='g')
return plt
学习曲线的意义:随着训练数据集(训练数据量)的增加,模型对训练数据拟合的准确性,对交叉验证数据集预测的准确性变化规律
过拟合
模型能够很好的拟合训练样本,对交叉验证数据集(新数据)的预测准确性较低
解决方法
获取更多训练数据
发生过拟合时,增加数据量可以有效改善模型性能
减少输入的特征数量
过拟合一定程度上说明模型过于复杂,这是我们可以尝试减少输入的特征数量,这样可以减少模型的计算量,也减少了模型的复杂度
欠拟合
模型不能很好的拟合训练样本,对交叉验证数据集(新数据)的预测准确性也较低
增加有价值的特征
欠拟合说明模型有些简单了,导致原因可能是输入特征数量过少,我们可以从原数据中挖掘出更多新的特征
增加多项式的特征
有时从原数据中挖掘特征不是件容易事情,这时我们可以将原来的某些特征相乘或者求平方作为新的特征,这就相当于增加个模型的阶数
x 1 , x 2 → x 1 2 , x 2 2 , x 1 x 2 x_1,x_2\rightarrow x_1^2,x_2^2,x_1x_2 x1,x2→x12,x22,x1x2
版权声明
本文为[夺笋123]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_54510474/article/details/124360905
边栏推荐
- Keil RVMDK compiled data type
- 22 year flying Book manpower Kit
- QT add external font ttf
- Test post and login function
- Query the logistics update quantity according to the express order number
- Solution to Chinese garbled code after reg file is imported into the registry
- ESP32 LVGL8. 1 - label (style 14)
- Cygwin64 right click to add menu, and open cygwin64 here
- 【ACM】376. Swing sequence
- Setting up keil environment of GD single chip microcomputer
猜你喜欢
Use of regular expressions in QT
JD-FreeFuck 京東薅羊毛控制面板 後臺命令執行漏洞
Function recursion and solving interesting problems
Robocode tutorial 7 - Radar locking
【ACM】376. Swing sequence
How to virtualize the video frame and background is realized in a few simple steps
os_authent_prefix
Install the yapiupload plug-in in idea and upload the API interface to the Yapi document
Promote QT default control to custom control
解决:cnpm : 无法加载文件 ...\cnpm.ps1,因为在此系统上禁止运行脚本
随机推荐
From introduction to mastery of MATLAB (2)
Imx6 debugging LVDS screen technical notes
Halo open source project learning (VII): caching mechanism
In shell programming, the shell file with relative path is referenced
机器学习理论之(7):核函数 Kernels —— 一种帮助 SVM 实现非线性化决策边界的方式
os_authent_prefix
Daily network security certification test questions (April 13, 2022)
MATLAB从入门到精通(二)
Cygwin64 right click to add menu, and open cygwin64 here
【ACM】70. climb stairs
Introduction to QT programming
教你用简单几个步骤快速重命名文件夹名
STM32: LCD display
Loop path
Promote QT default control to custom control
After CANopen starts PDO timing transmission, the heartbeat frame time is wrong, PDO is delayed, and CANopen time axis is disordered
SQL database syntax learning notes
WIN1 remote "this may be due to credssp encryption Oracle correction" solution
Nodejs installation
【科普】CRC校验(一)什么是CRC校验?