吴恩达机器学习笔记(代码片段)

未来可期-2018 未来可期-2018     2022-12-12     501

关键词:

文章目录

Error analysis

Methods to solve over fitting

  • more training examples
  • try smaller sets of features
  • try increasing λ \\lambda λ

Methods to solve under fitting

  • getting additional features
  • try adding polynomial features
  • try decreasing λ \\lambda λ

Recommend approach

  • start with a simple algorithm that you can implement quickly. Implement it and test it on your cross-validation data
  • plot learning curves to decide if more data, more features, etc. are likely to help.
  • Error analysis: See if you spot any systematic trend in what type of examples it is making errors on

Error metrics for skewed classes

10
1True PositiveFalse Positive
0False NegativeTrue Negative

p r e c i s i o n = T P T P + F P precision=\\fracTPTP+FP precision=TP+FPTP 准确率

r e c a l l = T P T P + F N recall=\\fracTPTP+FN recall=TP+FNTP 召回率

F 1 s c o r e = 2 P R P + R \\displaystyle F_1score=2\\fracPRP+R F1score=2P+RPR F值

Data for machine learning

In the following conditions, more data makes sense.

  • Assume feature x ∈ R n + 1 x\\in R^n+1 xRn+1 has sufficient information to predict y accurately.
  • Use a learning algorithm with many parameters such as logistic regression or linear regression with many features or neural network with many hidden units.

Support Vector Machine

Logistic regression Cost function
m i n θ 1 m [ ∑ i = 1 m y ( i ) ( − log ⁡ h θ ( x ( i ) ) ) + ( 1 − y ( i ) ) ( − log ⁡ ( 1 − h θ ( x ( i ) ) ) ) ] + λ 2 m ∑ j = 1 n θ j 2 min_\\theta\\frac1m[\\sum_i=1^my^(i)(-\\log h_\\theta(x^(i)))+(1-y^(i))(-\\log(1-h_\\theta(x^(i))))]+\\frac\\lambda2m\\sum_j=1^n\\theta_j^2 minθm1[i=1my(i)(loghθ(x(i)))+(1y(i))(log(1hθ(x(i))))]+2mλj=1nθj2
SVM hypothesis
m i n θ C ∑ i = 1 m [ y ( i ) c o s t 1 ( θ T x ( i ) ) + ( 1 − y ( i ) ) c o s t 0 ( θ T x ( i ) ) ] + 1 2 ∑ i = 1 n θ j 2 min_\\theta C\\sum_i=1^m[y^(i)cost_1(\\theta^Tx^(i))+(1-y^(i))cost_0(\\theta^Tx^(i))]+\\frac12\\sum_i=1^n\\theta_j^2 minθCi=1m[y(i)cost1(θTx(i))+(1y(i))cost0(θTx(i))]+21i=1nθj2

h θ ( x ) = 0 1 h_\\theta(x)= \\begincases 0\\\\ 1\\\\ \\endcases hθ(x)=01

SVM parameters

C = 1 λ C=\\frac1\\lambda C=λ1

  • large C low bias, high variance
  • small C higher bias, low variance

σ 2 \\sigma^2 σ2

  • large σ 2 \\sigma^2 σ2. feature f i f_i fi vary more smoothly. higher bias, lower variance
  • small σ 2 \\sigma^2 σ2. feature f i f_i fi vary less smoothly. lower bias, higher variance

Kernel function

  • no kernel

  • 高斯kernel
    f = e − ∣ ∣ x 1 − x 2 ∣ ∣ 2 σ 2 f=e^-\\frac|| x_1-x_2 ||2\\sigma^2 f=e2σ2x1x2

  • 多项式kernel k ( x , l ) = ( x T l + c o n s t a n t ) d e g r e e k(x,l)=(x^Tl+constant)^degree k(x,l)=(xTl+constant)degree

Muti-class classification

train K SVMs, one to distinguish y = i y=i y=i from the rest

Logistic regression vs SVMs

n=number of features x ∈ R n + 1 x\\in R^n+1 xRn+1,m=number of training examples

  • n is large relative to m: use logistic regression or SVM without kernel
  • n is small , m is intermediate: use SVM with Gaussian kernel
  • n is small and m is large: create or add more features and then use logistic regression or svm without kernel

K-means

