Skip to content

Exercise 3 #28

@JingxinLee

Description

@JingxinLee

`
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions