{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2019-09-01T03:38:26.157140Z", "start_time": "2019-09-01T03:38:26.142762Z" } }, "outputs": [], "source": [ "#!/usr/bin/python\n", "\n", "\n", "\"\"\"\n", " Starter code for the validation mini-project.\n", " The first step toward building your POI identifier!\n", "\n", " Start by loading/formatting the data\n", "\n", " After that, it's not our code anymore--it's yours!\n", "\"\"\"\n", "\n", "import pickle\n", "import sys\n", "sys.path.append(\"../tools/\")\n", "from feature_format import featureFormat, targetFeatureSplit\n", "\n", "data_dict = pickle.load(open(\"../final_project/final_project_dataset.pkl\", \"rb\") )\n", "\n", "### first element is our labels, any added elements are predictor\n", "### features. Keep this the same for the mini-project, but you'll\n", "### have a different feature list when you do the final project.\n", "features_list = [\"poi\", \"salary\"]\n", "\n", "data = featureFormat(data_dict, features_list, sort_keys = '../tools/python2_lesson13_keys.pkl')\n", "labels, features = targetFeatureSplit(data)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2019-09-01T03:47:44.785291Z", "start_time": "2019-09-01T03:47:44.777944Z" } }, "outputs": [ { "data": { "text/plain": [ "95" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "code", "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2019-09-01T03:58:48.227230Z", "start_time": "2019-09-01T03:58:48.210049Z" } }, "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,\n", " random_state=None, splitter='best')" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "### it's all yours from here forward! \n", "from sklearn.model_selection import train_test_split\n", "from sklearn.model_selection import GridSearchCV\n", "from sklearn.decomposition import PCA\n", "from sklearn.tree import DecisionTreeClassifier\n", "\n", "features_train, features_test, labels_train, labels_test = train_test_split(features, labels, test_size = 0.3, random_state = 42)\n", "\n", "clf = DecisionTreeClassifier()\n", "clf.fit(features_train, labels_train)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2019-09-01T03:58:50.429390Z", "start_time": "2019-09-01T03:58:50.421893Z" } }, "outputs": [ { "data": { "text/plain": [ "0.7241379310344828" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "clf.score(features_test, labels_test)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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" }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }