{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "kernelspec": { "display_name": "TensorFlow 2.3 on Python 3.6 (CUDA 10.1)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.9" }, "colab": { "name": "8-2.cross_entropy_cost.ipynb", "provenance": [] } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "fQB6ZKNtxuDH" }, "source": [ "# 크로스-엔트로피 비용" ] }, { "cell_type": "markdown", "metadata": { "id": "004gwPu2xuDI" }, "source": [ "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/rickiepark/dl-illustrated/blob/master/notebooks/8-2.cross_entropy_cost.ipynb)" ] }, { "cell_type": "code", "metadata": { "id": "kq-jnBk_xuDJ" }, "source": [ "from numpy import log" ], "execution_count": 1, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "-yTMedoVxuDJ" }, "source": [ "def cross_entropy(y, a):\n", " return -1*(y*log(a) + (1-y)*log(1-a))" ], "execution_count": 2, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "QqGaMAq3xuDJ", "outputId": "84bb0537-1736-49c3-f7b8-1355c530d9be", "colab": { "base_uri": "https://localhost:8080/" } }, "source": [ "cross_entropy(1, 0.9997)" ], "execution_count": 3, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "0.00030004500900199243" ] }, "metadata": {}, "execution_count": 3 } ] }, { "cell_type": "code", "metadata": { "id": "9FyZb-tBxuDK", "outputId": "d8818fb4-8347-4f45-82b4-d8e934df91b9", "colab": { "base_uri": "https://localhost:8080/" } }, "source": [ "cross_entropy(1, 0.9)" ], "execution_count": 4, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "0.10536051565782628" ] }, "metadata": {}, "execution_count": 4 } ] }, { "cell_type": "code", "metadata": { "id": "IdYOQHidxuDK", "outputId": "dba711e2-e93b-4445-b32a-04f711201ac4", "colab": { "base_uri": "https://localhost:8080/" } }, "source": [ "cross_entropy(1, 0.6)" ], "execution_count": 5, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "0.5108256237659907" ] }, "metadata": {}, "execution_count": 5 } ] }, { "cell_type": "code", "metadata": { "id": "OcmAQFQ8xuDL", "outputId": "9ffe2b51-8632-4407-b802-89edf91ad65b", "colab": { "base_uri": "https://localhost:8080/" } }, "source": [ "cross_entropy(1, 0.1192)" ], "execution_count": 6, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "2.1269525243508878" ] }, "metadata": {}, "execution_count": 6 } ] }, { "cell_type": "code", "metadata": { "id": "xLfOM7cBxuDL", "outputId": "5082b508-4721-40b6-de6b-9156f14efdcc", "colab": { "base_uri": "https://localhost:8080/" } }, "source": [ "cross_entropy(0, 0.1192)" ], "execution_count": 7, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "0.1269246935736668" ] }, "metadata": {}, "execution_count": 7 } ] }, { "cell_type": "code", "metadata": { "id": "AaGPBQ92xuDL", "outputId": "dc139833-0771-4141-c6bf-9764cbe647b5", "colab": { "base_uri": "https://localhost:8080/" } }, "source": [ "cross_entropy(1, 1-0.1192)" ], "execution_count": 8, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "0.1269246935736668" ] }, "metadata": {}, "execution_count": 8 } ] } ] }