Skip to content

Commit 83ca90a

Browse files
committed
feat(logloss) init
1 parent 9a11fcf commit 83ca90a

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

7 Log loss.ipynb

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Thinking in tensors, writing in PyTorch\n",
8+
"\n",
9+
"Hands-on training by [Piotr Migdał](https://p.migdal.pl) (2019). Version for Uniwersytet Śląski.\n",
10+
"\n",
11+
"**WORK IN PROGRESS**\n",
12+
"\n",
13+
"\n",
14+
"## Log loss\n",
15+
"\n",
16+
"Multi-class logistic regression can be expressed as a shallow neural network consisting of one linear layer and a softmax activation function.\n",
17+
"\n",
18+
"For binary classification, we can use sigmoid (a.k.a. logistic function):\n",
19+
"\n",
20+
"$$ \\sigma(x) = \\frac{1}{1+\\exp(-x)} $$\n",
21+
"\n",
22+
"Softmax function transforms any vector into distribution vector (values in range (0., 1.) that sum up to 1.):\n",
23+
"$$\\text{softmax}(x_i) = \\frac{\\exp(x_i)}{\\sum_j \\exp(x_j)}$$\n",
24+
"\n",
25+
"We use a cross-entropy loss function:\n",
26+
"$$- \\sum_j p_{j, true} \\log(p_{j, pred})$$\n",
27+
"\n",
28+
"Note that we do not state explicitly the softmax function in the model class below. For details see [torch.nn.CrossEntropyLoss](https://pytorch.org/docs/stable/nn.html#torch.nn.CrossEntropyLoss).\n",
29+
"\n",
30+
"See also:\n",
31+
"\n",
32+
"* [Cross-entropy vs. mean-squared error loss](https://www.reddit.com/r/MachineLearning/comments/8im9eb/d_crossentropy_vs_meansquared_error_loss/)\n",
33+
"* [Understanding binary cross-entropy / log loss: a visual explanation](https://towardsdatascience.com/understanding-binary-cross-entropy-log-loss-a-visual-explanation-a3ac6025181a)\n",
34+
"* [Cross entropy](https://pandeykartikey.github.io/machine/learning/basics/2018/05/22/cross-entropy.html) - another explanation\n",
35+
"* [Softmax function](https://en.wikipedia.org/wiki/Softmax_function)\n",
36+
"* [Multiclass logistic regression](https://en.wikipedia.org/wiki/Multinomial_logistic_regression)"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": 1,
42+
"metadata": {},
43+
"outputs": [],
44+
"source": [
45+
"import numpy as np"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": null,
51+
"metadata": {},
52+
"outputs": [],
53+
"source": []
54+
}
55+
],
56+
"metadata": {
57+
"kernelspec": {
58+
"display_name": "Python [conda env:py37]",
59+
"language": "python",
60+
"name": "conda-env-py37-py"
61+
},
62+
"language_info": {
63+
"codemirror_mode": {
64+
"name": "ipython",
65+
"version": 3
66+
},
67+
"file_extension": ".py",
68+
"mimetype": "text/x-python",
69+
"name": "python",
70+
"nbconvert_exporter": "python",
71+
"pygments_lexer": "ipython3",
72+
"version": "3.7.2"
73+
},
74+
"varInspector": {
75+
"cols": {
76+
"lenName": 16,
77+
"lenType": 16,
78+
"lenVar": 40
79+
},
80+
"kernels_config": {
81+
"python": {
82+
"delete_cmd_postfix": "",
83+
"delete_cmd_prefix": "del ",
84+
"library": "var_list.py",
85+
"varRefreshCmd": "print(var_dic_list())"
86+
},
87+
"r": {
88+
"delete_cmd_postfix": ") ",
89+
"delete_cmd_prefix": "rm(",
90+
"library": "var_list.r",
91+
"varRefreshCmd": "cat(var_dic_list()) "
92+
}
93+
},
94+
"types_to_exclude": [
95+
"module",
96+
"function",
97+
"builtin_function_or_method",
98+
"instance",
99+
"_Feature"
100+
],
101+
"window_display": false
102+
}
103+
},
104+
"nbformat": 4,
105+
"nbformat_minor": 2
106+
}

0 commit comments

Comments
 (0)