当前位置:网站首页>机器学习理论基础篇--关于机器学习的一些术语
机器学习理论基础篇--关于机器学习的一些术语
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
边栏推荐
- Can filter
- 【ACM】455. Distribute Biscuits (1. Give priority to big biscuits to big appetite; 2. Traverse two arrays with only one for loop (use subscript index -- to traverse another array))
- Robocode tutorial 8 - advanced robot
- The vivado project corresponding to the board is generated by TCL script
- 【ACM】376. 摆动序列
- 玻璃体中的硫酸软骨素
- Use stm32cube MX / stm32cube ide to generate FatFs code and operate SPI flash
- Serial port debugging tools cutecom and minicom
- SQL中函数 decode()与 replace()的用法
- SQL database syntax learning notes
猜你喜欢

Function recursion and solving interesting problems
![Resolve the error Max virtual memory areas VM max_ map_ count [65530] is too low, increase to at least [262144]](/img/5f/a80951777a0473fcaa685cd6a8e5dd.png)
Resolve the error Max virtual memory areas VM max_ map_ count [65530] is too low, increase to at least [262144]

Imx6 debugging LVDS screen technical notes

Matlab tips (6) comparison of seven filtering methods

使用 bitnami/postgresql-repmgr 镜像快速设置 PostgreSQL HA

QT add external font ttf

解决:cnpm : 无法加载文件 ...\cnpm.ps1,因为在此系统上禁止运行脚本

In win10 system, all programs run as administrator by default

How to virtualize the video frame and background is realized in a few simple steps

Kettle paoding jieniu Chapter 17 text file output
随机推荐
Use of regular expressions in QT
Install the yapiupload plug-in in idea and upload the API interface to the Yapi document
Daily CISSP certification common mistakes (April 18, 2022)
The vivado project corresponding to the board is generated by TCL script
Win1远程出现“这可能是由于credssp加密oracle修正”解决办法
ctfshow-web362(SSTI)
Loop path
Daily CISSP certification common mistakes (April 15, 2022)
CISSP certified daily knowledge points (April 18, 2022)
Kettle paoding jieniu Chapter 17 text file output
Daily CISSP certification common mistakes (April 12, 2022)
Error reported when running tensorboard: valueerror: duplicate plugins for name projector, solution
According to the result set queried by SQL statement, it is encapsulated as JSON
Configure iptables
Use Chenxi bookkeeping book to analyze the balance of revenue and expenditure of each account in a certain period of time
Dynamically add default fusing rules to feign client based on sentinel + Nacos
Tangle
多功能工具箱微信小程序源码
K210串口通信
Connection mode of QT signal and slot connect() and the return value of emit