Coursera machine learning 第二周 quiz 答案 Octave/Matlab Tutorial

https://www.coursera.org/learn/machine-learning/exam/dbM1J/octave-matlab-tutorial

Octave Tutorial

5 试题

1.

Suppose I first execute the following Octave commands:

A = [1 2; 3 4; 5 6];

B = [1 2 3; 4 5 6];

Which of the following are then valid Octave commands? Check all that apply and assume all options are written in an Octave command. (Hint: A‘ denotes the transpose of A.)

C = A * B;

C = B‘ + A;

C = A‘ * B;

C = B + A;

答案: ab (C = A * B 和 C = B‘ + A;)

2.

Question text

Let A=????16594211714310615138121????.

Which of the following indexing expressions gives B=????16594211714????? Check all that apply.

B = A(:, 1:2);

B = A(1:4, 1:2);

B = A(0:2, 0:4)

B = A(1:2, 1:4);

答案 :ab (B = A(:, 1:2);和 B = A(1:4, 1:2);)

3.

Let A be a 10x10 matrix and x be a 10-element vector. Your friend wants to compute the product Ax and writes the following code:

v = zeros(10, 1);

for i = 1:10

for j = 1:10

v(i) = v(i) + A(i, j) * x(j);

end

end

How would you vectorize this code to run without any FOR loops? Check all that apply.

v = A * x;

v = Ax;

v =x‘* A;

v = sum (A * x);

答案: a. v = A * x;

v = Ax :Undefined function or variable ‘Ax‘.

4.

Say you have two column vectors v and w, each with 7 elements (i.e., they have dimensions 7x1). Consider the following code:

z = 0;

for i = 1:7

z = z + v(i) * w(i)

end

Which of the following vectorizations correctly compute z? Check all that apply.

z = sum (v .* w);

z = w‘ * v;

z = v * w‘;

z = w * v‘;

答案: ab (z = sum (v .* w);和 z = w‘ * v; )

column vectors 列向量

5.

In Octave, many functions work on single numbers, vectors, and matrices. For example, the sin function when applied to a matrix will return a new matrix with the sin of each element. But you have to be careful, as certain functions have different behavior. Suppose you have an 7x7 matrix X. You want to compute the log of every element, the square of every element, add 1 to every element, and divide every element by 4. You will store the results in four matrices, A,B,C,D. One way to do so is the following code:

for i = 1:7

for j = 1:7

A(i, j) = log(X(i, j));

B(i, j) = X(i, j) ^ 2;

C(i, j) = X(i, j) + 1;

D(i, j) = X(i, j) / 4;

end

end

Which of the following correctly compute A,B,C, or D? Check all that apply.

C = X + 1;

D = X / 4;

B = X .^ 2;

B = X ^ 2;

答案: abc

B = X .^ 2 而不是 X ^ 2

时间: 2024-08-10 15:00:24

Coursera machine learning 第二周 quiz 答案 Octave/Matlab Tutorial的相关文章

Coursera machine learning 第二周 编程作业 Linear Regression

必做: [*] warmUpExercise.m - Simple example function in Octave/MATLAB[*] plotData.m - Function to display the dataset[*] computeCost.m - Function to compute the cost of linear regression[*] gradientDescent.m - Function to run gradient descent 1.warmUpE

Coursera Machine Learning 学习笔记(一)

之前就对Machine Learning很感兴趣,假期得闲看了Coursera Machine Learning 的全部课程,整理了笔记以便反复体会. I. Introduction (Week 1) - What is machine learning 对于机器学习的定义,并没有一个被一致认同的答案. Arthur Samuel (1959) 给出对机器学习的定义: 机器学习所研究的是赋予计算机在没有明确编程的情况下仍能学习的能力. Samuel设计了一个西洋棋游戏,他让程序自己跟自己下棋,并

Machine Learning第九周笔记

