Skip to content

Commit

Permalink
predict function
Browse files Browse the repository at this point in the history
  • Loading branch information
vmirly committed Nov 16, 2024
1 parent 52fa9d8 commit e402b4a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion decision_tree/decision_tree.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,18 @@
" def _most_common_label(self, y):\n",
" return Counter(y).most_common(1)[0][0]\n",
" \n",
" \n"
" def predict(self, X):\n",
" predictions = [self._predict(inputs) for inputs in X]\n",
" return np.array(predictions)\n",
" \n",
" def _predict_sample(self, x, tree):\n",
" if tree['leaf']:\n",
" return tree['value']\n",
" feature_value = x[tree['feature_index']]\n",
" if feature_value < tree['threshold']:\n",
" return self._predict_sample(x, tree['left'])\n",
" else:\n",
" return self._predict_sample(x, tree['right'])\n"
]
}
],
Expand Down

0 comments on commit e402b4a

Please sign in to comment.