Skip to content

Commit

Permalink
defined the helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vmirly committed Nov 15, 2024
1 parent d345659 commit 52fa9d8
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion decision_tree/decision_tree.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,26 @@
" \"right\": self._build_tree(X[right_indices], y[right_indices], depth + 1)\n",
" }\n",
" \n",
" \n"
" def _find_best_split(self, X, y, n_features):\n",
" best_feature = None\n",
" best_threshold = None\n",
" best_impurity = float('inf')\n",
"\n",
" for feature_index in range(n_features):\n",
" thresholds = np.unique(X[:, feature_index])\n",
" for threshold in thresholds:\n",
" impurity = gini_split(X, y, feature_index, threshold)\n",
" if impurity < best_impurity:\n",
" best_feature = feature_index\n",
" best_threshold = threshold\n",
" best_impurity = impurity\n",
"\n",
" return best_feature, best_threshold\n",
" \n",
" def _most_common_label(self, y):\n",
" return Counter(y).most_common(1)[0][0]\n",
" \n",
" \n"
]
}
],
Expand Down

0 comments on commit 52fa9d8

Please sign in to comment.