Skip to content

Exercise 3 #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JingxinLee opened this issue May 7, 2019 · 2 comments
Open

Exercise 3 #28

JingxinLee opened this issue May 7, 2019 · 2 comments

Comments

@JingxinLee
Copy link

JingxinLee commented May 7, 2019

`
def oneVsAll(X, y, num_labels, lambda_):
# Some useful variables
m, n = X.shape

# You need to return the following variables correctly 
all_theta = np.zeros((num_labels, n + 1))

# Add ones to the X data matrix
X = np.concatenate([np.ones((m, 1)), X], axis=1)

# ====================== YOUR CODE HERE ======================
initial_theta = np.zeros((n+1,1)) 
options = {'maxiter': 50}
for c in np.arange(1, num_labels+1):
    res = optimize.minimize(lrCostFunction, 
                            initial_theta, 
                            (X, (y == c), lambda_), 
                            jac=True, 
                            method='TNC',
                            options=options) 
    all_theta[c-1] = res.x


# ============================================================
return all_theta

`

Hi,Dib,
Could you please tell me what's wrong with my code? I am confused.
Thanks.

@nirmalhk7
Copy link

nirmalhk7 commented Mar 29, 2020

I'm facing problems in the same block. Here's my code:
`
# Some useful variables
m, n = X.shape

# You need to return the following variables correctly 
ll_theta = np.zeros((num_labels, n + 1))

# Add ones to the X data matrix
X = np.concatenate([np.ones((m, 1)), X], axis=1)

# ====================== YOUR CODE HERE ======================
for c in np.arange(num_labels):
    initial_theta=np.zeros(n+1)
    options={'maxiter':50}
    res=optimize.minimize(lrCostFunction,initial_theta,(X,(y==c),lambda_),jac=True,method='TNC',options=options)
    all_theta[c]=res.x
# ============================================================
return all_theta`

I'm able to call the function without errors, from the next block
lambda_ = 0.1 all_theta = oneVsAll(X, y, num_labels, lambda_)

Then, when I try to submit the work, no error is thrown, but following is the result:
Screenshot from 2020-03-29 15-00-35

The scores aren't shown on Coursera either. Please help.

Thanks!

@Julescorbara
Copy link

#6 Fixes this issue, the author used the wrong minimization method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants