AssertionError sur Jupyter (Python)
RésoluSalut à vous
Je travaille sur un algorithme Python (dans Jupyter) qui m'affiche une erreur d'assertion. Je ne sais pas comment la résoudre. Voici l'algorithme:
import numpy as np import matplotlib.pyplot as plt from utils import * import copy import math %matplotlib inline # load the dataset x_train, y_train = load_data() # print x_train print("Type of x_train:",type(x_train)) print("First five elements of x_train are:\n", x_train[:5]) # print y_train print("Type of y_train:",type(y_train)) print("First five elements of y_train are:\n", y_train[:5]) print ('The shape of x_train is:', x_train.shape) print ('The shape of y_train is: ', y_train.shape) print ('Number of training examples (m):', len(x_train)) # Create a scatter plot of the data. To change the markers to red "x", # we used the 'marker' and 'c' parameters plt.scatter(x_train, y_train, marker='x', c='r') # Set the title plt.title("Profits vs. Population per city") # Set the y-axis label plt.ylabel('Profit in $10,000') # Set the x-axis label plt.xlabel('Population of City in 10,000s') plt.show() # Compute cost with some initial values for paramaters w, b initial_w = 2 initial_b = 1 cost = compute_cost(x_train, y_train, initial_w, initial_b) print(type(cost)) print(f'Cost at initial w:{cost:0.3f}') # Public tests from public_tests import * compute_cost_test(compute_cost)
Et voici l'erreur:
AssertionError Traceback (most recent call last)
<ipython-input-85-0fe06c9a435b> in <module>
9 # Public tests
10 from public_tests import *
---> 11 compute_cost_test(compute_cost)
~/work/public_tests.py in compute_cost_test(target)
17 initial_b = 1.0
18 cost = target(x, y, initial_w, initial_b)
---> 19 assert cost == 2, f"Case 2: Cost must be 2 but got {cost}"
20
21 # print("Using X with shape (5, 1)")
AssertionError: Case 2: Cost must be 2 but got 0.5
Pouvez-vous m'éclairer s'il vous plaît ?
Merci d'avance.