SHARE
TWEET

Untitled

a guest Oct 16th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.  "cells": [
  3.   {
  4.    "cell_type": "markdown",
  5.    "metadata": {},
  6.    "source": [
  7.     "### Fitting the tree to employee data"
  8.    ]
  9.   },
  10.   {
  11.    "cell_type": "code",
  12.    "execution_count": 16,
  13.    "metadata": {},
  14.    "outputs": [
  15.     {
  16.      "data": {
  17.       "text/plain": [
  18.        "DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=None,\n",
  19.        "            max_features=None, max_leaf_nodes=None,\n",
  20.        "            min_impurity_decrease=0.0, min_impurity_split=None,\n",
  21.        "            min_samples_leaf=1, min_samples_split=2,\n",
  22.        "            min_weight_fraction_leaf=0.0, presort=False, random_state=42,\n",
  23.        "            splitter='best')"
  24.       ]
  25.      },
  26.      "execution_count": 16,
  27.      "metadata": {},
  28.      "output_type": "execute_result"
  29.     }
  30.    ],
  31.    "source": [
  32.     "# Import the classification algorithm\n",
  33.     "from sklearn.tree import DecisionTreeClassifier\n",
  34.     "\n",
  35.     "# Initialize it and call model by specifying the random_state parameter\n",
  36.     "model = DecisionTreeClassifier(random_state=42)\n",
  37.     "\n",
  38.     "# Apply a decision tree model to fit features to the target\n",
  39.     "model.fit(features_train, target_train)"
  40.    ]
  41.   },
  42.   {
  43.    "cell_type": "markdown",
  44.    "metadata": {},
  45.    "source": [
  46.     "### Checking the accuracy of prediction"
  47.    ]
  48.   },
  49.   {
  50.    "cell_type": "code",
  51.    "execution_count": 19,
  52.    "metadata": {},
  53.    "outputs": [
  54.     {
  55.      "name": "stdout",
  56.      "output_type": "stream",
  57.      "text": [
  58.       "100.0\n",
  59.       "97.22666666666666\n"
  60.      ]
  61.     }
  62.    ],
  63.    "source": [
  64.     "# Check the accuracy score of the prediction for the training set\n",
  65.     "print(model.score(features_train,target_train)*100)\n",
  66.     "\n",
  67.     "# Check the accuracy score of the prediction for the test set\n",
  68.     "print(model.score(features_test, target_test)*100)"
  69.    ]
  70.   }
  71.  ],
  72.  "metadata": {
  73.   "kernelspec": {
  74.    "display_name": "Python 3",
  75.    "language": "python",
  76.    "name": "python3"
  77.   },
  78.   "language_info": {
  79.    "codemirror_mode": {
  80.     "name": "ipython",
  81.     "version": 3
  82.    },
  83.    "file_extension": ".py",
  84.    "mimetype": "text/x-python",
  85.    "name": "python",
  86.    "nbconvert_exporter": "python",
  87.    "pygments_lexer": "ipython3",
  88.    "version": "3.7.3"
  89.   }
  90.  },
  91.  "nbformat": 4,
  92.  "nbformat_minor": 2
  93. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top