Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Fitting the tree to employee data"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 16,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=None,\n",
- " max_features=None, max_leaf_nodes=None,\n",
- " min_impurity_decrease=0.0, min_impurity_split=None,\n",
- " min_samples_leaf=1, min_samples_split=2,\n",
- " min_weight_fraction_leaf=0.0, presort=False, random_state=42,\n",
- " splitter='best')"
- ]
- },
- "execution_count": 16,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Import the classification algorithm\n",
- "from sklearn.tree import DecisionTreeClassifier\n",
- "\n",
- "# Initialize it and call model by specifying the random_state parameter\n",
- "model = DecisionTreeClassifier(random_state=42)\n",
- "\n",
- "# Apply a decision tree model to fit features to the target\n",
- "model.fit(features_train, target_train)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Checking the accuracy of prediction"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 19,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "100.0\n",
- "97.22666666666666\n"
- ]
- }
- ],
- "source": [
- "# Check the accuracy score of the prediction for the training set\n",
- "print(model.score(features_train,target_train)*100)\n",
- "\n",
- "# Check the accuracy score of the prediction for the test set\n",
- "print(model.score(features_test, target_test)*100)"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.7.3"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement