from helpers import visualize_cost_function import numpy as np def loss_function(sizes, prices, weight0, weight1): predictions = [weight0 + weight1*sizes[i] for i in range(len(prices))] return sum([(predictions[i] - prices[i])**2 for i in range(len(prices))])/(2*len(prices)) def loss_function2(sizes, prices, weight0, weight1): predictions = [weight0 + weight1*sizes[i] for i in range(len(prices))] return sum([(np.sin(predictions[i]/prices[i]**2) * (predictions[i]*prices[i]**3)) for i in range(len(prices))])/(2*len(prices)) #Poniższy kod wyznacza wartości funkcji kosztu w dziedzinie wartości atrybutów w0 i w1 w0_values = np.arange(-10, 10, 0.5) w1_values = np.arange(-10, 10, 0.5) sizes_transformed = ((sizes - np.mean(sizes)) / np.std(sizes)).reshape(-1) prices_transformed = ((prices - np.mean(prices)) / np.std(prices)).reshape(-1) w0_values = np.arange(-100, 100, 5) w1_values = np.arange(-100, 100, 5) visualize_cost_function(sizes_transformed, prices_transformed, w0_values, w1_values, loss_function) visualize_cost_function(sizes_transformed, prices_transformed, w0_values, w1_values, loss_function2)