BaşlayınÜcretsiz Başlayın

Comparing the logistic and hinge losses

In this exercise you'll create a plot of the logistic and hinge losses using their mathematical expressions, which are provided to you.

The loss function diagram from the video is shown on the right.

Bu egzersiz

Linear Classifiers in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Evaluate the log_loss() and hinge_loss() functions at the grid points so that they are plotted.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Mathematical functions for logistic and hinge losses
def log_loss(raw_model_output):
   return np.log(1+np.exp(-raw_model_output))
def hinge_loss(raw_model_output):
   return np.maximum(0,1-raw_model_output)

# Create a grid of values and plot
grid = np.linspace(-2,2,1000)
plt.plot(grid, ____, label='logistic')
plt.plot(grid, ____, label='hinge')
plt.legend()
plt.show()
Kodu Düzenle ve Çalıştır