Unable to solve question 3,4 and 5 of W3_Practice lab

My error part:
NameError Traceback (most recent call last)
in
1 # Compute and display gradient with w and b initialized to zeros
----> 2 initial_w = np.zeros(n)
3 initial_b = 0.
4
5 dj_db, dj_dw = compute_gradient(X_train, y_train, initial_w, initial_b)

NameError: name ‘n’ is not defined

Expected Output:

dj_db at initial w and b (zeros) -0.1
dj_dw at initial w and b (zeros): [-12.00921658929115, -11.262842205513591]

Compute and display cost and gradient with non-zero w and b

test_w = np.array([ 0.2, -0.5])
test_b = -24
dj_db, dj_dw = compute_gradient(X_train, y_train, test_w, test_b)

print(‘dj_db at test w and b:’, dj_db)
print(‘dj_dw at test w and b:’, dj_dw.tolist())

UNIT TESTS

compute_gradient_test(compute_gradient)

NameError Traceback (most recent call last)
in
2 test_w = np.array([ 0.2, -0.5])
3 test_b = -24
----> 4 dj_db, dj_dw = compute_gradient(X_train, y_train, test_w, test_b)
5
6 print(‘dj_db at test w and b:’, dj_db)

NameError: name ‘X_train’ is not defined

Expected Output:

dj_db at test w and b (non-zeros) -0.5999999999991071
dj_dw at test w and b (non-zeros): [-44.8313536178737957, -44.37384124953978]

initial_w = 0.01 * (np.random.rand(2) - 0.5)
initial_b = -8

Some gradient descent settings

iterations = 10000
alpha = 0.001

w,b, J_history,_ = gradient_descent(X_train ,y_train, initial_w, initial_b,
compute_cost, compute_gradient, alpha, iterations, 0)

ameError Traceback (most recent call last)
in
----> 1 np.random.seed(1)
2 initial_w = 0.01 * (np.random.rand(2) - 0.5)
3 initial_b = -8
4
5 # Some gradient descent settings

NameError: name ‘np’ is not defined

Expected Output: Cost 0.30, (Click to see details):

plot_decision_boundary(w, b, X_train, y_train)

Set the y-axis label

plt.ylabel(‘Exam 2 score’)

Set the x-axis label

plt.xlabel(‘Exam 1 score’)
plt.legend(loc=“upper right”)
plt.show()

NameError Traceback (most recent call last)
in
----> 1 plot_decision_boundary(w, b, X_train, y_train)
2 # Set the y-axis label
3 plt.ylabel(‘Exam 2 score’)
4 # Set the x-axis label
5 plt.xlabel(‘Exam 1 score’)

NameError: name ‘w’ is not defined

UNQ_C4

GRADED FUNCTION: predict

