Machine Learning 机器学习_吴恩达 练习题记录

本文探讨了如何使用多项式回归预测学生期末考试成绩,基于期中考试成绩,并介绍了特征缩放和均值归一化的重要性。文章还讨论了梯度下降法中的特征缩放作用,以及大规模数据集对学习算法性能的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Linear Regression with Multiple Variables

You’d like to use polynomial regression to predict a student’s final exam score from their midterm exam score. Concretely, suppose you want to fit a model of the form
h θ ( x ) = θ 0 + θ 1 x 1 + θ 2 x 2 h θ ​ ( x ) = θ 0 ​ + θ 1 ​ x 1 ​ + θ 2 ​ x 2 h_\theta(x) = \theta_0 + \theta_1 x_1 + \theta_2 x_2hθ​(x)=θ_0​+θ_1​x_1​+θ_2​x_2 hθ(x)=θ0+θ1x1+θ2x2hθ(x)=θ0+θ1x1+θ2x2
​, where x 1 x_1 x1,​ is the midterm score and x_2x2​ is (midterm score)^22. Further, you plan to use both feature scaling (dividing by the “max-min”, or range, of a feature) and mean normalization. hat is the normalized feature ( x 2 ) ( 2 ) ​ (x_2)^{(2)}​ (x2)(2) (Hint: midterm = 72, final = 74 is training example 2.) Please round off your answer to two decimal places and enter in the text box below.

注意看这题的提示是,max-min,所以在编程题中,有featureNormalize的.m文件
本身的.m是
x n = x n − μ n S n {x_n} = \frac{{{x_n} - {\mu _n}}}{{{S_n}}} xn=Snxnμn
然后如下分母改成range的就可以得到正确答案了

function [X_norm, mu, sigma] = featureNormalize(X)
%FEATURENORMALIZE Normalizes the features in X 
%   FEATURENORMALIZE(X) returns a normalized version of X where
%   the mean value of each feature is 0 and the standard deviation
%   is 1. This is often a good preprocessing step to do when
%   working with learning algorithms.
% You need to set these values correctly
X_norm = X;
mu = mean(X_norm);
sigma = std(X_norm);
% Instructions: First, for each feature dimension, compute the mean
% Hint: You might find the 'mean' and 'std' functions useful.
%
X_norm=(X-mu)./(max(X)-min(X));
% ============================================================end

关于第5题:
Which of the following are reasons for using feature scaling?
It speeds up gradient descent by making it require fewer iterations to get to a good solution.
It is necessary to prevent the normal equation from getting stuck in local optima.
It speeds up gradient descent by making each iteration of gradient descent less expensive to compute.
It prevents the matrix XTX (used in the normal equation) from being non-invertable (singular/degenerate).

解释:它对梯度下降法的帮助是:减少迭代次数,从而加速程序。正如视频中所说,正规方程不需要特征缩放,因此有关正规方程的两个选项都不选。
来源:逍遥游

Support Vector Machines

!即是正确的选项,X是错误的。
2.Suppose a massive dataset is available for training a learning algorithm. Training on a lot of data is likely to give good performance when two of the following conditions hold true.Which are the two?
!We trian a learning algorithm with a large number of parameters(that is able to learn/represent fairly complex functions).
!The features x contain sufficient information to predict y accurately.
!A human expert on the …
!Our learning algorithm is able to present fairly complex functions
X When we are willing to include high order polynomial

3.Suppose you have trained a logistic regression classifier (x)≥threshold, and predict 0 if hθ(x)<threshold, where currently the threshold is set to 0.5.Suppose you decrease the threshold to 0.3. Which of the following are true? Check all that apply.
if 0.5->0.1
!High recall
!Low precision
X is likely to have unchanged precision and recall, but lower accuracy

if 0.5->0.7 /0.9
!Low recall
!High precision
X is likely to have unchanged precision and recall, but higher accuracy
X same F1 score
X is likely to have unchanged precision and recall, but lower accuracy

4.Suppose you are working on a spam classifier, where spam emails are positive examples (y=1y=1) and non-spam emails are negative examples (y=0y=0). You have a training set of emails in which 99% of the emails are non-spam and the other 1% is spam. Which of the following statements are true? Check all that apply.
!non-spam 99% accuracy
!spam 100% recall and 1% precision
!non-spam 0% recall
!non-spam perform similarly on the cross validation set.
X spam recall 0% and 99% precision
X non-spam overfit

5.Which of the following statements are true? Check all that apply.
!Using a very large training set makes it unlikely for model to overfit the training data.
!“The error analysis”
!On skewed datasets accuracy is not a good measure of performance and…
X It’s a good idea to spend
X After training a logistic
X If your model is underfitting the training set, obtaining more data is likely to help

Programming Exercise 1: Linear Regression Machine Learning Introduction In this exercise, you will implement linear regression and get to see it work on data. Before starting on this programming exercise, we strongly recom- mend watching the video lectures and completing the review questions for the associated topics. To get started with the exercise, you will need to download the starter code and unzip its contents to the directory where you wish to complete the exercise. If needed, use the cd command in Octave/MATLAB to change to this directory before starting this exercise. You can also find instructions for installing Octave/MATLAB in the “En- vironment Setup Instructions” of the course website. Files included in this exercise ex1.m - Octave/MATLAB script that steps you through the exercise ex1 multi.m - Octave/MATLAB script for the later parts of the exercise ex1data1.txt - Dataset for linear regression with one variable ex1data2.txt - Dataset for linear regression with multiple variables submit.m - Submission script that sends your solutions to our servers [?] 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 [†] computeCostMulti.m - Cost function for multiple variables [†] gradientDescentMulti.m - Gradient descent for multiple variables [†] featureNormalize.m - Function to normalize features [†] normalEqn.m - Function to compute the normal equations ? indicates files you will need to complete † indicates optional exercises
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Kin-Zhang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值