From 40b3859547de4e57b9415468def33aced6256092 Mon Sep 17 00:00:00 2001 From: Andreaierardi Date: Wed, 4 Mar 2020 16:54:16 +0100 Subject: [PATCH] updating nb --- .../COVID-19 Analysis-checkpoint.ipynb | 54 ++++-------------- .../Python/Examples/COVID-19 Analysis.ipynb | 56 ++++--------------- .../Examples/Diamonds ML regression.ipynb | 2 +- 3 files changed, 25 insertions(+), 87 deletions(-) diff --git a/1year/2trimester/Coding for Data Science - Python language/Python/Examples/.ipynb_checkpoints/COVID-19 Analysis-checkpoint.ipynb b/1year/2trimester/Coding for Data Science - Python language/Python/Examples/.ipynb_checkpoints/COVID-19 Analysis-checkpoint.ipynb index 501944c16..967872f38 100644 --- a/1year/2trimester/Coding for Data Science - Python language/Python/Examples/.ipynb_checkpoints/COVID-19 Analysis-checkpoint.ipynb +++ b/1year/2trimester/Coding for Data Science - Python language/Python/Examples/.ipynb_checkpoints/COVID-19 Analysis-checkpoint.ipynb @@ -18241,54 +18241,24 @@ }, { "cell_type": "code", - "execution_count": 307, + "execution_count": 1, "metadata": {}, - "outputs": [ - { - "ename": "AttributeError", - "evalue": "'numpy.ndarray' object has no attribute 'columns'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# Import tools needed for visualization\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mfeature_list\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mlist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfeatures\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0msklearn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtree\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mexport_graphviz\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mpydot\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mAttributeError\u001b[0m: 'numpy.ndarray' object has no attribute 'columns'" - ] - } - ], + "outputs": [], "source": [ "# Import tools needed for visualization\n", "\n", - "feature_list = list(features.columns)\n", - "from sklearn.tree import export_graphviz\n", - "import pydot\n", - "rf_small = RandomForestRegressor(n_estimators=10, max_depth = 3)\n", - "rf_small.fit(train_features, train_labels)# Extract the small tree\n", - "tree_small = rf_small.estimators_[5]# Save the tree as a png image\n", - "export_graphviz(tree_small, out_file = 'small_tree.dot', feature_names = list(df_hubei.columns), rounded = True, precision = 1)\n", + "#feature_list = list(df_hubei.columns[0])\n", + "#from sklearn.tree import export_graphviz\n", + "#import pydot\n", + "#rf_small = RandomForestRegressor(n_estimators=10, max_depth = 3)\n", + "#rf_small.fit(train_features, train_labels)# Extract the small tree\n", + "#tree_small = rf_small.estimators_[5]# Save the tree as a png image\n", + "#export_graphviz(tree_small, out_file = 'small_tree.dot', feature_names = [\"Values\"], rounded = True, precision = 1)\n", "\n", - "(graph, ) = pydot.graph_from_dot_file('small_tree.dot')\n", - "graph.write_png('small_tree.png');" + "#(graph, ) = pydot.graph_from_dot_file('small_tree.dot')\n", + "#graph.write_png('small_tree.png');" ] }, - { - "cell_type": "code", - "execution_count": 311, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['Values', 'Lags']" - ] - }, - "execution_count": 311, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, { "cell_type": "code", "execution_count": null, @@ -18317,5 +18287,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/1year/2trimester/Coding for Data Science - Python language/Python/Examples/COVID-19 Analysis.ipynb b/1year/2trimester/Coding for Data Science - Python language/Python/Examples/COVID-19 Analysis.ipynb index 94ad89075..967872f38 100644 --- a/1year/2trimester/Coding for Data Science - Python language/Python/Examples/COVID-19 Analysis.ipynb +++ b/1year/2trimester/Coding for Data Science - Python language/Python/Examples/COVID-19 Analysis.ipynb @@ -18241,54 +18241,22 @@ }, { "cell_type": "code", - "execution_count": 324, + "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:7: DataConversionWarning:\n", - "\n", - "A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples,), for example using ravel().\n", - "\n" - ] - }, - { - "ename": "FileNotFoundError", - "evalue": "[WinError 2] \"dot\" not found in path.", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32mE:\\ProgramData\\Anaconda3\\lib\\site-packages\\pydot.py\u001b[0m in \u001b[0;36mcreate\u001b[1;34m(self, prog, format, encoding)\u001b[0m\n\u001b[0;32m 1914\u001b[0m \u001b[0marguments\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0marguments\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1915\u001b[1;33m \u001b[0mworking_dir\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtmp_dir\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1916\u001b[0m )\n", - "\u001b[1;32mE:\\ProgramData\\Anaconda3\\lib\\site-packages\\pydot.py\u001b[0m in \u001b[0;36mcall_graphviz\u001b[1;34m(program, arguments, working_dir, **kwargs)\u001b[0m\n\u001b[0;32m 135\u001b[0m \u001b[0mstdout\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0msubprocess\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mPIPE\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 136\u001b[1;33m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 137\u001b[0m )\n", - "\u001b[1;32mE:\\ProgramData\\Anaconda3\\lib\\subprocess.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)\u001b[0m\n\u001b[0;32m 774\u001b[0m \u001b[0merrread\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merrwrite\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 775\u001b[1;33m restore_signals, start_new_session)\n\u001b[0m\u001b[0;32m 776\u001b[0m \u001b[1;32mexcept\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mE:\\ProgramData\\Anaconda3\\lib\\subprocess.py\u001b[0m in \u001b[0;36m_execute_child\u001b[1;34m(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)\u001b[0m\n\u001b[0;32m 1177\u001b[0m \u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfspath\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcwd\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mcwd\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;32melse\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1178\u001b[1;33m startupinfo)\n\u001b[0m\u001b[0;32m 1179\u001b[0m \u001b[1;32mfinally\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mFileNotFoundError\u001b[0m: [WinError 2] Impossibile trovare il file specificato", - "\nDuring handling of the above exception, another exception occurred:\n", - "\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mgraph\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m)\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpydot\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgraph_from_dot_file\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'small_tree.dot'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m \u001b[0mgraph\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwrite_png\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'small_tree.png'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m;\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;32mE:\\ProgramData\\Anaconda3\\lib\\site-packages\\pydot.py\u001b[0m in \u001b[0;36mnew_method\u001b[1;34m(path, f, prog, encoding)\u001b[0m\n\u001b[0;32m 1732\u001b[0m self.write(\n\u001b[0;32m 1733\u001b[0m \u001b[0mpath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mformat\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mprog\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mprog\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1734\u001b[1;33m encoding=encoding)\n\u001b[0m\u001b[0;32m 1735\u001b[0m \u001b[0mname\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'write_{fmt}'\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfmt\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfrmt\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1736\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__setattr__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnew_method\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mE:\\ProgramData\\Anaconda3\\lib\\site-packages\\pydot.py\u001b[0m in \u001b[0;36mwrite\u001b[1;34m(self, path, prog, format, encoding)\u001b[0m\n\u001b[0;32m 1815\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1816\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1817\u001b[1;33m \u001b[0ms\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mprog\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mformat\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mencoding\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mencoding\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1818\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0mio\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'wb'\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1819\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mE:\\ProgramData\\Anaconda3\\lib\\site-packages\\pydot.py\u001b[0m in \u001b[0;36mcreate\u001b[1;34m(self, prog, format, encoding)\u001b[0m\n\u001b[0;32m 1920\u001b[0m args[1] = '\"{prog}\" not found in path.'.format(\n\u001b[0;32m 1921\u001b[0m prog=prog)\n\u001b[1;32m-> 1922\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mOSError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1923\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1924\u001b[0m \u001b[1;32mraise\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mFileNotFoundError\u001b[0m: [WinError 2] \"dot\" not found in path." - ] - } - ], + "outputs": [], "source": [ "# Import tools needed for visualization\n", "\n", - "feature_list = list(df_hubei.columns[0])\n", - "from sklearn.tree import export_graphviz\n", - "import pydot\n", - "rf_small = RandomForestRegressor(n_estimators=10, max_depth = 3)\n", - "rf_small.fit(train_features, train_labels)# Extract the small tree\n", - "tree_small = rf_small.estimators_[5]# Save the tree as a png image\n", - "export_graphviz(tree_small, out_file = 'small_tree.dot', feature_names = [\"Values\"], rounded = True, precision = 1)\n", + "#feature_list = list(df_hubei.columns[0])\n", + "#from sklearn.tree import export_graphviz\n", + "#import pydot\n", + "#rf_small = RandomForestRegressor(n_estimators=10, max_depth = 3)\n", + "#rf_small.fit(train_features, train_labels)# Extract the small tree\n", + "#tree_small = rf_small.estimators_[5]# Save the tree as a png image\n", + "#export_graphviz(tree_small, out_file = 'small_tree.dot', feature_names = [\"Values\"], rounded = True, precision = 1)\n", "\n", - "(graph, ) = pydot.graph_from_dot_file('small_tree.dot')\n", - "graph.write_png('small_tree.png');" + "#(graph, ) = pydot.graph_from_dot_file('small_tree.dot')\n", + "#graph.write_png('small_tree.png');" ] }, { @@ -18319,5 +18287,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/1year/2trimester/Coding for Data Science - Python language/Python/Examples/Diamonds ML regression.ipynb b/1year/2trimester/Coding for Data Science - Python language/Python/Examples/Diamonds ML regression.ipynb index 798bb3968..bbd9f9036 100644 --- a/1year/2trimester/Coding for Data Science - Python language/Python/Examples/Diamonds ML regression.ipynb +++ b/1year/2trimester/Coding for Data Science - Python language/Python/Examples/Diamonds ML regression.ipynb @@ -689,5 +689,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }