{
 "cells": [
  {
   "cell_type": "code",
<<<<<<< HEAD
   "execution_count": 10,
=======
   "execution_count": 1,
>>>>>>> caaa71666df3f35a02848991df9e15db55aef57c
   "id": "b6ea6c3b",
   "metadata": {},
   "outputs": [
    {
<<<<<<< HEAD
     "name": "stdout",
     "output_type": "stream",
     "text": [
<<<<<<< HEAD
      "       age  workclass  education.num  marital.status  occupation  \\\n",
      "0       90          0              9               6           0   \n",
      "1       82          4              9               6           4   \n",
      "2       66          0             10               6           0   \n",
      "3       54          4              4               0           7   \n",
      "4       41          4             10               5          10   \n",
      "...    ...        ...            ...             ...         ...   \n",
      "32556   22          4             10               4          11   \n",
      "32557   27          4             12               2          13   \n",
      "32558   40          4              9               2           7   \n",
      "32559   58          4              9               6           1   \n",
      "32560   22          4              9               4           1   \n",
      "\n",
      "       relationship  race  sex  capital.gain  capital.loss  hours.per.week  \n",
      "0                 1     4    0             0          4356              40  \n",
      "1                 1     4    0             0          4356              18  \n",
      "2                 4     2    0             0          4356              40  \n",
      "3                 4     4    0             0          3900              40  \n",
      "4                 3     4    0             0          3900              40  \n",
      "...             ...   ...  ...           ...           ...             ...  \n",
      "32556             1     4    1             0             0              40  \n",
      "32557             5     4    0             0             0              38  \n",
      "32558             0     4    1             0             0              40  \n",
      "32559             4     4    0             0             0              40  \n",
      "32560             3     4    1             0             0              20  \n",
      "\n",
      "[32561 rows x 11 columns]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 683108 characters]",
      "text/plain": [
       "<Figure size 2000x1000 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Feature Importances:\n",
      "           feature  importance\n",
      "5     relationship    0.218174\n",
      "0              age    0.174282\n",
      "2    education.num    0.147966\n",
      "8     capital.gain    0.129988\n",
      "10  hours.per.week    0.105884\n",
      "4       occupation    0.085228\n",
      "1        workclass    0.052566\n",
      "9     capital.loss    0.044720\n",
      "6             race    0.023650\n",
      "3   marital.status    0.011255\n",
      "7              sex    0.006286\n"
=======
      "       age workclass  fnlwgt  education.num      marital.status  \\\n",
      "0       90         ?   77053              9             Widowed   \n",
      "1       82   Private  132870              9             Widowed   \n",
      "2       66         ?  186061             10             Widowed   \n",
      "3       54   Private  140359              4            Divorced   \n",
      "4       41   Private  264663             10           Separated   \n",
      "...    ...       ...     ...            ...                 ...   \n",
      "32556   22   Private  310152             10       Never-married   \n",
      "32557   27   Private  257302             12  Married-civ-spouse   \n",
      "32558   40   Private  154374              9  Married-civ-spouse   \n",
      "32559   58   Private  151910              9             Widowed   \n",
      "32560   22   Private  201490              9       Never-married   \n",
      "\n",
      "              occupation   relationship   race     sex  capital.gain  \\\n",
      "0                      ?  Not-in-family  White  Female             0   \n",
      "1        Exec-managerial  Not-in-family  White  Female             0   \n",
      "2                      ?      Unmarried  Black  Female             0   \n",
      "3      Machine-op-inspct      Unmarried  White  Female             0   \n",
      "4         Prof-specialty      Own-child  White  Female             0   \n",
      "...                  ...            ...    ...     ...           ...   \n",
      "32556    Protective-serv  Not-in-family  White    Male             0   \n",
      "32557       Tech-support           Wife  White  Female             0   \n",
      "32558  Machine-op-inspct        Husband  White    Male             0   \n",
      "32559       Adm-clerical      Unmarried  White  Female             0   \n",
      "32560       Adm-clerical      Own-child  White    Male             0   \n",
      "\n",
      "       capital.loss  hours.per.week native.country income  \n",
      "0              4356              40  United-States  <=50K  \n",
      "1              4356              18  United-States  <=50K  \n",
      "2              4356              40  United-States  <=50K  \n",
      "3              3900              40  United-States  <=50K  \n",
      "4              3900              40  United-States  <=50K  \n",
      "...             ...             ...            ...    ...  \n",
      "32556             0              40  United-States  <=50K  \n",
      "32557             0              38  United-States  <=50K  \n",
      "32558             0              40  United-States   >50K  \n",
      "32559             0              40  United-States  <=50K  \n",
      "32560             0              20  United-States  <=50K  \n",
      "\n",
      "[32561 rows x 14 columns]\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "could not convert string to float: '?'",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mValueError\u001b[39m                                Traceback (most recent call last)",
      "\u001b[32m/tmp/ipykernel_3669/1374041598.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m()\u001b[39m\n\u001b[32m     37\u001b[39m print(X)\n\u001b[32m     38\u001b[39m \n\u001b[32m     39\u001b[39m \u001b[38;5;66;03m# Create and train the decision tree classifier\u001b[39;00m\n\u001b[32m     40\u001b[39m clf = DecisionTreeClassifier(random_state=\u001b[32m42\u001b[39m)\n\u001b[32m---> \u001b[39m\u001b[32m41\u001b[39m clf.fit(X, y)\n\u001b[32m     42\u001b[39m \n\u001b[32m     43\u001b[39m \u001b[38;5;66;03m# Visualize the tree\u001b[39;00m\n\u001b[32m     44\u001b[39m plt.figure(figsize=(\u001b[32m20\u001b[39m,\u001b[32m10\u001b[39m))\n",
      "\u001b[32m~/Documents/MLPproject/.venv/lib/python3.12/site-packages/sklearn/base.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m(estimator, *args, **kwargs)\u001b[39m\n\u001b[32m   1361\u001b[39m                 skip_parameter_validation=(\n\u001b[32m   1362\u001b[39m                     prefer_skip_nested_validation \u001b[38;5;28;01mor\u001b[39;00m global_skip_validation\n\u001b[32m   1363\u001b[39m                 )\n\u001b[32m   1364\u001b[39m             ):\n\u001b[32m-> \u001b[39m\u001b[32m1365\u001b[39m                 \u001b[38;5;28;01mreturn\u001b[39;00m fit_method(estimator, *args, **kwargs)\n",
      "\u001b[32m~/Documents/MLPproject/.venv/lib/python3.12/site-packages/sklearn/tree/_classes.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m(self, X, y, sample_weight, check_input)\u001b[39m\n\u001b[32m   1020\u001b[39m         self : DecisionTreeClassifier\n\u001b[32m   1021\u001b[39m             Fitted estimator.\n\u001b[32m   1022\u001b[39m         \"\"\"\n\u001b[32m   1023\u001b[39m \n\u001b[32m-> \u001b[39m\u001b[32m1024\u001b[39m         super()._fit(\n\u001b[32m   1025\u001b[39m             X,\n\u001b[32m   1026\u001b[39m             y,\n\u001b[32m   1027\u001b[39m             sample_weight=sample_weight,\n",
      "\u001b[32m~/Documents/MLPproject/.venv/lib/python3.12/site-packages/sklearn/tree/_classes.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m(self, X, y, sample_weight, check_input, missing_values_in_feature_mask)\u001b[39m\n\u001b[32m    248\u001b[39m             check_X_params = dict(\n\u001b[32m    249\u001b[39m                 dtype=DTYPE, accept_sparse=\u001b[33m\"csc\"\u001b[39m, ensure_all_finite=\u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[32m    250\u001b[39m             )\n\u001b[32m    251\u001b[39m             check_y_params = dict(ensure_2d=\u001b[38;5;28;01mFalse\u001b[39;00m, dtype=\u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[32m--> \u001b[39m\u001b[32m252\u001b[39m             X, y = validate_data(\n\u001b[32m    253\u001b[39m                 self, X, y, validate_separately=(check_X_params, check_y_params)\n\u001b[32m    254\u001b[39m             )\n\u001b[32m    255\u001b[39m \n",
      "\u001b[32m~/Documents/MLPproject/.venv/lib/python3.12/site-packages/sklearn/utils/validation.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m(_estimator, X, y, reset, validate_separately, skip_check_array, **check_params)\u001b[39m\n\u001b[32m   2962\u001b[39m             \u001b[38;5;66;03m# :(\u001b[39;00m\n\u001b[32m   2963\u001b[39m             check_X_params, check_y_params = validate_separately\n\u001b[32m   2964\u001b[39m             \u001b[38;5;28;01mif\u001b[39;00m \u001b[33m\"estimator\"\u001b[39m \u001b[38;5;28;01mnot\u001b[39;00m \u001b[38;5;28;01min\u001b[39;00m check_X_params:\n\u001b[32m   2965\u001b[39m                 check_X_params = {**default_check_params, **check_X_params}\n\u001b[32m-> \u001b[39m\u001b[32m2966\u001b[39m             X = check_array(X, input_name=\u001b[33m\"X\"\u001b[39m, **check_X_params)\n\u001b[32m   2967\u001b[39m             \u001b[38;5;28;01mif\u001b[39;00m \u001b[33m\"estimator\"\u001b[39m \u001b[38;5;28;01mnot\u001b[39;00m \u001b[38;5;28;01min\u001b[39;00m check_y_params:\n\u001b[32m   2968\u001b[39m                 check_y_params = {**default_check_params, **check_y_params}\n\u001b[32m   2969\u001b[39m             y = check_array(y, input_name=\u001b[33m\"y\"\u001b[39m, **check_y_params)\n",
      "\u001b[32m~/Documents/MLPproject/.venv/lib/python3.12/site-packages/sklearn/utils/validation.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_writeable, force_all_finite, ensure_all_finite, ensure_non_negative, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator, input_name)\u001b[39m\n\u001b[32m   1050\u001b[39m                         )\n\u001b[32m   1051\u001b[39m                     array = xp.astype(array, dtype, copy=\u001b[38;5;28;01mFalse\u001b[39;00m)\n\u001b[32m   1052\u001b[39m                 \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m   1053\u001b[39m                     array = _asarray_with_order(array, order=order, dtype=dtype, xp=xp)\n\u001b[32m-> \u001b[39m\u001b[32m1054\u001b[39m             \u001b[38;5;28;01mexcept\u001b[39;00m ComplexWarning \u001b[38;5;28;01mas\u001b[39;00m complex_warning:\n\u001b[32m   1055\u001b[39m                 raise ValueError(\n\u001b[32m   1056\u001b[39m                     \u001b[33m\"Complex data not supported\\n{}\\n\"\u001b[39m.format(array)\n\u001b[32m   1057\u001b[39m                 ) \u001b[38;5;28;01mfrom\u001b[39;00m complex_warning\n",
      "\u001b[32m~/Documents/MLPproject/.venv/lib/python3.12/site-packages/sklearn/utils/_array_api.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m(array, dtype, order, copy, xp, device)\u001b[39m\n\u001b[32m    753\u001b[39m         \u001b[38;5;66;03m# Use NumPy API to support order\u001b[39;00m\n\u001b[32m    754\u001b[39m         \u001b[38;5;28;01mif\u001b[39;00m copy \u001b[38;5;28;01mis\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[32m    755\u001b[39m             array = numpy.array(array, order=order, dtype=dtype)\n\u001b[32m    756\u001b[39m         \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m757\u001b[39m             array = numpy.asarray(array, order=order, dtype=dtype)\n\u001b[32m    758\u001b[39m \n\u001b[32m    759\u001b[39m         \u001b[38;5;66;03m# At this point array is a NumPy ndarray. We convert it to an array\u001b[39;00m\n\u001b[32m    760\u001b[39m         \u001b[38;5;66;03m# container that is consistent with the input's namespace.\u001b[39;00m\n",
      "\u001b[32m~/Documents/MLPproject/.venv/lib/python3.12/site-packages/pandas/core/generic.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m(self, dtype, copy)\u001b[39m\n\u001b[32m   2167\u001b[39m             )\n\u001b[32m   2168\u001b[39m         values = self._values\n\u001b[32m   2169\u001b[39m         \u001b[38;5;28;01mif\u001b[39;00m copy \u001b[38;5;28;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m   2170\u001b[39m             \u001b[38;5;66;03m# Note: branch avoids `copy=None` for NumPy 1.x support\u001b[39;00m\n\u001b[32m-> \u001b[39m\u001b[32m2171\u001b[39m             arr = np.asarray(values, dtype=dtype)\n\u001b[32m   2172\u001b[39m         \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m   2173\u001b[39m             arr = np.array(values, dtype=dtype, copy=copy)\n\u001b[32m   2174\u001b[39m \n",
      "\u001b[31mValueError\u001b[39m: could not convert string to float: '?'"
>>>>>>> 2ff73d660ba62540b0a320049b9314f62843e037
=======
     "ename": "InvalidIndexError",
     "evalue": "(slice(None, None, None), 0)",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mKeyError\u001b[39m                                  Traceback (most recent call last)",
      "\u001b[36mFile \u001b[39m\u001b[32m~/Documents/MLP/Projects/MLPproject/.venv/lib/python3.12/site-packages/pandas/core/indexes/base.py:3812\u001b[39m, in \u001b[36mIndex.get_loc\u001b[39m\u001b[34m(self, key)\u001b[39m\n\u001b[32m   3811\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m-> \u001b[39m\u001b[32m3812\u001b[39m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_engine\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcasted_key\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m   3813\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n",
      "\u001b[36mFile \u001b[39m\u001b[32mpandas/_libs/index.pyx:167\u001b[39m, in \u001b[36mpandas._libs.index.IndexEngine.get_loc\u001b[39m\u001b[34m()\u001b[39m\n",
      "\u001b[36mFile \u001b[39m\u001b[32mpandas/_libs/index.pyx:196\u001b[39m, in \u001b[36mpandas._libs.index.IndexEngine.get_loc\u001b[39m\u001b[34m()\u001b[39m\n",
      "\u001b[36mFile \u001b[39m\u001b[32mpandas/_libs/hashtable_class_helper.pxi:7088\u001b[39m, in \u001b[36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[39m\u001b[34m()\u001b[39m\n",
      "\u001b[36mFile \u001b[39m\u001b[32mpandas/_libs/hashtable_class_helper.pxi:7096\u001b[39m, in \u001b[36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[39m\u001b[34m()\u001b[39m\n",
      "\u001b[31mKeyError\u001b[39m: (slice(None, None, None), 0)",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[31mInvalidIndexError\u001b[39m                         Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 39\u001b[39m\n\u001b[32m     37\u001b[39m ax = fig.add_subplot(n_features, n_features, plt_num)\n\u001b[32m     38\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m(i == j):\n\u001b[32m---> \u001b[39m\u001b[32m39\u001b[39m     ax.hist(\u001b[43mX_train\u001b[49m\u001b[43m[\u001b[49m\u001b[43m:\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mi\u001b[49m\u001b[43m]\u001b[49m, bins=\u001b[32m25\u001b[39m, color=\u001b[33m'\u001b[39m\u001b[33mgray\u001b[39m\u001b[33m'\u001b[39m)\n\u001b[32m     40\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m     41\u001b[39m     ax.scatter(X_train[:, j], X_train[:, i], c=np.array(colors)[y_train], s=\u001b[32m30\u001b[39m, alpha=\u001b[32m0.3\u001b[39m)\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/Documents/MLP/Projects/MLPproject/.venv/lib/python3.12/site-packages/pandas/core/frame.py:4113\u001b[39m, in \u001b[36mDataFrame.__getitem__\u001b[39m\u001b[34m(self, key)\u001b[39m\n\u001b[32m   4111\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.columns.nlevels > \u001b[32m1\u001b[39m:\n\u001b[32m   4112\u001b[39m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._getitem_multilevel(key)\n\u001b[32m-> \u001b[39m\u001b[32m4113\u001b[39m indexer = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mcolumns\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m   4114\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m is_integer(indexer):\n\u001b[32m   4115\u001b[39m     indexer = [indexer]\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/Documents/MLP/Projects/MLPproject/.venv/lib/python3.12/site-packages/pandas/core/indexes/base.py:3818\u001b[39m, in \u001b[36mIndex.get_loc\u001b[39m\u001b[34m(self, key)\u001b[39m\n\u001b[32m   3813\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n\u001b[32m   3814\u001b[39m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(casted_key, \u001b[38;5;28mslice\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m (\n\u001b[32m   3815\u001b[39m         \u001b[38;5;28misinstance\u001b[39m(casted_key, abc.Iterable)\n\u001b[32m   3816\u001b[39m         \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28many\u001b[39m(\u001b[38;5;28misinstance\u001b[39m(x, \u001b[38;5;28mslice\u001b[39m) \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m casted_key)\n\u001b[32m   3817\u001b[39m     ):\n\u001b[32m-> \u001b[39m\u001b[32m3818\u001b[39m         \u001b[38;5;28;01mraise\u001b[39;00m InvalidIndexError(key)\n\u001b[32m   3819\u001b[39m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01merr\u001b[39;00m\n\u001b[32m   3820\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[32m   3821\u001b[39m     \u001b[38;5;66;03m# If we have a listlike key, _check_indexing_error will raise\u001b[39;00m\n\u001b[32m   3822\u001b[39m     \u001b[38;5;66;03m#  InvalidIndexError. Otherwise we fall through and re-raise\u001b[39;00m\n\u001b[32m   3823\u001b[39m     \u001b[38;5;66;03m#  the TypeError.\u001b[39;00m\n",
      "\u001b[31mInvalidIndexError\u001b[39m: (slice(None, None, None), 0)"
>>>>>>> caaa71666df3f35a02848991df9e15db55aef57c
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKEAAACTCAYAAADm43kQAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjcsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvTLEjVAAAAAlwSFlzAAAPYQAAD2EBqD+naQAACbdJREFUeJzt3UtIVG0YB/D/aM5MQTNd8VKjEdKVyC5YupFAEArJVfYtcoi0gjY2kCVFYi2EigjEqI3OokUXsFoUSkQRpBGUgmktrFCDxq6eycgJ9PkW4XzfpFOeacZHp/8PzmJO7znv+3b+HOeceeGxiIiASFGC9gCIGEJSxxCSOoaQ1DGEpI4hJHUMIaljCEkdQ0jqGEJSZzqEDx48QGFhIdLS0mCxWHDjxo3fHnP//n2sX78eNpsNmZmZ8Hq9EQyV4pXpEH79+hVr165FXV3dhNq/fv0a27Ztw5YtW9De3o7y8nKUlpaiubnZ9GApPln+ZAGDxWLB9evXUVRUFLbN4cOHcevWLTx79iy4b+fOnRgYGEBTU1OkXVMcmRHrDlpbW5Gfnx+yr6CgAOXl5WGPCQQCCAQCwc8jIyP49OkT5s+fD4vFEquh0m+ICL58+YK0tDQkJETvcSLmIfT5fEhOTg7Zl5ycDL/fj2/fvmHmzJljjqmpqUF1dXWsh0YR6uvrw+LFi6N2vpiHMBKVlZXweDzBz4ZhID09HX19fXA4HIoj+7v5/X64XC7Mnj07queNeQhTUlLQ398fsq+/vx8Oh2PcuyAA2Gw22Gy2MfsdDgdDOAVE+ytRzN8T5uTk4O7duyH77ty5g5ycnFh3TdOE6RAODg6ivb0d7e3tAH68gmlvb0dvby+AH39KS0pKgu3379+PV69eoaKiAi9evMD58+dx9epVHDx4MDozoOlPTLp3754AGLO53W4REXG73ZKXlzfmmKysLLFarbJ06VJpaGgw1adhGAJADMMwO1yKolhdhz96TzhZ/H4/nE4nDMPgd0JFs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WVJSEtatW4fu7u5YDDEmwl0Hh8OBmTNnTvg86iGMh+VhkczhZ8PDw+jo6EBqamqshhl1UbsOZp+aYkFjeVi0mZ1DdXW1NDc3y8uXL+XJkyeyc+dOsdvt0tnZqTUF+fLli7S1tUlbW5sAkLNnz0pbW5v09PSIiMiRI0dk165dwfajr2gOHTokz58/l7q6uun7ikZk8peHxYKZOZSXlwfbJicny9atW+Xp06cKo/7PvXv3BMCYbXTcbrdb8vLyxhyTlZUlVqtVli5dKg0NDab75VIuUqf+nZCIISR1DCGpYwhJHUNI6hhCUscQkjqGkNQxhKSOISR1DCGpYwhJ3b+8OUfiN/PNKAAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 1500x1500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.pipeline import Pipeline\n",
    "from sklearn.tree import DecisionTreeClassifier, plot_tree\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "\n",
    "df = pd.read_csv('./Datasets/adult.csv', comment = '#')\n",
    "\n",
    "# First, create a copy of the dataframe to avoid modifying the original\n",
    "df_encoded = df.copy()\n",
    "\n",
    "# Apply label encoding to categorical columns\n",
    "label_encoder = LabelEncoder()\n",
    "categorical_columns = ['workclass', 'marital.status', 'occupation', \n",
    "                      'relationship', 'race', 'sex', 'income']\n",
    "\n",
    "for column in categorical_columns:\n",
    "    df_encoded[column] = label_encoder.fit_transform(df_encoded[column])\n",
    "\n",
    "# Now properly separate features and target\n",
<<<<<<< HEAD
    "X = df_encoded.drop(columns=['income', 'native.country', 'education','fnlwgt'])\n",
=======
    "X = df_encoded.drop(columns=['income', 'native.country', 'education'])\n",
>>>>>>> 2ff73d660ba62540b0a320049b9314f62843e037
    "y = df_encoded['income']\n",
    "\n",
    "# Split the data\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
    "X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.2, random_state=42)\n",
    "\n",
    "\n",
    "\n",
    "n_features = 10\n",
    "fig=plt.figure( figsize=(15, 15) )\n",
    "plt_num = 1\n",
    "for i in range(n_features):\n",
    "    for j in range(n_features):\n",
    "        ax = fig.add_subplot(n_features, n_features, plt_num)\n",
    "        if(i == j):\n",
    "            ax.hist(X_train[:, i], bins=25, color='gray')\n",
    "        else:\n",
    "            ax.scatter(X_train[:, j], X_train[:, i], c=np.array(colors)[y_train], s=30, alpha=0.3)\n",
    "                \n",
    "        if(i == n_features-1):\n",
    "            ax.set_xlabel(f'$x_{{{j}}}$', fontsize=22)\n",
    "        \n",
    "        if(j==0):\n",
    "            ax.set_ylabel(f'$x_{{{i}}}$', fontsize=22)\n",
    "\n",
<<<<<<< HEAD
    "# Print feature importances\n",
    "importances = pd.DataFrame({\n",
    "    'feature': X.columns,\n",
    "    'importance': clf.feature_importances_\n",
    "})\n",
    "print(\"\\nFeature Importances:\")\n",
    "print(importances.sort_values('importance', ascending=False))\n",
<<<<<<< HEAD
    "\n"
=======
    "\n",
    "# Example prediction\n",
    "print(\"\\nPrediction for a new sample:\")\n",
    "new_sample = pd.DataFrame([[350, 0, 0, 0.09]], columns=X.columns)  # Force=300, Coating=Yes, Defects=No, Moisture=0.05\n",
    "prediction = clf.predict(new_sample)\n",
    "print(f\"Will the rod break? {'Yes' if prediction[0] == 1 else 'No'}\")"
>>>>>>> 2ff73d660ba62540b0a320049b9314f62843e037
=======
    "        ax.grid(True)\n",
    "        plt_num +=1\n"
>>>>>>> caaa71666df3f35a02848991df9e15db55aef57c
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "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.12.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
