{"id":12443,"date":"2021-05-28T20:33:10","date_gmt":"2021-05-29T01:33:10","guid":{"rendered":"httpss:\/\/www.powenko.com\/wordpress\/docs\/python\/tensorflow\/%e6%a8%a1%e5%9e%8b-mlp%e5%88%86%e9%a1%9e%e6%b3%95-2\/"},"modified":"2021-05-28T20:35:40","modified_gmt":"2021-05-29T01:35:40","slug":"%e6%a8%a1%e5%9e%8b-mlp%e5%88%86%e9%a1%9e%e6%b3%95-2","status":"publish","type":"docs","link":"https:\/\/www.powenko.com\/wordpress\/?docs=python\/tensorflow\/%e6%a8%a1%e5%9e%8b-mlp%e5%88%86%e9%a1%9e%e6%b3%95-2","title":{"rendered":"\u6a21\u578b-MLP\u5206\u985e\u6cd5One Hot Encoding"},"content":{"rendered":"<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nt=2\r\ncategory=2\r\ndim=x_train.shape&#x5B;1]\r\n\r\n\r\ny_train2=tf.keras.utils.to_categorical(y_train, num_classes=(category))\r\ny_test2=tf.keras.utils.to_categorical(y_test, num_classes=(category))\r\n# \u5efa\u7acb\u6a21\u578b\r\nmodel = tf.keras.models.Sequential()\r\nmodel.add(tf.keras.layers.Dense(units=200,\r\n    activation=tf.nn.relu,\r\n    input_dim=dim))\r\nmodel.add(tf.keras.layers.Dense(units=40*t,\r\n    activation=tf.nn.relu ))\r\nmodel.add(tf.keras.layers.Dense(units=80*t,\r\n    activation=tf.nn.relu ))\r\nmodel.add(tf.keras.layers.Dense(units=100*t,\r\n    activation=tf.nn.relu ))\r\nmodel.add(tf.keras.layers.Dense(units=category,\r\n    activation=tf.nn.softmax ))\r\nmodel.compile(optimizer='adam',\r\n    loss=tf.keras.losses.categorical_crossentropy,\r\n    metrics=&#x5B;'accuracy'])\r\nmodel.fit(x_train, y_train2,\r\n          epochs=300*t,\r\n          batch_size=64)\r\n\r\n#\u6e2c\u8a66\r\nmodel.summary()\r\n\r\nscore = model.evaluate(x_test, y_test2, batch_size=64)\r\nprint(&quot;score:&quot;,score)\r\n\r\npredict2 = model.predict_classes(x_test)\r\nprint(&quot;predict_classes:&quot;,predict2)\r\nprint(&quot;y_test&quot;,y_test&#x5B;:])\r\n<\/pre>\n","protected":false},"featured_media":0,"parent":12431,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-12443","docs","type-docs","status-publish","hentry"],"comment_count":0,"_links":{"self":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12443"}],"collection":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12443"}],"version-history":[{"count":3,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12443\/revisions"}],"predecessor-version":[{"id":12448,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12443\/revisions\/12448"}],"up":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12431"}],"next":[{"title":"\u6a21\u578b-CNN\u5206\u985e","link":"https:\/\/www.powenko.com\/wordpress\/?docs=python\/tensorflow\/%e6%a8%a1%e5%9e%8b-cnn%e5%88%86%e9%a1%9e","href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12545"}],"prev":[{"title":"\u6a21\u578b","link":"https:\/\/www.powenko.com\/wordpress\/?docs=python\/tensorflow\/%e6%a8%a1%e5%9e%8b","href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12440"}],"wp:attachment":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12443"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fdoc_tag&post=12443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}