|
1 | 1 | {
|
2 | 2 | "cells": [
|
3 | 3 | {
|
| 4 | + "attachments": {}, |
4 | 5 | "cell_type": "markdown",
|
5 | 6 | "metadata": {},
|
6 | 7 | "source": [
|
7 | 8 | "# Thinking in tensors, writing in PyTorch\n",
|
8 | 9 | "\n",
|
9 |
| - "A hands-on course by [Piotr Migdał](https://p.migdal.pl) (2019).\n", |
| 10 | + "A hands-on course by [Piotr Migdał](https://p.migdal.pl) (2019-2022).\n", |
10 | 11 | "This notebook prepared by [Weronika Ormaniec](https://github.com/werkaaa) and Piotr Migdał.\n",
|
11 | 12 | "\n",
|
12 | 13 | "## Notebook 3: Linear regression\n",
|
|
30 | 31 | "In Python we typically use [LinearRegression from scikit-learn](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html). Here we use PyTorch to show everything step-by-step. Moreover, linear regression is a building block of any regression with deep learning - so it is good to understand it well!"
|
31 | 32 | ]
|
32 | 33 | },
|
33 |
| - { |
34 |
| - "cell_type": "code", |
35 |
| - "execution_count": null, |
36 |
| - "metadata": {}, |
37 |
| - "outputs": [], |
38 |
| - "source": [ |
39 |
| - "!pip install --quiet 'livelossplot<0.5'" |
40 |
| - ] |
41 |
| - }, |
42 | 34 | {
|
43 | 35 | "cell_type": "code",
|
44 | 36 | "execution_count": null,
|
|
53 | 45 | "import torch.nn as nn\n",
|
54 | 46 | "\n",
|
55 | 47 | "from livelossplot import PlotLosses\n",
|
| 48 | + "from livelossplot.outputs import MatplotlibPlot\n", |
56 | 49 | "from ipywidgets import interact, fixed"
|
57 | 50 | ]
|
58 | 51 | },
|
|
144 | 137 | "metadata": {},
|
145 | 138 | "outputs": [],
|
146 | 139 | "source": [
|
147 |
| - "X = np.log(data['BodyWeight(kg)'])\n", |
148 |
| - "Y = np.log(data['BrainWeight(kg)'])" |
| 140 | + "X = np.log(data['BodyWeight(kg)']).astype('float32')\n", |
| 141 | + "Y = np.log(data['BrainWeight(kg)']).astype('float32')" |
149 | 142 | ]
|
150 | 143 | },
|
151 | 144 | {
|
|
394 | 387 | " plt.title(\"Prediction\")\n",
|
395 | 388 | " plt.legend(loc='lower right')\n",
|
396 | 389 | " \n",
|
397 |
| - " liveloss = PlotLosses(extra_plots=[extra_plot], plot_extrema=False)\n", |
| 390 | + " liveloss = PlotLosses()\n", |
398 | 391 | " \n",
|
399 | 392 | " for i in range(num_epochs):\n",
|
400 | 393 | " A -= learning_rate * dL_da(A, B, X, Y)\n",
|
|
586 | 579 | " plt.title(\"Prediction\")\n",
|
587 | 580 | " plt.legend(loc='lower right')\n",
|
588 | 581 | " \n",
|
589 |
| - " liveloss = PlotLosses(extra_plots=[extra_plot], plot_extrema=False)\n", |
| 582 | + " liveloss = PlotLosses()\n", |
590 | 583 | "\n",
|
591 | 584 | " for epoch in range(num_epochs):\n",
|
592 | 585 | " \n",
|
|
751 | 744 | "\n",
|
752 | 745 | "\n"
|
753 | 746 | ]
|
| 747 | + }, |
| 748 | + { |
| 749 | + "cell_type": "markdown", |
| 750 | + "metadata": {}, |
| 751 | + "source": [] |
754 | 752 | }
|
755 | 753 | ],
|
756 | 754 | "metadata": {
|
757 | 755 | "kernelspec": {
|
758 |
| - "display_name": "Python [default]", |
| 756 | + "display_name": "pytorch-macos-m1-gpu", |
759 | 757 | "language": "python",
|
760 | 758 | "name": "python3"
|
761 | 759 | },
|
|
769 | 767 | "name": "python",
|
770 | 768 | "nbconvert_exporter": "python",
|
771 | 769 | "pygments_lexer": "ipython3",
|
772 |
| - "version": "3.5.4" |
| 770 | + "version": "3.9.13" |
773 | 771 | },
|
774 | 772 | "notify_time": "30",
|
775 | 773 | "toc": {
|
|
813 | 811 | "_Feature"
|
814 | 812 | ],
|
815 | 813 | "window_display": false
|
| 814 | + }, |
| 815 | + "vscode": { |
| 816 | + "interpreter": { |
| 817 | + "hash": "032715a8d60757555a2623145b534a689e8b5634c5398e8bbec1014c4a8ede12" |
| 818 | + } |
816 | 819 | }
|
817 | 820 | },
|
818 | 821 | "nbformat": 4,
|
|
0 commit comments