博客已经迁移到Marcovaldo's blog Andrew Ng在Machine Learning的第九周介绍了异常检测(anomaly detection)和推荐系统(recommender system),将笔记整理在下面. Anomaly Detection Density Estimation Problem Motivation 视频开头,Andrew Ng告诉我们,异常检测(anomaly detection)主要应用于无监督式学习,但它更像是监督式学习.我们以飞行器发动机为例来

Coursera - Machine Learning, Stanford: Week 1

Welcome and introduction Overview Reading Log 9/9 videos and quiz completed; 10/29 Review; Note 1.1 Welcome 1) What is machine learning? Machine learning is the science of getting compters to learn, without being explicitly programmed. 1.2 Introducti

CS281: Advanced Machine Learning 第二节 Generative model

本小节阅读: MLAPP:第三章 CS229:Naive bayes 贝叶斯概念学习 我们考虑一个小孩学习一个词的过程,比如"狗".大概是小孩的父母指出了这个词的一些正例,比如说:"看那条可爱的狗"或者"记住那条小狗"等等.然而,他们是不太可能提供如"看那条不是狗的东西"的负例.当然,负例也可能在动态学习的过程中接触到,比如父母可能纠正小孩的错误:"那是一只猫,不是一条狗." - 但是心理学研究者已经指出人

Coursera Machine Learning 学习笔记(十四)

- Cost function 对于线性回归模型,我们定义的代价函数是所有模型误差的平方和.理论上来说,我们也可以对逻辑回归模型沿用这个定义,但是问题在于,当我们将带入到这样定义了的代价函数中时,我们得到的代价函数将是一个非凸函数(non-convex function). 这意味着我们的代价函数有许多局部最小值,这将影响梯度下降算法寻找全局最小值. 因此,我们重新定义逻辑回归的代价函数为: 其中 与之间的关系如下图所示: 这样构建的函数的特点是:当实际的y=1且也为1时误差为0,当y=1但不为

神经网络作业: NN LEARNING Coursera Machine Learning(Andrew Ng) WEEK 5

在WEEK 5中,作业要求完成通过神经网络(NN)实现多分类的逻辑回归(MULTI-CLASS LOGISTIC REGRESSION)的监督学习(SUOERVISED LEARNING)来识别阿拉伯数字.作业主要目的是感受如何在NN中求代价函数(COST FUNCTION)和其假设函数中各个参量(THETA)的求导值(GRADIENT DERIVATIVE)(利用BACKPROPAGGATION). 难度不高,但问题是你要习惯使用MALAB的矩阵QAQ,作为一名蒟蒻,我已经狗带了.以下代核心部

Coursera Machine Learning 学习笔记(六)

- Gradient descent 梯度下降算法是一个用来求得函数最小值的算法,这里我们将使用梯度下降算法来求出代价函数的最小值. 梯度下降的思想是:开始的时候我们随机选择一个参数的组合并计算代价函数,之后我们寻找下一个能使得代价函数值下降最多的参数的组合. 我们持续如此过程直到一个局部最小值(local minimum),由于我们并没有完全尝试完所有参数的组合,所以我们不能够确定我们得到的局部最小值是否为全局最小值(global minimum),而且选择不同的参数组合,我们可能会找到不同的

Coursera Machine Learning 学习笔记(二)

- Supervised Learning 对于监督学习我们先看一个例子,下图中表示的是一个房价预测的例子.图中横坐标表示房屋占地面积,纵坐标表示房屋交易价格.图中的每个叉则表示一个房屋实例. 现在,我们希望能够预测一个房屋占地面积为750平方英尺的房屋的交易价格是多少.简单的方法是根据这些数据点的分布,画出一条合适的直线,然后根据这条直线来预测.当然,在此房价预测例子中,一个二次函数更加适合已有数据的分布.因此,我们可能会更加希望使用这个二次函数的曲线来进行房价预测. 因此,我们称上述这样的学