{"id":53,"date":"2023-10-16T14:28:05","date_gmt":"2023-10-16T14:28:05","guid":{"rendered":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/?p=53"},"modified":"2023-10-16T14:28:41","modified_gmt":"2023-10-16T14:28:41","slug":"2023-09-26-%e8%aa%b2%e7%a8%8b%e8%a3%9c%e5%85%85%e8%b3%87%e6%96%99-week-03-2-2","status":"publish","type":"post","link":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/?p=53","title":{"rendered":"2023-10-17 \u8ab2\u7a0b\u88dc\u5145\u8cc7\u6599 Week 06"},"content":{"rendered":"\n<p>Demo Project to show Gradient Descent<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>PyCharm code, \u8cc7\u6599\u4f86\u6e90: <a href=\"http:\/\/speech.ee.ntu.edu.tw\/~tlkagk\/courses\/ML_2017\/demo\/GradientDescentDemo.ipynb\">LINK<\/a><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>import tkinter\nimport matplotlib\nimport matplotlib.pyplot as plt\n\nmatplotlib.use('tkagg')\n# %matplotlib inline\nimport random as random\nimport numpy as np\nimport csv\n\nx_data = &#91;338., 333., 328., 207., 226., 25., 179., 60., 208., 606.]\ny_data = &#91;640., 633., 619., 393., 428., 27., 193., 66., 226., 1591.]\n\nx = np.arange(-200, -100, 1)  # bias\ny = np.arange(-5, 5, 0.1)  # weight\nZ = np.zeros((len(x), len(y)))\nX, Y = np.meshgrid(x, y)\nfor i in range(len(x)):\n    for j in range(len(y)):\n        b = x&#91;i]\n        w = y&#91;j]\n        Z&#91;j]&#91;i] = 0\n        for n in range(len(x_data)):\n            Z&#91;j]&#91;i] = Z&#91;j]&#91;i] + (y_data&#91;n] - b - w * x_data&#91;n]) ** 2\n        Z&#91;j]&#91;i] = Z&#91;j]&#91;i] \/ len(x_data)\n\n# ydata = b + w * xdata\nb = -120  # initial b\nw = -4  # initial w\nlr = 0.000001  # learning rate\niteration = 100000\n\nb_lr = 0.0\nw_lr = 0.0\n\n# Store initial values for plotting.\nb_history = &#91;b]\nw_history = &#91;w]\n\n# Iterations\nfor i in range(iteration):\n\n    b_grad = 0.0\n    w_grad = 0.0\n    for n in range(len(x_data)):\n        b_grad = b_grad - 2.0 * (y_data&#91;n] - b - w * x_data&#91;n]) * 1.0\n        w_grad = w_grad - 2.0 * (y_data&#91;n] - b - w * x_data&#91;n]) * x_data&#91;n]\n\n    b_lr = b_lr + b_grad ** 2\n    w_lr = w_lr + w_grad ** 2\n\n    # Update parameters.\n    b = b - lr \/ np.sqrt(b_lr) * b_grad\n    w = w - lr \/ np.sqrt(w_lr) * w_grad\n\n    # Store parameters for plotting\n    b_history.append(b)\n    w_history.append(w)\n\n# plot the figure\nplt.contourf(x, y, Z, 50, alpha=0.5, cmap=plt.get_cmap('jet'))\nplt.plot(&#91;-188.4], &#91;2.67], 'x', ms=12, markeredgewidth=3, color='orange')\nplt.plot(b_history, w_history, 'o-', ms=3, lw=1.5, color='black')\nplt.xlim(-200, -100)\nplt.ylim(-5, 5)\nplt.xlabel(r'$b$', fontsize=16)\nplt.ylabel(r'$w$', fontsize=16)\nplt.show()<\/code><\/pre>\n\n\n\n<p><strong>DEMO 1 task<\/strong><br>\u7528 python \u8a08\u7b97\u67d0\u4e00\u500b\u65b0\u805e\u7db2\u9801\u51fa\u73fe Taiwan \u95dc\u9375\u5b57\u7684\u6b21\u6578<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>with open('demo_1003.html') as f:\n    lines = f.read()\n\nwords = lines.split()\n#print(words&#91;0])\n\nsearch_word = \"Taiwan\"\ncount = words.count(search_word)\nprint(\"\u641c\u5c0b\u7d50\u679c(\", search_word, \")\", count)<\/code><\/pre>\n\n\n\n<p><strong>DEMO 2 task<br><\/strong>1. \u767b\u5165<br>2. \u4fee\u6539\u66b1\u7a31<br>3. \u4fee\u6539\u5bc6\u78bc<br>4. \u4fee\u6539\u5927\u982d\u8cbc<br>\u53ef\u4ee5\u4f7f\u7528 <strong>Postman<\/strong>, \u4e0d\u904e\u6700\u597d\u662f\u5690\u8a66\u4f7f\u7528 python \u4f86\u9032\u884c.<\/p>\n\n\n\n<p><strong>\u4eca\u5929 API \u7d50\u679c URL<\/strong><br><a href=\"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/API\/\">https:\/\/www.cutexyz.com\/edu\/mlearning2309\/API\/<\/a><\/p>\n\n\n\n<p>\u5982\u679c\u8981\u770b\u900f\u904e\u5b78\u865f\u8207\u4e2d\u6587\u59d3\u540d\u767b\u5165\u7684\u7d50\u679c:<br><a href=\"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/API\/index2.php\">https:\/\/www.cutexyz.com\/edu\/mlearning2309\/API\/index2.php<\/a><\/p>\n\n\n\n<p>\u4eca\u65e5\u6703\u4f7f\u7528\u7684 API List<\/p>\n\n\n\n<p><strong>API 1<\/strong>: login<br>Protocol: HTTPS POST<br>API URL:  https:\/\/www.cutexyz.com\/edu\/mlearning2309\/API\/api_login.php<br><strong>Parameters<\/strong>:<br>1. student_uid: \u5b78\u865f<br>2. pwd: \u5bc6\u78bc, \u9810\u8a2d\u70ba cute301, \u6c92\u6709\u5fd8\u8a18\u5bc6\u78bc\u529f\u80fd, \u5982\u679c\u6709\u4eba\u5fd8\u8a18, \u8acb\u5148\u8207\u8001\u5e2b\u901a\u77e5<br><strong>Return Data ( JSON FORMAT )<\/strong>:<br>1. result: \u7d50\u679c, OK \u4ee3\u8868\u6c92\u554f\u984c, ERROR \u4ee3\u8868\u932f\u8aa4\u767c\u751f<br>2. data: \u5167\u542b\u552f\u4e00\u8cc7\u6599 token: \u7528\u65bc\u767b\u5165\u4e4b\u5f8c\u547c\u53eb\u5225\u7684 API \u642d\u914d\u4f7f\u7528<br>3. msg: \u5982\u679c\u6709\u7279\u6b8a\u88dd\u6846\u9700\u8981\u8a73\u8ff0\u554f\u984c\u6642\u5c31\u6703\u5728\u9019\u908a\u986f\u793a<\/p>\n\n\n\n<p>\u5982\u679c\u8981\u770b\u900f\u904e\u5b78\u865f\u8207\u4e2d\u6587\u59d3\u540d\u767b\u5165\u7684\u7d50\u679c:<br><a href=\"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/API\/index2.php\">https:\/\/www.cutexyz.com\/edu\/gmlearning2309\/API\/index2.php<\/a><\/p>\n\n\n\n<p>API List<\/p>\n\n\n\n<p><strong>API <\/strong>2: updateprofile<br>Protocol: HTTPS POST<br>API URL:  https:\/\/www.cutexyz.com\/edu\/mlearning2309\/API\/api_updateprofile.php<br><strong>Parameters<\/strong>:<br>1. student_uid: \u5b78\u865f<br>2. token: \u4f60\u5728\u767b\u5165\u5f8c, \u7531\u7cfb\u7d71\u767c\u7d66\u4f60\u7684\u52d5\u614b\u5bc6\u78bc, \u6709\u6548\u671f\u5167\u9019\u500b\u5bc6\u78bc\u4e0d\u6703\u8b8a\u52d5<br>3. mode: \u4f60\u60f3\u4f7f\u7528\u7684\u529f\u80fd; 1: \u4fee\u6539\u66b1\u7a31, 2: \u4fee\u6539\u5bc6\u78bc, 3: \u4e0a\u50b3\u5927\u982d\u8cbc<br>4.value1:\u5e36\u5165\u7684\u53c3\u6578, mode 1 \u8acb\u5e36\u5165\u66b1\u7a31, mode 2 \u8f15\u5e36\u5165\u65b0\u7684\u5bc6\u78bc, mode 3 \u8acb\u5e36\u5165\u6a94\u6848( jpg \u9650\u5b9a)<br><strong>Return Data ( JSON FORMAT )<\/strong>:<br>1. result: \u7d50\u679c, OK \u4ee3\u8868\u6c92\u554f\u984c, ERROR \u4ee3\u8868\u932f\u8aa4\u767c\u751f<br>2. data: null \u672c API \u4e0d\u6703\u4f7f\u7528<br>3. msg: \u5982\u679c\u6709\u7279\u6b8a\u88dd\u6846\u9700\u8981\u8a73\u8ff0\u554f\u984c\u6642\u5c31\u6703\u5728\u9019\u908a\u986f\u793a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Demo Project to show Gradient Descent DEMO 1 task\u7528 python \u8a08\u7b97\u67d0\u4e00\u500b\u65b0\u805e\u7db2\u9801\u51fa\u73fe Taiwan \u95dc\u9375\u5b57\u7684\u6b21\u6578 DEMO 2 task1. \u767b\u51652. \u4fee\u6539\u66b1\u7a313. \u4fee\u6539\u5bc6\u78bc4. \u4fee\u6539\u5927\u982d\u8cbc\u53ef\u4ee5\u4f7f\u7528 Postman, \u4e0d\u904e\u6700\u597d\u662f\u5690\u8a66\u4f7f\u7528 python \u4f86\u9032\u884c. \u4eca\u5929 API \u7d50\u679c URLhttps:\/\/www.cutexyz.com\/edu\/mlearning2309\/API\/ \u5982\u679c\u8981\u770b\u900f\u904e\u5b78\u865f\u8207\u4e2d\u6587\u59d3\u540d\u767b\u5165\u7684\u7d50\u679c:https:\/\/www.cutexyz.com\/edu\/mlearning2309\/API\/index2.php \u4eca\u65e5\u6703\u4f7f\u7528\u7684 API List API 1: loginProtocol: HTTPS POSTAPI URL: https:\/\/www.cutexyz.com\/edu\/mlearning2309\/API\/api_login.phpParameters:1. student_uid: \u5b78\u865f2. pwd: \u5bc6\u78bc, \u9810\u8a2d\u70ba cute301, \u6c92\u6709\u5fd8\u8a18\u5bc6\u78bc\u529f\u80fd, \u5982\u679c\u6709\u4eba\u5fd8\u8a18, \u8acb\u5148\u8207\u8001\u5e2b\u901a\u77e5Return Data ( JSON FORMAT ):1. result: \u7d50\u679c, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[4],"tags":[],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=53"}],"version-history":[{"count":2,"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=\/wp\/v2\/posts\/53\/revisions"}],"predecessor-version":[{"id":55,"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=\/wp\/v2\/posts\/53\/revisions\/55"}],"wp:attachment":[{"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}