始める無料で始める

ロジスティック損失とヒンジ損失の比較

この演習では、与えられた数式を使ってロジスティック損失とヒンジ損失をプロットします。

右側には、動画で示した損失関数の図が表示されています。

この演習はコースの一部です

Python で学ぶ線形分類器

コースを見る

演習の手順

  • log_loss()hinge_loss()グリッド上の点で評価し、プロットされるようにしてください。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# 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()
コードを編集して実行