TypeError Traceback (most recent call last)
in
5 tmp_X = np.random.randn(4, 2) - 0.5
6
----> 7 tmp_p = predict(tmp_X, tmp_w, tmp_b)
8 print(f’Output of predict: shape {tmp_p.shape}, value {tmp_p}')
9

in predict(tmp_X, tmp_w, tmp_b)
11
12
—> 13 for iteration in range(tmp_X):
14 # Compute predictions
15 tmp_X = np.dot(tmp_X, theta)

TypeError: only integer scalar arrays can be converted to a scalar index
Expected output

Output of predict: shape (4,),value [0. 1. 1. 1.]
NameError Traceback (most recent call last)
in
1 #Compute accuracy on our training set
----> 2 p = predict(X_train, w,b)
3 print('Train Accuracy: f'(np.mean(p == y_train) * 100))

NameError: name ‘X_train’ is not defined

Train Accuracy (approx): 92.00

NameError Traceback (most recent call last)
in
1 # load dataset
----> 2 X_train, y_train = load_data(“data/ex2data2.txt”)

NameError: name ‘load_data’ is not defined

NameError Traceback (most recent call last)
in
1 # print X_train
----> 2 print(“X_train:”, X_train[:5])
3 print(“Type of X_train:”,type(X_train))
4
5 # print y_train

NameError: name ‘X_train’ is not defined

NameError Traceback (most recent call last)
in
----> 1 print ('The shape of X_train is: ’ + str(X_train.shape))
2 print ('The shape of y_train is: ’ + str(y_train.shape))
3 print ('We have m = d training examples' (len(y_train)))

NameError: name ‘X_train’ is not defined

NameError Traceback (most recent call last)
in
1 # Plot examples
----> 2 plot_data(X_train, y_train[:], pos_label=“Accepted”, neg_label=“Rejected”)
3
4 # Set the y-axis label
5 plt.ylabel(‘Microchip Test 2’)

NameError Traceback (most recent call last)
in
1 # Plot examples
----> 2 plot_data(X_train, y_train[:], pos_label=“Accepted”, neg_label=“Rejected”)
3
4 # Set the y-axis label
5 plt.ylabel(‘Microchip Test 2’)

NameError: name ‘plot_data’ is not defined

NameError: name ‘plot_data’ is not defined

NameError Traceback (most recent call last)
in
----> 1 print(“X_train[0]:”, X_train[0])
2 print(“mapped X_train[0]:”, mapped_X[0])

NameError: name ‘X_train’ is not defined

UNQ_C5

File “”, line 2
def compute_cost_reg(X, y, w, b, lambda_ = 1):
^
IndentationError: unexpected indent

NameError Traceback (most recent call last)
in
----> 1 X_mapped = map_feature(X_train[:, 0], X_train[:, 1])
2 np.random.seed(1)
3 initial_w = np.random.rand(X_mapped.shape[1]) - 0.5
4 initial_b = 0.5
5 lambda_ = 0.5
NameError: name ‘map_feature’ is not defined

Expected Output:

Regularized cost : 0.6618252552483948

UNQ_C6

NameError Traceback (most recent call last)
in
----> 1 X_mapped = map_feature(X_train[:, 0], X_train[:, 1])
2 np.random.seed(1)
3 initial_w = np.random.rand(X_mapped.shape[1]) - 0.5
4 initial_b = 0.5
5

NameError: name ‘map_feature’ is not defined
Expected Output:

**dj_db:**0.07138288792343
First few elements of regularized dj_dw:
[[-0.010386028450548], [0.011409852883280], [0.0536273463274], [0.003140278267313]]
NameError Traceback (most recent call last)
in
2 import numpy as np
3 np.random.seed(1)
----> 4 initial_w = np.random.rand(X_mapped.shape[1])-0.5
5 initial_b = 1.
6

NameError: name ‘X_mapped’ is not defined
Expected Output: Cost < 0.5 (Click for details)
NameError Traceback (most recent call last)
in
----> 1 plot_decision_boundary(w, b, X_mapped, y_train)
2 # Set the y-axis label
3 plt.ylabel(‘Microchip Test 2’)
4 # Set the x-axis label
5 plt.xlabel(‘Microchip Test 1’)

NameError: name ‘plot_decision_boundary’ is not defined

NameError Traceback (most recent call last)
in
1 #Compute accuracy on the training set
----> 2 p = predict(X_mapped, w, b)
3
4 print('Train Accuracy: f'(np.mean(p == y_train) * 100))

NameError: name ‘predict’ is not defined

Expected Output:

Train Accuracy:~ 80%

Seems to me you are in great need of some python language course because these errors are pretty simple. In coursera you have some pretty good python courses to take :slight_smile:

You have to run all the above cells.

I am not been able to edit test code and some other codes.How can I run the codes?Can you please see my code and tell me where I am wrong?I am not being able to edit the code.So,even if there is problem with test code I cannot edit it.
Even if I have used different code still it’s not running. Please give me access to edit it.

I request you to look into the matter and take necessary action . KIndly allow me to edit the test code so that I may pass the and start the next course of this specialization.

You are not supposed to edit any test cells. Simply write your code where instructed.

The problem is that you are not running the above cells. In the menu bar, click on Cell → Run All Above.