- ๐ All Sites
- _APDaga DumpBox
- _APDaga Tech
- _APDaga Invest
- _APDaga Videos
- ๐️ Categories
- _Free Tutorials
- __Python (A to Z)
- __Internet of Things
- __Coursera (ML/DL)
- __HackerRank (SQL)
- __Interview Q&A
- _Artificial Intelligence
- __Machine Learning
- __Deep Learning
- _Internet of Things
- __Raspberry Pi
- __Coursera MCQs
- __Linkedin MCQs
- __Celonis MCQs
- _Handwriting Analysis
- __Graphology
- _Investment Ideas
- _Open Diary
- _Troubleshoots
- _Freescale/NXP
- ๐ฃ Mega Menu
- _Logo Maker
- _Youtube Tumbnail Downloader
- ๐ธ️ Sitemap
Coursera: Machine Learning (Week 3) [Assignment Solution] - Andrew NG
Recommended Machine Learning Courses: Coursera: Machine Learning Coursera: Deep Learning Specialization Coursera: Machine Learning with Python Coursera: Advanced Machine Learning Specialization Udemy: Machine Learning LinkedIn: Machine Learning Eduonix: Machine Learning edX: Machine Learning Fast.ai: Introduction to Machine Learning for Coders
- ex2.m - Octave/MATLAB script that steps you through the exercise
- ex2 reg.m - Octave/MATLAB script for the later parts of the exercise
- ex2data1.txt - Training set for the first half of the exercise
- ex2data2.txt - Training set for the second half of the exercise
- submit.m - Submission script that sends your solutions to our servers
- mapFeature.m - Function to generate polynomial features
- plotDecisionBoundary.m - Function to plot classifier's decision boundary
- [*] plotData.m - Function to plot 2D classification data
- [*] sigmoid.m - Sigmoid Function
- [*] costFunction.m - Logistic Regression Cost Function
- [*] predict.m - Logistic Regression Prediction Function
- [*] costFunctionReg.m - Regularized Logistic Regression Cost
- Video - YouTube videos featuring Free IOT/ML tutorials
plotData.m :
Sigmoid.m :, costfunction.m :, check-out our free tutorials on iot (internet of things):.
predict.m :
Costfunctionreg.m :, 61 comments.
how could you do this please explain me...
What explanation you want? Please be more specific.
How can i download these files?
You can copy the the code from above code sections.
Hi Akshay, Please may I have theses files as well: ex2.m ex2 reg.m ex2data1.txt ex2data2.txt submit.m mapFeature.m plotDecisionBoundary.m
You can get those files from Coursera assignments. I don't have those with me now.
can you please tell me what you did by this grad = (1/m)* (X'*(h_x-y));
its the simplified version of derivative term d/d0*j0 which we call gradient. check the formula once and you will understand it
this means:- take the transpose of feature matrix X(i.e X') and multiply it with the difference of matrices h_x and y i.e the matrix with sigmoid outputs and the result matrix(y). Finally multiply the end product with 1/m , where m is the number of training examples. This is the vectorized implementation of the code that's actually way more lengthier to implement using loops.
Hi, can you please explain the predict function?
In this gradient decent the number of iteration are not specified so how is the gradient decent working? can someone please explain?
I used the exact code at the end but I'm still getting 65/100 not able to figure out the reason
Did you figure out the reason yet?
Hi !! why didn't you use sum() function for grad even why formula contains that ?
sum() is used for the summation in the formula. But here while coding for grad computation: grad = (1/m)* (X'*(h_x-y)); Here We are doing matrix multiplication which itself consist of "sum of product". So, no need of external sum function. Please try to do it on paper by yourself, you will get clear idea. Thanks
we have learned that Z= theta transpose X then why are using Z=X multiplied by theta in the above codes ?
When we are calculating z(small z) for a single sample, then it is z=theta' * x. (here small x) But When you do the same computation for all the samples at the same time then we call it as Z (Capital Z). Z = X * theta. (Here Capital X) Try to do it using pen-paper, you will get clear understanding.
Hii, thanks for your help mr. Akshay. I had this one doubt about predict.m function: I tried coding for predict function in the following way: h_x = sigmoid(X*theta); if (0<=h_x<0.5) p=0; elseif (0.5<=h_x<=1) p=1; endif I know I did it in a long way but the accuracy that I am getting 60.00. Your code gave me the accuracy 89.00. Can you please help me understand what's wrong with this and what's the exact difference between your code and mines'?
P is a matrix with dimensions m x 1. Solution: You can put your code in a "for" loop and check the value of each element in h_x and accordingly set the value of each element in p. It will work.
hey bro it says z not defined why???
Hi, I think you are doing this assignment in Octave and that's why you are facing this issue. Chethan Bhandarkar has provided solution for it. Please check it out: https://www.apdaga.com/2018/06/coursera-machine-learning-week-2.html?showComment=1563986935868#c4682866656714070064 Thanks
I have copy the exact code for plotData.m , and all the others program worked very well but I am still getting 70/100. Can you tel what's the problem ?
Can you tell me , how can I run "ex2" script in console ?
hi I want to clarify few things from you, I have read in regression, these are few important points which have not been covered in andrew ng regression topic, how to find how significant your variable is, significance of p value and R^2 (R-square) values. I would like to know more about them. kindly share some sources.
HI, The line code reg_term = (lambda/(2*m)) * sum(theta(2:end).^2); in costFunctionReg function, can you explain more about this part theta(2:end) , what does it mean and how did you deduce it,
sir,please explain me predict.m function I used for i=1:size(X,1) if sigmoid(X*theta)>=0.5 p=sigmoid(X*theta); end as well as, h_x = sigmoid(X*theta); for i=1:size(X,1) if (0<=h_x<0.5) p=0; elseif (0.5<=h_x<=1) p=1; end but i am getting 40 accuracy it is working only with your code.why sir?
Hi there, I am trying the the same code as yours of sigmoid() function but each time it is getting an error saying that 'z' undefined near line 6 column 18 error: called from sigmoid at line 6 column 5 what to do please help me out..
Hello Akshay, It'd be great if you kindly share the code for "fminunc" in this week's files(wherever needed), coz i don't understand that particular function well, neither did i get its solution anywhere else on internet.
Hi Ankit, Sorry but I don't have the code for "fminunc".
grad(2:end) = (1/m)* (X(:,2:end)'*(h_x-y))+(lambda/m)*theta(2:end); can u please explain this..
Hey it says my plot is empty can someone help?
I am facing this type of problem in matlab , what can i do ? how to fix that n where ?? 'fminunc' requires Optimization Toolbox. Error in ex2 (line 99) fminunc(@(t)(costFunction(t, X, y)), initial_theta, options);
In sigmoid error in line 6 (the preallocated value assigned to variable 'g' might be unused) what should i do
How's value of 'g' is unused. 'g' is nothing but output of sigmoid function. If you are getting some msg, it must be warning not error. So, don't worry about it, keep it as it is. (But I don't think you should get any kind of warning like this). line 6, is called initialization of variable.
Hi Akshay can you please explain why we use this X(:,2:end) and theta(2:end) instead of plain X and theta??
It's because as per the theory in videos, We don't apply regularization on theta_0. Regularization is applied from theta_1 onwards. and that's why 2 gradients. 1st corresponding to theta_0 and other for theta_1 onwards.
And also why use two gradents?
Good day sir, im new in this course...i could not fully understand the assignment in week 3...as i enter my code...i think still in error..
please explain the predict function
Predict function is fairly simple. You have implemented your gradient and now you just have to predict whether the answer will be 1 or 0... So, what will you do is check for the result > 0.5. If it is above the 0.5, then prediction will be true (1), otherwise false (0)
@Hassan Ashas Thank you very much for your explanation.
costfuntion is not returning the scalar value, it is returning the 1*100 matrix.
Opening and closing brackets are not matching you code. NOTE: check the brackets are "2*m" YOUR CODE: reg_term = (lambda/2*m)) * sum(theta(2:end).^2); WORKING CODE: reg_term = (lambda/(2*m)) * sum(theta(2:end).^2);
Hello Akshay, While computing cost function I am getting so many outputs
You should only get [J, grad] as a output of costFunction & costFunctionReg.
Error - theta may not be defined , predict function
hi i have a doubt i took theta as [zeros(n+1),1] it is giving me 0 and i cant submit the assignment can you specify initial value of theta and theta and values of X. i am totally confused
nothing is working here every time it is showing >> plotData error: 'y' undefined near line 14 column 12 error: called from plotData at line 14 column 5 >>
J = (1 / m) * sum ((- y. * Log (h_x)) - ((1-y). * Log (1-h_x))) the log representation in this equation means ln isn't it? So, shouldn't we write it as log (1-h_x) / log (10).
I made it this way: function [J, grad] = costFunctionReg(theta, X, y, lambda) %COSTFUNCTIONREG Compute cost and gradient for logistic regression with regularization % J = COSTFUNCTIONREG(theta, X, y, lambda) computes the cost of using % theta as the parameter for regularized logistic regression and the % gradient of the cost w.r.t. to the parameters. % Initialize some useful values m = length(y); % number of training examples % You need to return the following variables correctly J = 0; grad = zeros(size(theta)); % ====================== YOUR CODE HERE ====================== % Instructions: Compute the cost of a particular choice of theta. % You should set J to the cost. % Compute the partial derivatives and set grad to the partial % derivatives of the cost w.r.t. each parameter in theta [J, grad] = costFunction(theta, X, y); feats = theta(2:end); J = J + lambda / (2 * m) * (feats' * feats); grad(2:end) = grad(2:end) + lambda / m * feats; % ============================================================= end
My question is about the solved subroutine 'plotDecisionBoundary.m' Line 20 : plot_y I didn't understand the definition of this Infact how this particular code helped to plot the decision boundary! Please explain..
so in cost function grad is basically you doing gradient descent right? but what is the use of 1/m? i'm really confused sorry
While calculating cost function, we are doing sum (summation) operation over 'm' samples. And then dividing it by 'm' in order to scale the output (as a scaling factor).
Muje 55 marks hi aa rahe he mane code bhi sahi likha he phir bhi...logistic regression cost and regularised logistic regression gradient dono me 0 marks he..
i really confused in assignment, i enjoyed all the stuff that prof.Ng doing buat why it turns out to become nightmare when im face the programming assignment? In the cosfunctionreg.m why you put grad(1) = (1/m)* (X(:,1)'*(h_x-y)); whats this mean? grad(2:end) = (1/m)* (X(:,2:end)'*(h_x-y))+(lambda/m)*theta(2:end); what grad(2:end) mean?
These 2 lines are for calcuating gradient with regularization. since we don't add regularization term to 1st entry. (we have to write 2 seperate lines of code for it)
Hi dear Akshay. I'm trying to submit week 3 assignment but I keep seeing the error: !! Submission failed: unexpected error: Error: File: costFunctionReg.m Line: 22 Column: 3 Invalid expression. Check for missing or extra characters. Can you help me out?
I am getting a syntax error in exercise "CostfunctionReg.m" at grad(1) = (1/m)* (X(:,1)'*(h_x-y)); please tell me why am i getting this error. yes i am running it in octave but please don't tell me to go through the another link . please just tell me the issue.
!! Submission failed: Index exceeds array bounds. Function: getResponse LineNumber: 132of submitWithConfiguration
Here in the cost function though y and log(h_x) both have the same dimensions (mx1), how the dot product is possible between them?
We are not doing the dot product of y and log(h_x) while calculating cost function. Multiplication represented by dot astrix (.*) means element wise multiplication in matlab. Eg. -y.*log(h_x) Please check the code once again.
Our website uses cookies to improve your experience. Learn more
Contact form
Navigation Menu
Search code, repositories, users, issues, pull requests..., provide feedback.
We read every piece of feedback, and take your input very seriously.
Saved searches
Use saved searches to filter your results more quickly.
To see all available qualifiers, see our documentation .
andrew-ng-machine-learning
Here are 144 public repositories matching this topic..., greyhatguy007 / machine-learning-specialization-coursera.
Contains Solutions and Notes for the Machine Learning Specialization By Stanford University and Deeplearning.ai - Coursera (2022) by Prof. Andrew NG
- Updated Sep 29, 2024
- Jupyter Notebook
ashishpatel26 / Andrew-NG-Notes
This is Andrew NG Coursera Handwritten Notes.
- Updated Mar 7, 2024
nsoojin / coursera-ml-py
Python programming assignments for Machine Learning by Prof. Andrew Ng in Coursera
- Updated Sep 2, 2020
ajaymache / machine-learning-yearning
Machine Learning Yearning book by ๐ ฐ๏ธ ๐ท๐ญ๐ป๐ฎ๐ ๐
- Updated Dec 20, 2018
abdur75648 / Deep-Learning-Specialization-Coursera
This repo contains the updated version of all the assignments/labs (done by me) of Deep Learning Specialization on Coursera by Andrew Ng. It includes building various deep learning models from scratch and implementing them for object detection, facial recognition, autonomous driving, neural machine translation, trigger word detection, etc.
- Updated Feb 9, 2024
susilvaalmeida / machine-learning-andrew-ng
Implementations in python of methods and programming assignments of course Machine Learning of Coursera by Andrew Ng
- Updated May 30, 2020
azminewasi / Machine-Learning-AndrewNg-DeepLearning.AI
Contains all course modules, exercises and notes of ML Specialization by Andrew Ng, Stanford Un. and DeepLearning.ai in Coursera
- Updated Dec 5, 2023
nsoojin / coursera-ml-py-sj
- Updated Mar 24, 2017
azminewasi / Deep-Learning-AndrewNg-DeepLearning.AI
Contains all course modules, exercises and notes of Deep Learning Specialization by Andrew Ng, and DeepLearning.ai in Coursera
- Updated Jun 11, 2023
sohansai / machine-learning-andrew-ng
This repository contains codes of Andrew Ng's course Machine learning
- Updated Oct 6, 2023
greyhatguy007 / MachineLearningAndrewNG
Machine Learning Course - Coursera
- Updated Jun 11, 2022
VuBacktracking / Coursera-Machine-Learning-Specialization
Contains Optional Labs and Solutions of Programming Assignment for the Machine Learning Specialization By Stanford University and Deeplearning.ai - Coursera (2023) by Prof. Andrew NG
- Updated Sep 24, 2023
Zhenye-Na / coursera-ml
๐กThis repository contains all of the lecture exercises of Machine Learning course by Andrew Ng, Stanford University @ Coursera. All are implemented by myself and in MATLAB/Octave.
- Updated Mar 11, 2019
stamatelou / Machine-Learning-AndrewNg-SOLUTIONS
All the solutions from the programming assignments of the Machine Learning Course in Coursera taught by Andrew NG, Professor of Stanford University
- Updated Feb 2, 2020
thenomaniqbal / ML-assignments-coursera-andrew-ng-python
Solutions of the exercises of Andrew Ng's Machine Learning course available on Coursera (in Python).
- Updated Oct 20, 2024
EslamAsHhraf / Machine-Learning-Labs
๐ My solutions to practice labs in Machine Learning Specialization by Andrew Ng. I hope it will be helpful.
- Updated Oct 5, 2023
FMCalisto / machine-learning-stanford-coursera
Exercises and source code of the MOOC Course on Coursera for Machine Learning by Stanford University. The course was taught by Prof. Andrew Ng.
- Updated Apr 14, 2021
AbhiSaphire / MachineLearning-CourseraCourse-StanfordUniversity
This repo is for anyone who wants help in understanding and solving Andrew Ng's Coursera Course on Machine Learning Assignments and Quizes. (YEAR 2020)
- Updated May 19, 2020
A-sad-ali / Machine-Learning-Specialization
- Updated Jul 27, 2024
arasgungore / Stanford-Machine-Learning
My solutions to the assignments in the Machine Learning Specialization offered by Stanford University on Coursera.
- Updated Jan 15, 2024
Improve this page
Add a description, image, and links to the andrew-ng-machine-learning topic page so that developers can more easily learn about it.
Curate this topic
Add this topic to your repo
To associate your repository with the andrew-ng-machine-learning topic, visit your repo's landing page and select "manage topics."
COMMENTS
Contains Solutions and Notes for the Machine Learning Specialization by Andrew NG on Coursera. Note : If you would like to have a deeper understanding of the concepts by understanding all the math required, have a look at Mathematics for Machine Learning and Data Science
*This Repository Contains Solution to the Assignments of the Machine Learning Specialization from deeplearning.ai on Coursera Taught by Andrew Ng. ... This 3-course Specialization is an updated version of Andrew's pioneering Machine Learning course, rated 4.9 out of 5 and taken by over 4.8 million learners since it launched in 2012. ...
This repositry contains the python versions of the programming assignments for the Machine Learning online class taught by Professor Andrew Ng. This is perhaps the most popular introductory online machine learning class. In addition to being popular, it is also one of the best Machine learning ...
54. One-vs-all logistic regression and neural networks to recognize hand-written digits. I have recently completed the Machine Learning course from Coursera by Andrew NG. While doing the course we have to go through various quiz and assignments. Here, I am sharing my solutions for the weekly assignments throughout the course.
by Akshay Daga (APDaga) - April 25, 2021. 4. The complete week-wise solutions for all the assignments and quizzes for the course "Coursera: Machine Learning by Andrew NG" is given below: Recommended Machine Learning Courses: Coursera: Machine Learning. Coursera: Deep Learning Specialization.
61. Logistic regression and apply it to two different datasets. I have recently completed the Machine Learning course from Coursera by Andrew NG. While doing the course we have to go through various quiz and assignments. Here, I am sharing my solutions for the weekly assignments throughout the course. These solutions are for reference only.
This is super late, but thank you for this post, as I only discovered Andrew Ng's course because of this. Amazingly good for both discovering the math, concepts, computational approaches and real life situations for machine learning from beginner to near expert levels. Especially because your example with Python are extremely relevant for me.
This repo contains the updated version of all the assignments/labs (done by me) of Deep Learning Specialization on Coursera by Andrew Ng. It includes building various deep learning models from scratch and implementing them for object detection, facial recognition, autonomous driving, neural machine translation, trigger word detection, etc.
Edit: to be clear, this repo linked below in the comments is the assignments as you see them in the course, and it allows you to submit the assignments using python instead of octave/Matlab. Clone this repo on your local machine and work on it through there. This repo here is the assignments with the solutions If you get stuck you can use this ...
Hi everyone, I recently completed Andrew Ng's three courses in machine learning through Coursera. In light of what was once a free offering that is now paid, I have open sourced my notes and submissions for the lab assignments, in hopes people can follow along with the material.