diff --git a/experiment/random forest/RandomForest.ipynb b/experiment/random forest/RandomForest.ipynb index 35b0dbbf2afcaa327dd0acef0440916323b11476..bd022f3e64e0f88cf1fbb3f2712df3b440827a1e 100644 --- a/experiment/random forest/RandomForest.ipynb +++ b/experiment/random forest/RandomForest.ipynb @@ -162,7 +162,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -171,7 +171,7 @@ "RandomForestClassifier(max_depth=5, n_estimators=20, random_state=0)" ] }, - "execution_count": 7, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -208,7 +208,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -217,7 +217,7 @@ "(0.9974059662775616, 0.9754756871035941, 0.9863189397178281, None)" ] }, - "execution_count": 14, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -232,7 +232,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -241,7 +241,7 @@ "0.9872990672752531" ] }, - "execution_count": 15, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -252,6 +252,60 @@ "accuracy_score(y_test ,clf_y_pred)" ] }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "clf_vector = list()\n", + "\n", + "for m_depth_iter in range(1, 21):\n", + " clf_item = RandomForestClassifier(n_estimators=20, max_depth=m_depth_iter, random_state=0, criterion='entropy')\n", + " clf_item.fit(X_train, y_train)\n", + " clf_vector.append(clf_item)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "depth: 1 0.9866186309830159 0.810570824524313 0.8899721448467967\n", + "depth: 2 0.9861751152073732 0.904862579281184 0.9437706725468578\n", + "depth: 3 0.9902998236331569 0.9496828752642706 0.9695661558385495\n", + "depth: 4 0.9969365426695842 0.9632135306553912 0.9797849462365591\n", + "depth: 5 0.9978326831382748 0.9733615221987315 0.9854452054794521\n", + "depth: 6 0.9991379310344828 0.9801268498942918 0.9895410885805763\n", + "depth: 7 0.9978687127024722 0.9898520084566597 0.993844194438548\n", + "depth: 8 0.9987261146496815 0.9945031712473573 0.9966101694915255\n", + "depth: 9 0.9978768577494692 0.9936575052854123 0.9957627118644068\n", + "depth: 10 0.9983050847457627 0.9961945031712474 0.9972486772486773\n", + "depth: 11 0.9978840457046128 0.9970401691331924 0.9974619289340102\n", + "depth: 12 0.9987293519695044 0.9970401691331924 0.9978840457046128\n", + "depth: 13 0.9974630021141649 0.9974630021141649 0.9974630021141649\n", + "depth: 14 0.9978867286559594 0.99830866807611 0.9980976537729866\n", + "depth: 15 0.9978813559322034 0.9957716701902748 0.996825396825397\n", + "depth: 16 0.9974619289340102 0.9970401691331924 0.9972510044406852\n", + "depth: 17 0.9970376639864579 0.9961945031712474 0.9966159052453468\n", + "depth: 18 0.996196111580727 0.9966173361522199 0.9964066793489749\n", + "depth: 19 0.9966159052453468 0.9961945031712474 0.9964051596532035\n", + "depth: 20 0.9970376639864579 0.9961945031712474 0.9966159052453468\n" + ] + } + ], + "source": [ + "for clf_item in clf_vector:\n", + " clf_y_pred = clf_item.predict(X_test)\n", + "\n", + " p, r, f, _ = precision_recall_fscore_support(y_test, clf_y_pred, average=\"binary\")\n", + " print(f\"depth: {clf_item.max_depth} {p} {r} {f}\")" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/experiment/random forest/rnf.png b/experiment/random forest/rnf.png new file mode 100644 index 0000000000000000000000000000000000000000..d1b25338349854115a04c82ea24293df5bad7ae1 Binary files /dev/null and b/experiment/random forest/rnf.png differ