function p = predict(theta, X)
%PREDICT Predict whether the label is 0 or 1 using learned logistic
%regression parameters theta
% p = PREDICT(theta, X) computes the predictions for X using a
% threshold at 0.5 (i.e., if sigmoid(theta'*x) >= 0.5, predict 1)
m = size(X, 1); % Number of training examples
% You need to return the following variables correctly
p = zeros(m, 1);
% ====================== YOUR CODE HERE ======================
% Instructions: Complete the following code to make predictions using
% your learned logistic regression parameters.
% You should set p to a vector of 0's and 1's
%
p = 1./(1.+exp(-X*theta))
p = p>0.5
% =========================================================================
end
吴恩达的机器学习编程作业5:predict逻辑回归预测模型
最新推荐文章于 2025-11-07 09:22:21 发布
本文介绍了一个使用学习到的逻辑回归参数进行预测的函数。该函数通过设置阈值为0.5来判断样本属于类别0还是1。对于输入的特征矩阵X和参数向量theta,函数计算了每个样本被归类为1的概率,并据此作出预测。
1144

被折叠的 条评论
为什么被折叠?