Input

  • K (number of clusters)
  • training set x ( 1 ) , x ( 2 ) , ⋯   , x ( m ) \\x^(1),x^(2),\\cdots,x^(m)\\ x(1),x(2),,查看详情

    机器学习-吴恩达andrewngweek1知识总结introduciton(代码片段)

    Coursera课程地址因为Coursera的课程还有考试和论坛,后续的笔记是基于Courserahttps://www.coursera.org/learn/machine-learning/home/welcome1.什么是机器学习?提供了机器学习的两种定义。亚瑟·塞缪尔(ArthurSamuel)将其描述为࿱... 查看详情

    吴恩达机器学习学习笔记——代价函数

    单变量线性回归函数 hθ(x)=θ0+θ1x为了使线性回归函数对数据有较好的预测性,即y到h(x)的距离都很小。  查看详情

    吴恩达“机器学习”——学习笔记二

    定义一些名词欠拟合(underfitting):数据中的某些成分未被捕获到,比如拟合结果是二次函数,结果才只拟合出了一次函数。过拟合(overfitting):使用过量的特征集合,使模型过于复杂。参数学习算法(parametriclearningalgorithms)... 查看详情

    吴恩达机器学习随笔什么是机器学习?(代码片段)

    定义   TomMitchell对机器学习定义为“计算机从经验E中学习,解决某一任务T,进行某一度量P,通过P测定在T上的表现因经验E而提高”。定义个人觉得大体理解即可,如果扣文咬字去理解会十分痛苦,就不做过多解释了。原文:... 查看详情

    吴恩达《机器学习系列课程》学习笔记

    ...f0c;结果最后,B站反而更像中国的YouTube。在B站上看到吴恩达的《机器学习系列课程》,看了看发现挺有意思,就梳理一下在此形成学习笔记。第一节:前言机器学习早已成为我们的日常。每当使用Google或Bing等搜... 查看详情

    吴恩达《机器学习系列课程》学习笔记:监督学习

    吴恩达的课程会很偏于用实例来掌握理论知识,不过看着还是有些云里雾里,倒是杉山将的《图解机器学习》介绍得更易懂些。在此进行结合学习。杉山将是这么通俗地定义监督学习、无监督学习和强化学习,它们是... 查看详情

    machinelearning|andrewng|coursera吴恩达机器学习笔记

    Week1:MachineLearning: AcomputerprogramissaidtolearnfromexperienceEwithrespecttosomeclassoftasksTandperformancemeasureP,ifitsperformanceattasksinT,asmeasuredbyP,improveswithexperienceE. Supe 查看详情

    吴恩达“机器学习”——学习笔记八

    偏差方差权衡(biasvariancetradeoff)偏差:如果说一个模型欠拟合,也可以说它的偏差很大。方差:如果说一个模型过拟合,也可以说它的方差很大。训练误差经验风险最小化(ERM)选择参数,使得训练误差最小化,即假设类H:所有假设... 查看详情

    coursera-andrewng(吴恩达)机器学习笔记——第一周

    一.初识机器学习何为机器学习?Acomputerprogramissaidtolearn fromexperienceEwithrespecttosometaskT andsomeperformancemeasureP,ifits performanceonT,asmeasuredbyP,improves withexperienceE.理解:通过实验E,完 查看详情

    吴恩达深度学习笔记(代码片段)

    监督学习简介文章目录监督学习简介前言一、监督学习常见应用二、基础知识1.数据类型2.学习次序3.常用符号4.二分分类(logistics)5.梯度下降法6.导数和流程图(略)7.logistics中的梯度下降7.向量化的必要性8.向量... 查看详情

    吴恩达2014机器学习教程笔记目录

    ...重实践,结合起来学习事半功倍。但是论经典,还是首推吴恩达的机器学习课程。吴大大14年在coursera的课程通俗易懂、短小精悍,在讲解知识点的同时,还会穿插相关领域的最新动态,并向你推荐相关论文。课程10周共18节课,... 查看详情

    吴恩达深度学习笔记(代码片段)

    神经网络文章目录神经网络前言一、一些基础的numpy语法二、神经网络1、原理2、代码MATLAB版本:python版本:3、激活函数tanh函数Relu函数LeakyReLU函数(PReLU)ELU(ExponentialLinearUnits)函数总结前言学习的第二天一、一些... 查看详情

    machinelearning(吴恩达<一>)(代码片段)

    目录一、机器学习(ML)简介1.人工智能、机器学习、深度学习的关系2.机器学习与深度学习的比较2.1、应用场景2.2、所需数据量2.3、执行时间2.4、解决问题的方法3.监督学习(SupervisedLearning)4.无监督学习(Unsupervise... 查看详情

    吴恩达机器学习——线性回归(代码片段)

    ...籍,但书上讲的总归有些晦涩,看到大家在推荐吴恩达的课程,于是去看了,发现确实很不错,有很多书上难懂的公式,其实视频里十几分钟就讲明白了&# 查看详情

    吴恩达机器学习作业——异常检测和推荐系统(代码片段)

    异常检测参考资料:https://github.com/fengdu78/Coursera-ML-AndrewNg-Notes先看数据:importnumpyasnpimportmatplotlib.pyplotaspltfromscipyimportstatsfromscipy.ioimportloadmatimportmathdata=loadmat( 查看详情

    吴恩达机器学习作业——异常检测和推荐系统(代码片段)

    异常检测参考资料:https://github.com/fengdu78/Coursera-ML-AndrewNg-Notes先看数据:importnumpyasnpimportmatplotlib.pyplotaspltfromscipyimportstatsfromscipy.ioimportloadmatimportmathdata=loadmat( 查看详情

    吴恩达“机器学习”——学习笔记五

    朴素贝叶斯算法(NaiveBayes)(续学习笔记四)两个朴素贝叶斯的变化版本x_i可以取多个值,即p(x_i|y)是符合多项式分布的,不是符合伯努利分布的。其他的与符合伯努利的情况一样。(同时也提供一种思路将连续型变量变成离散型的... 查看详情