|
16 | 16 | { |
17 | 17 | "cell_type": "code", |
18 | 18 | "execution_count": 1, |
19 | | - "metadata": {}, |
| 19 | + "metadata": { |
| 20 | + "collapsed": true |
| 21 | + }, |
20 | 22 | "outputs": [], |
21 | 23 | "source": [ |
22 | 24 | "import numpy as np\n", |
|
39 | 41 | "To keep things simple we will create a simple multilayer perceptron with only one hidden layer with size 5000 (half the size of the input) and see how it goes." |
40 | 42 | ] |
41 | 43 | }, |
| 44 | + { |
| 45 | + "cell_type": "code", |
| 46 | + "execution_count": null, |
| 47 | + "metadata": { |
| 48 | + "collapsed": true |
| 49 | + }, |
| 50 | + "outputs": [], |
| 51 | + "source": [ |
| 52 | + "# Load the dataset\n", |
| 53 | + "newsgroups = np.load('./resources/newsgroup.npz')\n", |
| 54 | + "\n", |
| 55 | + "# Define the model\n", |
| 56 | + "model = MLPClassifier(\n", |
| 57 | + " activation='relu', # Rectifier Linear Unit activation\n", |
| 58 | + " hidden_layer_sizes=(5000,), # 1 hidden layer of size 5000\n", |
| 59 | + " max_iter=5, # Each epochs takes a lot of time so we keep it to 5\n", |
| 60 | + " batch_size=100, # The batch size is set to 100 elements\n", |
| 61 | + " solver='adam') # We use the adam solver\n", |
| 62 | + "\n", |
| 63 | + "model.fit(newsgroups['train_data'],\n", |
| 64 | + " newsgroups['train_target'])" |
| 65 | + ] |
| 66 | + }, |
42 | 67 | { |
43 | 68 | "cell_type": "code", |
44 | 69 | "execution_count": 2, |
|
78 | 103 | } |
79 | 104 | ], |
80 | 105 | "source": [ |
81 | | - "# Load the dataset\n", |
82 | | - "newsgroups = np.load('./resources/newsgroup.npz')\n", |
83 | | - "\n", |
84 | | - "# Define the model\n", |
85 | | - "model = MLPClassifier(\n", |
86 | | - " activation='relu', # Rectifier Linear Unit activation\n", |
87 | | - " hidden_layer_sizes=(5000,), # 1 hidden layer of size 5000\n", |
88 | | - " max_iter=5, # Each epochs takes a lot of time so we keep it to 5\n", |
89 | | - " batch_size=100, # The batch size is set to 100 elements\n", |
90 | | - " solver='adam') # We use the adam solver\n", |
91 | | - "\n", |
92 | | - "model.fit(newsgroups['train_data'],\n", |
93 | | - " newsgroups['train_target'])\n", |
94 | | - "\n", |
95 | 106 | "accuracy = accuracy_score(\n", |
96 | | - " newsgroups['test_target'],\n", |
97 | | - " model.predict(newsgroups['test_data']))\n", |
| 107 | + " newsgroups['test_target'],\n", |
| 108 | + " model.predict(newsgroups['test_data']))\n", |
98 | 109 | "\n", |
99 | 110 | "print(\"Accuracy: %.2f\" % accuracy)\n", |
100 | 111 | "\n", |
101 | 112 | "print(classification_report(\n", |
102 | | - " newsgroups['test_target'],\n", |
103 | | - " model.predict(newsgroups['test_data'])))" |
| 113 | + " newsgroups['test_target'],\n", |
| 114 | + " model.predict(newsgroups['test_data'])))" |
104 | 115 | ] |
105 | 116 | } |
106 | 117 | ], |
107 | 118 | "metadata": { |
108 | 119 | "kernelspec": { |
109 | | - "display_name": "Python [conda env:tensorflow-tutorial]", |
| 120 | + "display_name": "Python [conda env:env_edm]", |
110 | 121 | "language": "python", |
111 | | - "name": "conda-env-tensorflow-tutorial-py" |
| 122 | + "name": "conda-env-env_edm-py" |
112 | 123 | }, |
113 | 124 | "language_info": { |
114 | 125 | "codemirror_mode": { |
|
0 commit comments