faridcher / ml-course

Starter code of Prof. Andrew Ng's machine learning MOOC in R statistical language
https://www.coursera.org/learn/machine-learning
172 stars 148 forks source link

Typo in gradientdescentmulti.R in starter ex1 #5

Closed djanesh closed 7 years ago

djanesh commented 7 years ago

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.

faridcher commented 7 years ago

Thanks for reporting. I pushed a commit to fix this typo.