Andrew Ng Machine Learning 第九周

前言

网易云课堂(双语字幕,不卡):https://study.163.com/course/courseMain.htm?courseId=1004570029
Coursera:https://www.coursera.org/learn/machine-learning
本人初学者,先在网易云课堂上看网课,再去Coursera上做作业,开博客以记录,文章中引用图片皆为课程中所截。

异常检测

1.目标动机

在这里插入图片描述
Tips:判断新的xtest是否是异常数据
在这里插入图片描述
Tips:由现有的训练集拟合出一个p(x)模型,将p(xtest)代入模型,将结果与ε对比,若小于ε,即说明新的点落在该模型的概率过小,即为异常

2.高斯分布(正态分布)

在这里插入图片描述
在这里插入图片描述

3.算法

Tips:假设p(x)拟合为高斯分布
在这里插入图片描述
Tips:对于每个特征x,求出相应的高斯分布参数μ和σ,最后将每个p(xi)相乘,得出最后的p(x)

4.开发和评估异常检测

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
Tips:以上为假设情况,假设分配情况如上
在这里插入图片描述
Tips:在训练集上模型p(x),在交叉集或者测试集上测试当前p(x)情况
在这里插入图片描述
Tips:评估方法在第六周笔记,同样ε也用这种方法来决定

5.异常检测VS监督学习

在这里插入图片描述
Tips:简单来说,异常检测情况是当正样本很少负样本很大的时候或者出现异常的情况很多的时候使用

6.选择要使用的功能

(1)特征高斯化

在这里插入图片描述

(2)误差分析

在这里插入图片描述
Tips:用从训练集中得到的p(x)去在交叉集上验证,将其中验证有误差的样本人为的挑选出来,并且根据特征判断出是否应该有新的特征

7.多变量高斯分布

在这里插入图片描述
Tips:简单来说,本来CPU Load和Memory Use应该是线性关系,所以我们需要的数据模型p(x)应该是个椭圆,可是按照上述方法,p(x)所拟合的永远会是一种圆形,则无法判断出它的异常性
在这里插入图片描述
在这里插入图片描述

8.使用多变量高斯分布的异常检测

在这里插入图片描述

推荐系统

1.问题规划

在这里插入图片描述
在这里插入图片描述
Tips:很常见的网站自动推荐的问题。这里nμ=4,nm=5,r(1,1)=1,r(3,1)=0。问题就是通过大量的r(i,j)和y(i,j)去判断那些没有评价的电影的星级来进行电影推荐

2.基于内容的推荐算法

在这里插入图片描述
Tips:假设对于每部电影都创建两个特征值,并且向量化,即对于第一部电影有特征向量x(1)=(1,0.9,0),此处1为截距特征,然后把这个系统当作一个线性回归问题
在这里插入图片描述
Tips:为了判断用户j对某个没评价电影的评分,假设学习一个θ向量来计算评分
在这里插入图片描述
Tips:为了学习θ,定义了相应的代价函数,为了训练出参数θ,即?
在这里插入图片描述
在这里插入图片描述
Tips:梯度下降的方法,此处i:r(i,j)=1的意思是对于每部电影中每个有评价的电影进行累加,Σ (当前θ对该电影i的预测-实际评分*电影特征值+正则项)

3.协同过滤

在这里插入图片描述
Tips:正常情况下,刚开始是不知道一部电影的特征值
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
Tips:此时假设已知每个人参数θ和对该电影的评分,就能求出相应某部电影的特征值
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
Tips:联合两种代价函数,假设知道一种,求另外一个,交换,一直交叉往复,无数次后就能得到都满足的最后结果

4.协同过滤算法

在这里插入图片描述
Tips:将协同过滤结合后的结果,前者是对于每个一评过分的(i,j)组合求预测项和结果项的差的和,后面就是两个正则化

5.算法执行步骤

在这里插入图片描述
在这里插入图片描述

6.矢量化:低轶矩阵分解

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
Tips:矢量化后做法就是XΘT,这个算法也叫低轶矩阵分解
在这里插入图片描述

7.均值规范化

在这里插入图片描述
Tips:若有人没对任何电影评分,则用以上算法无法解决
在这里插入图片描述
在这里插入图片描述
Tips:计算出每个电影已知评分的平均,在计算矩阵Y的时候每行减去相应的平均值,最后在对用户j预测电影i评分的时候加上电影i评分的平均值

题目

1.Question 1

For which of the following problems would anomaly detection be a suitable algorithm?
在这里插入图片描述解答:AB

2.Question 2

Suppose you have trained an anomaly detection system for fraud detection, and your system that flags anomalies when p(x)p(x) is less than \varepsilonε, and you find on the cross-validation set that it is missing many fradulent transactions (i.e., failing to flag them as anomalies). What should you do?
在这里插入图片描述
解答:A

3.Question 3

Suppose you are developing an anomaly detection system to catch manufacturing defects in airplane engines. You model uses
在这里插入图片描述
在这里插入图片描述
解答:B

4.Question 4

Which of the following are true? Check all that apply.
在这里插入图片描述
解答:CD
(对于A,classfication accuracy在倾斜集上效果很差)

5.Question 5

You have a 1-D dataset {x(1)…x(m)}and you want to detect outliers in the dataset. You first plot the dataset and it looks like this:
在这里插入图片描述
Suppose you fit the gaussian distribution parameters μ1 and σ12 to this dataset. Which of the following values for μ1 and σ12 might you get?
在这里插入图片描述
解答:A

6.Question 6

Suppose you run a bookstore, and have ratings (1 to 5 stars) of books. Your collaborative filtering algorithm has learned a parameter vector θ (j)for user jj, and a feature vector x(i) for each book. You would like to compute the “training error”, meaning the average squared error of your system’s predictions on all the ratings that you have gotten from your users. Which of these are correct ways of doing so (check all that apply)? For this problem, let mm be the total number of ratings you have gotten from your users. (Another way of saying this is
在这里插入图片描述
解答:AC

7.Question 7

In which of the following situations will a collaborative filtering system be the most appropriate learning algorithm (compared to linear or logistic regression)?
在这里插入图片描述
解答:CD
(对于B,用户只有一个,不用推荐系统)

8.Question 8

You run a movie empire, and want to build a movie recommendation system based on collaborative filtering. There were three popular review websites (which we’ll call A, B and C) which users to go to rate movies, and you have just acquired all three companies that run these websites. You’d like to merge the three companies’ datasets together to build a single/unified system. On website A, users rank a movie as having 1 through 5 stars. On website B, users rank on a scale of 1 - 10, and decimal values (e.g., 7.5) are allowed. On website C, the ratings are from 1 to 100. You also have enough information to identify users/movies on one website with users/movies on a different website. Which of the following statements is true?
在这里插入图片描述
解答:D

9.Question 9

Which of the following are true of collaborative filtering systems? Check all that apply.
在这里插入图片描述
解答:AB

10.Question 10

Suppose you have two matrices A and B, where A is 5x3 and B is 3x5. Their product is C = AB, a 5x5 matrix. Furthermore, you have a 5x5 matrix RR where every entry is 0 or 1. You want to find the sum of all elements C(i,j) for which the corresponding R(i,j) is 1, and ignore all elements C(i,j)where R(i,j) = 0. One way to do so is the following code:
Which of the following pieces of Octave code will also correctly compute this total? Check all that apply. Assume all options are in code.
在这里插入图片描述
解答:AB
(对于C,如果是A*B.*R就是对的)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值