{"id":80,"date":"2023-12-12T06:05:24","date_gmt":"2023-12-12T06:05:24","guid":{"rendered":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/?p=80"},"modified":"2023-12-12T06:51:23","modified_gmt":"2023-12-12T06:51:23","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-2-3","status":"publish","type":"post","link":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/?p=80","title":{"rendered":"2023-12-12 \u8ab2\u7a0b\u88dc\u5145\u8cc7\u6599 Week 14"},"content":{"rendered":"\n<p>Demo Project<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u624b\u5beb\u8fa8\u8b58\u7cfb\u7d71 by MNIST<\/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>from keras.datasets import mnist\n\n(train_images, train_labels), (test_images, test_labels) = mnist.load_data()\nprint(\"train_images original shape: \", train_images.shape)\nprint(\"train_labels original shape: \", train_labels.shape)\n\nfrom keras import models\nfrom keras import layers\n\nnetwork = models.Sequential()\n\n# Hidden layer\nnetwork.add(layers.Dense(512, activation='relu', input_shape=(28 * 28,)))\n\n# Output layer\nnetwork.add(layers.Dense(10, activation='softmax'))\n\nnetwork.compile(optimizer='rmsprop',                # \u512a\u5316\u5668\u9078\u64c7\n                loss='categorical_crossentropy',    # \u640d\u5931\u51fd\u6578\n                metrics=&#91;'accuracy'])               # \u7528\u6e96\u78ba\u5ea6\u505a\u8a55\u91cf\n\nfix_train_images = train_images.reshape((60000, 28 * 28)).astype('float32') \/ 255\nfix_test_images = test_images.reshape((10000, 28 * 28)).astype('float32') \/ 255\n\nfrom keras.utils import to_categorical\n\nfix_train_labels = to_categorical(train_labels)\nfix_test_labels = to_categorical(test_labels)\n\nresult = network.fit(\n    fix_train_images,   # training data\n    fix_train_labels,   # \u6b63\u78ba\u7b54\u6848\n    epochs=12,          # \u4ee3\u8868\u8981\u8dd1\u5e7e\u6b21\n    batch_size=128,     # \u6bcf\u6b21\u8a13\u7df4\u4f7f\u7528\u5e7e\u7b46\u8cc7\u6599, \u6240\u4ee5 60000 \/128 \u7d04\u7b49\u65bc 469 \u7d44\n    validation_data=(fix_test_images, fix_test_labels))\n\ntest_loss, test_acc = network.evaluate(fix_test_images, fix_test_labels)\nprint('test_loss:', test_loss)\nprint('test_acc:', test_acc)\n===== \u4ee5\u4e0b\u662f\u5ee2 code ====\n\n# After training the model, it is time to use it to do predictions on testing data.\ny_pred = classifier.predict(xtest)\n\nplt.title('Classifier (Test set)')\nplt.xlabel('Age')\nplt.ylabel('Estimated Salary')\nplt.legend()\nplt.show()\n<\/code><\/pre>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Demo Project<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","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":[5],"tags":[],"class_list":["post-80","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=\/wp\/v2\/posts\/80","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=80"}],"version-history":[{"count":3,"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=\/wp\/v2\/posts\/80\/revisions"}],"predecessor-version":[{"id":83,"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=\/wp\/v2\/posts\/80\/revisions\/83"}],"wp:attachment":[{"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cutexyz.com\/edu\/mlearning2309\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}