Browse Source

Improve README.md

fetches/feikei/master
Shuhui Bu 6 years ago
parent
commit
47b6df8a51
3 changed files with 142 additions and 172 deletions
  1. +51
    -51
      2_pytorch/1_NN/linear-regression-gradient-descend.ipynb
  2. +89
    -119
      2_pytorch/PyTorch_quick_intro.ipynb
  3. +2
    -2
      README.md

+ 51
- 51
2_pytorch/1_NN/linear-regression-gradient-descend.ipynb
File diff suppressed because it is too large
View File


+ 89
- 119
2_pytorch/PyTorch_quick_intro.ipynb View File

@@ -41,14 +41,11 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"\n",
"1.00000e-07 *\n",
" 0.0000 0.0000 5.3571\n",
" 0.0000 0.0000 0.0000\n",
" 0.0000 0.0000 0.0000\n",
" 0.0000 5.4822 0.0000\n",
" 5.4823 0.0000 5.4823\n",
"[torch.FloatTensor of size 5x3]"
"tensor([[5.0275e-38, 0.0000e+00, 5.7453e-44],\n",
" [0.0000e+00, nan, 4.5886e-41],\n",
" [1.3733e-14, 6.4076e+07, 2.0706e-19],\n",
" [7.3909e+22, 2.4176e-12, 1.1625e+33],\n",
" [8.9605e-01, 1.1632e+33, 5.6003e-02]])"
] ]
}, },
"execution_count": 2, "execution_count": 2,
@@ -70,13 +67,11 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"\n",
" 0.3673 0.2522 0.3553\n",
" 0.0070 0.7138 0.0463\n",
" 0.6198 0.6019 0.3752\n",
" 0.4755 0.3675 0.3032\n",
" 0.5824 0.5104 0.5759\n",
"[torch.FloatTensor of size 5x3]"
"tensor([[0.7334, 0.3729, 0.2952],\n",
" [0.0380, 0.1581, 0.2454],\n",
" [0.6000, 0.1633, 0.7892],\n",
" [0.1951, 0.5389, 0.3149],\n",
" [0.6041, 0.8072, 0.5542]])"
] ]
}, },
"execution_count": 3, "execution_count": 3,
@@ -133,13 +128,11 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"\n",
" 0.4063 0.7378 1.2411\n",
" 0.0687 0.7725 0.0634\n",
" 1.1016 1.4291 0.7324\n",
" 0.7604 1.2880 0.4597\n",
" 0.6020 1.0124 1.0185\n",
"[torch.FloatTensor of size 5x3]"
"tensor([[1.7112, 1.2969, 0.3289],\n",
" [0.7841, 1.0128, 0.7596],\n",
" [1.1364, 1.1541, 0.8970],\n",
" [0.8831, 0.7063, 0.3158],\n",
" [1.5160, 1.3610, 0.8437]])"
] ]
}, },
"execution_count": 5, "execution_count": 5,
@@ -182,22 +175,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"\n",
" 0.4063 0.7378 1.2411\n",
" 0.0687 0.7725 0.0634\n",
" 1.1016 1.4291 0.7324\n",
" 0.7604 1.2880 0.4597\n",
" 0.6020 1.0124 1.0185\n",
"[torch.FloatTensor of size 5x3]"
"tensor([[1.7112, 1.2969, 0.3289],\n",
" [0.7841, 1.0128, 0.7596],\n",
" [1.1364, 1.1541, 0.8970],\n",
" [0.8831, 0.7063, 0.3158],\n",
" [1.5160, 1.3610, 0.8437]])"
] ]
}, },
"execution_count": 7,
"execution_count": 6,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -211,7 +202,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -219,32 +210,23 @@
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"最初y\n", "最初y\n",
"\n",
" 0.0390 0.4856 0.8858\n",
" 0.0617 0.0587 0.0171\n",
" 0.4818 0.8272 0.3572\n",
" 0.2849 0.9205 0.1565\n",
" 0.0196 0.5020 0.4426\n",
"[torch.FloatTensor of size 5x3]\n",
"\n",
"tensor([[0.9778, 0.9240, 0.0337],\n",
" [0.7461, 0.8548, 0.5141],\n",
" [0.5364, 0.9908, 0.1078],\n",
" [0.6880, 0.1675, 0.0010],\n",
" [0.9120, 0.5539, 0.2896]])\n",
"第一种加法,y的结果\n", "第一种加法,y的结果\n",
"\n",
" 0.0390 0.4856 0.8858\n",
" 0.0617 0.0587 0.0171\n",
" 0.4818 0.8272 0.3572\n",
" 0.2849 0.9205 0.1565\n",
" 0.0196 0.5020 0.4426\n",
"[torch.FloatTensor of size 5x3]\n",
"\n",
"tensor([[0.9778, 0.9240, 0.0337],\n",
" [0.7461, 0.8548, 0.5141],\n",
" [0.5364, 0.9908, 0.1078],\n",
" [0.6880, 0.1675, 0.0010],\n",
" [0.9120, 0.5539, 0.2896]])\n",
"第二种加法,y的结果\n", "第二种加法,y的结果\n",
"\n",
" 0.4063 0.7378 1.2411\n",
" 0.0687 0.7725 0.0634\n",
" 1.1016 1.4291 0.7324\n",
" 0.7604 1.2880 0.4597\n",
" 0.6020 1.0124 1.0185\n",
"[torch.FloatTensor of size 5x3]\n",
"\n"
"tensor([[1.7112, 1.2969, 0.3289],\n",
" [0.7841, 1.0128, 0.7596],\n",
" [1.1364, 1.1541, 0.8970],\n",
" [0.8831, 0.7063, 0.3158],\n",
" [1.5160, 1.3610, 0.8437]])\n"
] ]
} }
], ],
@@ -306,22 +288,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10,
"execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"\n",
" 1\n",
" 1\n",
" 1\n",
" 1\n",
" 1\n",
"[torch.FloatTensor of size 5]"
"tensor([1., 1., 1., 1., 1.])"
] ]
}, },
"execution_count": 10,
"execution_count": 8,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -333,7 +309,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11,
"execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -342,7 +318,7 @@
"array([1., 1., 1., 1., 1.], dtype=float32)" "array([1., 1., 1., 1., 1.], dtype=float32)"
] ]
}, },
"execution_count": 11,
"execution_count": 9,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -354,7 +330,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12,
"execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -362,14 +338,7 @@
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"[1. 1. 1. 1. 1.]\n", "[1. 1. 1. 1. 1.]\n",
"\n",
" 1\n",
" 1\n",
" 1\n",
" 1\n",
" 1\n",
"[torch.DoubleTensor of size 5]\n",
"\n"
"tensor([1., 1., 1., 1., 1.], dtype=torch.float64)\n"
] ]
} }
], ],
@@ -424,15 +393,28 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor([[2.4446, 1.6699, 0.6242],\n",
" [0.8222, 1.1709, 1.0050],\n",
" [1.7364, 1.3174, 1.6862],\n",
" [1.0782, 1.2452, 0.6307],\n",
" [2.1201, 2.1682, 1.3979]], device='cuda:0')\n"
]
}
],
"source": [ "source": [
"# 在不支持CUDA的机器下,下一步不会运行\n", "# 在不支持CUDA的机器下,下一步不会运行\n",
"if t.cuda.is_available():\n", "if t.cuda.is_available():\n",
" x = x.cuda()\n", " x = x.cuda()\n",
" y = y.cuda()\n", " y = y.cuda()\n",
" x + y"
" x + y\n",
"print(x+y)"
] ]
}, },
{ {
@@ -459,7 +441,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -468,7 +450,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16,
"execution_count": 19,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
@@ -476,13 +458,11 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"Variable containing:\n",
" 1 1\n",
" 1 1\n",
"[torch.FloatTensor of size 2x2]"
"tensor([[1., 1.],\n",
" [1., 1.]], requires_grad=True)"
] ]
}, },
"execution_count": 16,
"execution_count": 19,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -495,7 +475,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17,
"execution_count": 20,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
@@ -503,12 +483,10 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"Variable containing:\n",
" 4\n",
"[torch.FloatTensor of size 1]"
"tensor(4., grad_fn=<SumBackward0>)"
] ]
}, },
"execution_count": 17,
"execution_count": 20,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -520,16 +498,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18,
"execution_count": 21,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"<SumBackward0 at 0x7fc14824b860>"
"<SumBackward0 at 0x7fe8cf72c908>"
] ]
}, },
"execution_count": 18,
"execution_count": 21,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -540,7 +518,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19,
"execution_count": 22,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -549,19 +527,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20,
"execution_count": 23,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"Variable containing:\n",
" 1 1\n",
" 1 1\n",
"[torch.FloatTensor of size 2x2]"
"tensor([[1., 1.],\n",
" [1., 1.]])"
] ]
}, },
"execution_count": 20,
"execution_count": 23,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -581,19 +557,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21,
"execution_count": 24,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"Variable containing:\n",
" 2 2\n",
" 2 2\n",
"[torch.FloatTensor of size 2x2]"
"tensor([[2., 2.],\n",
" [2., 2.]])"
] ]
}, },
"execution_count": 21,
"execution_count": 24,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -631,19 +605,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23,
"execution_count": 25,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"\n",
" 0 0\n",
" 0 0\n",
"[torch.FloatTensor of size 2x2]"
"tensor([[0., 0.],\n",
" [0., 0.]])"
] ]
}, },
"execution_count": 23,
"execution_count": 25,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -655,19 +627,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24,
"execution_count": 26,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"Variable containing:\n",
" 1 1\n",
" 1 1\n",
"[torch.FloatTensor of size 2x2]"
"tensor([[1., 1.],\n",
" [1., 1.]])"
] ]
}, },
"execution_count": 24,
"execution_count": 26,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }


+ 2
- 2
README.md View File

@@ -1,8 +1,8 @@
# Python与机器学习 # Python与机器学习


本教程包含了一些使用Python来学习机器学习的notebook,通过本教程能够引导学习Python的基础知识、机器学习的理论知识与实际编程,并学习如何解决实际问题。
本教程包含了一些使用Python来学习机器学习的notebook,通过本教程的引导来快速得学习Python、Python的常用库、机器学习的理论知识与实际编程,并学习如何解决实际问题。


由于**本课程需要大量的编程练习才能取得比较好的学习效果**,因此需要认真把作业和报告完成。作业的地址是:https://gitee.com/machinelearning2018/pr_homework 请按照里面的说明进行操作,并提交作业
由于**本课程需要大量的编程练习才能取得比较好的学习效果**,因此需要认真把作业和报告完成,写作业的过程可以查阅网上的资料,但是不能直接照抄,需要自己独立思考并独立写出代码




## 内容 ## 内容


Loading…
Cancel
Save