aboutsummaryrefslogtreecommitdiff
path: root/R_LogR/mlclass-ex2/predict.m
diff options
context:
space:
mode:
authorleshe4ka46 <alex9102naid1@ya.ru>2025-12-13 19:41:40 +0300
committerleshe4ka46 <alex9102naid1@ya.ru>2025-12-13 19:41:40 +0300
commit175ac10904d0f31c3ffeeeed507c8914f13d0b15 (patch)
tree671c68a03354c5084470c5cfcfd4fe87aae2aff8 /R_LogR/mlclass-ex2/predict.m
parent72b4edeadeafc9c54b3db9b0961a45da3d07b77c (diff)
linr, logr
Diffstat (limited to 'R_LogR/mlclass-ex2/predict.m')
-rw-r--r--R_LogR/mlclass-ex2/predict.m32
1 files changed, 32 insertions, 0 deletions
diff --git a/R_LogR/mlclass-ex2/predict.m b/R_LogR/mlclass-ex2/predict.m
new file mode 100644
index 0000000..7af3a20
--- /dev/null
+++ b/R_LogR/mlclass-ex2/predict.m
@@ -0,0 +1,32 @@
+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
+%
+thresh = 0.5
+
+pred = sigmoid(X * theta);
+for i = 1:m
+ if pred(i) >= thresh
+ p(i) = 1;
+ else
+ p(i) = 0;
+ endif
+
+
+
+% =========================================================================
+
+
+end