Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,044 changes: 107 additions & 937 deletions chapter_03_linear-networks/0_linear-regression.ipynb

Large diffs are not rendered by default.

2,249 changes: 1,106 additions & 1,143 deletions chapter_03_linear-networks/1_linear-regression-scratch.ipynb

Large diffs are not rendered by default.

82 changes: 41 additions & 41 deletions chapter_03_linear-networks/2_linear-regression-concise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.append('..')\n",
"\n",
"import numpy as np\n",
"import mindspore\n",
"import mindspore.dataset as ds\n",
"import mindspore.ops as ops\n",
"from mindspore import Tensor\n",
"from d2l import mindspore as d2l\n",
"\n",
Expand All @@ -20,7 +22,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -47,31 +49,37 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[Tensor(shape=[10, 2], dtype=Float32, value=\n",
" [[ 1.73414111e-01, -1.24616718e+00],\n",
" [ 1.02213132e+00, -6.50639892e-01],\n",
" [ 1.30825520e+00, -1.22844315e+00],\n",
" ...\n",
" [-1.60054636e+00, 1.20353259e-01],\n",
" [ 7.61325806e-02, 7.83914328e-01],\n",
" [ 1.73925209e+00, -3.65485922e-02]]),\n",
" [[-0.22888152, 0.9795823 ],\n",
" [-0.6006927 , 2.0978146 ],\n",
" [-0.3551168 , 0.17106538],\n",
" [ 0.225816 , 0.89234185],\n",
" [ 0.7022703 , 0.37690485],\n",
" [ 0.09781982, 0.58985835],\n",
" [-1.6895691 , -0.71199685],\n",
" [-0.9362989 , 0.08117686],\n",
" [-1.1256968 , -0.26578853],\n",
" [-0.10324197, -0.25843388]]),\n",
" Tensor(shape=[10, 1], dtype=Float32, value=\n",
" [[ 8.76539135e+00],\n",
" [ 8.46442604e+00],\n",
" [ 1.09844027e+01],\n",
" ...\n",
" [ 6.07668221e-01],\n",
" [ 1.68395686e+00],\n",
" [ 7.80520296e+00]])]"
" [[ 0.39374894],\n",
" [-4.1332893 ],\n",
" [ 2.9085197 ],\n",
" [ 1.6274605 ],\n",
" [ 4.334508 ],\n",
" [ 2.3881655 ],\n",
" [ 3.2570887 ],\n",
" [ 2.0458496 ],\n",
" [ 2.8606327 ],\n",
" [ 4.8533044 ]])]"
]
},
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -82,7 +90,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -95,7 +103,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -105,7 +113,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -114,7 +122,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -123,16 +131,16 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"epoch 1, loss 0.000214\n",
"epoch 2, loss 0.000108\n",
"epoch 3, loss 0.000108\n"
"..epoch 1, loss 0.000389\n",
"epoch 2, loss 0.000107\n",
"epoch 3, loss 0.000107\n"
]
}
],
Expand All @@ -154,16 +162,15 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"w的估计误差: [Tensor(shape=[], dtype=Float32, value= -0.00017786)\n",
" Tensor(shape=[], dtype=Float32, value= -0.000656366)]\n",
"b的估计误差: [-0.00027466]\n"
"w的估计误差: [-3.00407410e-05 -2.89583206e-04]\n",
"b的估计误差: [0.00088167]\n"
]
}
],
Expand All @@ -173,20 +180,13 @@
"b = net[0].bias.data\n",
"print('b的估计误差:', true_b - b)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:mindspore2.0]",
"display_name": "Python 3.10",
"language": "python",
"name": "conda-env-mindspore2.0-py"
"name": "py310"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -198,7 +198,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
"version": "3.10.14"
}
},
"nbformat": 4,
Expand Down
Loading