# theta = 0.5 # y_pred = sigmoid_(x * theta) # m = 1 # length of y_true is 1 # print(log_loss_(y_true, y_pred, m)) # 0.12692801104297152 # # Test n.2 # x = [1, 2, 3, 4] # y_true = 0 # theta = [-1.5, 2.3, 1.4, 0.7] # x_dot_theta = sum([a*b for a, b in zip(x, theta)]) # y_pred = sigmoid_(x_dot_theta) # m = 1 # print(log_loss_(y_true, y_pred, m)) # # 10.100041078687479 # # # Test n.3 x_new = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] y_true = [1, 0, 1] theta = [-1.5, 2.3, 1.4, 0.7] x_dot_theta = [] for i in range(len(x_new)): my_sum = 0 # for j in range(len(x_new[i])): # my_sum += x_new[i][j] * theta[j] my_sum = sum([a * b for a, b in zip(x_new[i], theta)]) x_dot_theta.append(my_sum) y_pred = sigmoid_(x_dot_theta) m = len(y_true) print(log_loss_(y_true, y_pred, m)) # # 7.233346147374828
import numpy as np from log_loss import log_loss_ from log_pred import logistic_predict_ y1 = np.array([1]) x1 = np.array([4]) theta1 = np.array([[2], [0.5]]) y_hat1 = logistic_predict_(x1, theta1) print(log_loss_(y1, y_hat1)) print("---------------------------------------") # Output: # 0.01814992791780973 # Example 2: y2 = np.array([[1], [0], [1], [0], [1]]) x2 = np.array([[4], [7.16], [3.2], [9.37], [0.56]]) theta2 = np.array([[2], [0.5]]) y_hat2 = logistic_predict_(x2, theta2) print(log_loss_(y2, y_hat2)) print("---------------------------------------") # Output: # 2.4825011602474483 # Example 3: y3 = np.array([[0], [1], [1]]) x3 = np.array([[0, 2, 3, 4], [2, 4, 5, 5], [1, 3, 2, 7]]) theta3 = np.array([[-2.4], [-1.5], [0.3], [-1.4], [0.7]]) y_hat3 = logistic_predict_(x3, theta3) print(log_loss_(y3, y_hat3)) print("---------------------------------------") # Output: