Git Product home page Git Product logo

ml-course's Introduction

Introduction

This is one of the best massive open online courses (MOOCs) on machine learning and is taught by Prof. Andrew NG. However, Prof. NG teaches the course along with MATLAB/Octave and the programming exercises must be done and submitted with either of them. Do you like the course but not the proprietary MATLAB or the sluggish Octave? Or for any reason, would you rather to use the free GNU R to complete the programming exercises?

To watch the lecture videos and slides please visit the course original website. This repository provides the starter code to solve the programming exercises in R statistical software. Simply follow these steps to complete the programming exercises:

  1. Watch the lecture videos
  2. Read R compatible version of instructions which are available as wiki pages
  3. fill the parts of the code that are written "YOUR CODE HERE"
  4. If you couldn't solve it by yourself, get help from the accompanied file suffixed by -solution inside the same directory of the starter code. For example, starter/ex1/computeCost.r has an associated solution file named starter/ex1/computeCost-solution.r
  5. Submit

Dependencies

In order to produce similar results and plots to Octave/MATLAB, you should install a few packages (install.packages(c('rgl','lbfgsb3c','SnowballC','jsonlite', 'httr'))):

  • rgl package is used to produce the 3D scatter plots and surface plots in the exercises 1 and 7.
  • lbfgsb3c: to solve large optimization tasks in exercises 4 and 8
  • SnowballC: portStemmer function in this package plays the same role of the portStemmer.m in exercise 6
  • jsonlite and httr packages are needed for submissions.

Furthermore, the ginv (generalized inverse) function in MASS package doesn't produce the same result of the MATLAB pinv (pseudo-inverse). So lib/pinv.r is the modified version of MASS::ginv to produce the same result of the MATLAB pinv.

Submission

After completing each assignment, source("submit.r") and then submit() in your R console. I submitted the solutions to Coursera for testing and the scores were 100%. Please report any problems with submission here.

Licence

This project is released under MIT to the extent it is original.

ml-course's People

Contributors

faridcher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ml-course's Issues

Typo in gradientdescentmulti.R in starter ex1

The following is the original code from your starter section

gradientDescentMulti <- function(X, y, theta, alpha, num_iters) {
  #GRADIENTDESCENTMULTI Performs gradient descent to learn theta
  #   theta <- GRADIENTDESCENTMULTI(x, y, theta, alpha, num_iters) updates theta by
  #   taking num_iters gradient steps with learning rate alpha
  
  # Initialize some useful values
  m <- length(y) # number of training examples
  J_history <- rep(0,num_iters)
  
  for (iter in 1:num_iters) {
    # ---------------------- YOUR CODE HERE ----------------------
    # Instructions: Perform a single gradient step on the parameter vector
    #               theta.
    #
    # Hint: While debugging, it can be useful to print out the values
    #       of the cost function (computeCostMulti) and gradient here.
    #
    
    
    }
    
    # ------------------------------------------------------------
    
    # Save the cost J in every iteration
    J_history[iter] <- computeCostMulti(X, y, theta)
    
  }
  list(theta = theta, J_history = J_history)
}

We get following error

> submit()
== Submitting solutions | Linear Regression with Multiple Variables... 
Login (email address): 
username(#replaced)
token:
token(#replaced)
!! Submission failed: unexpected error: gradientDescentMulti.R:29:1: unexpected '}'
28:   list(theta = theta, J_history = J_history)
29: }
    ^
!! Please try again later.
Error in response$errorMessage : 
  object of type 'special' is not subsettable

The curly brace above save the cost J in every iteration should be commented out. The issue pointed by one of the user might be because of this. After commenting that curly brace, the program is working fine. Thanks for developing this and making available for free.

Problems with submission

Hi, I've been having a problem with submission (please see below).

Do you have any idea why this might be happening?

Cheers
Bob

source("submit.r")
submit()
== Submitting solutions | Linear Regression with Multiple Variables...
Login (email address):
[email protected]
token:
4BIEsjivD1WGjERU
!! Submission failed: unexpected error: gradientDescentMulti.R:29:1: unexpected '}'
28: list(theta = theta, J_history = J_history)
29: }
^
!! Please try again later.
Error in response$errorMessage :
object of type 'special' is not subsettable

why Theta is called as a subfunction

Hi Fared,
Curios to know why you create function within function (Theta as a subfunction of cost function).
For example,

linearRegCostFunction <- function(X, y, lambda) {
function(theta) {

why not
linearRegCostFunction <- function(X, y, lambda,theta) {

Is it just a coding style or there is a particular reason.

Thanks in advance.

Submission error

Hi
First things first, thank you for this very good resource for leaarning maching learning. May the good lord continue to bless you.

However I have an error in running ex1.R.
I keep getting this error message below

Running warmUpExercise ...
5x5 Identity Matrix:
Error in warmUpExercise() : object 'A' not found

Any help.
Thanks

P.S I have tried this also.. same result

source("D:/UIUC PHD/MACHINE LEARNING/COURSERA/EXERCISES/1/ex1.R")
Running warmUpExercise ...
5x5 Identity Matrix:
Error in warmUpExercise() : object 'A' not found

Problem with submission

Thank you so much for creating this repository. This is exactly what I need! I am very eager to get this up and running, however, in testing it out, when trying to submit the warm up exercise in exercise 1, I get the following error message:

!! Submission failed: unexpected error: object 'A' not found
!! Please try again later.Error: object of type 'special' is not subsettable

This error occurs after entering my coursera email and the token.

Attached is the exact code which I run to produce the error, and below is some info regarding my R version and ubuntu system:

Any help on this issue would be great.
Thanks again!

R.Version()
$platform
[1] "x86_64-pc-linux-gnu"

$arch
[1] "x86_64"

$os
[1] "linux-gnu"

$system
[1] "x86_64, linux-gnu"

$status
[1] ""

$major
[1] "3"

$minor
[1] "4.2"

$year
[1] "2017"

$month
[1] "09"

$day
[1] "28"

$svn rev
[1] "73368"

$language
[1] "R"

$version.string
[1] "R version 3.4.2 (2017-09-28)"

$nickname
[1] "Short Summer"

submission problem warm up.txt

pred <- predict(Theta1, Theta2, X[rp[1],]) Error in rep(0, m) : invalid 'times' argument

Hi Fared,
The 94th line of the ex3_nn.R reads as follows:
pred <- predict(Theta1, Theta2, X[rp[i],])

It is called from inside this loop:
for (i in 1:m){
pred <- predict(Theta1, Theta2, X[rp[i],])
}

I am getting the following error:

pred <- predict(Theta1, Theta2, X[rp[1],])
Error in rep(0, m) : invalid 'times' argument

The predict function worked fine when it was invoked the first time in the same program at line 76
pred <- predict(Theta1, Theta2, X)

I could not find anything wrong with the repeat command used inside the predict function at row 14
p <- rep(0,m) where m <- dim(X)[1]

I am not sure if the function results are cached in R the first time which causes problem when called again.

Can you please help.

https://github.com/faridcher/machine-learning-course/blob/master/Solutions/mlclass-ex3/ex3_nn.R

Matlab file to R file (.mat to .Rda) converstion

Hello Farid,
I am a newbie in R; finding your Github repository very useful in coming up to speed.

Can you please help me understand how you converted a matlab file (.mat) into an R file (.Rda)

https://github.com/faridcher/ machine-learning-course/tree/ master/Starter/mlclass-ex3

from ex3data1.mat in matlab to
'ex3data1.Rda'

Thank you for the help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.