diff --git a/HospitalCancerClassification.ipynb b/HospitalCancerClassification.ipynb index cc15719..bc9edba 100644 --- a/HospitalCancerClassification.ipynb +++ b/HospitalCancerClassification.ipynb @@ -34,7 +34,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 53, "id": "1092545b-8be3-487b-87df-d8829e0a00eb", "metadata": {}, "outputs": [], @@ -45,12 +45,13 @@ "import pandas as pd\n", "import sklearn # importing the scikit-learn project, different name due to syntax rules \n", "import scipy\n", - "import threadpoolctl" + "import threadpoolctl\n", + "import matplotlib" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "3a05014a-200c-4bc6-9667-568898547852", "metadata": {}, "outputs": [], @@ -71,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "10d93e7f-9ba8-45a4-831d-7ba48046fea7", "metadata": {}, "outputs": [ @@ -81,7 +82,7 @@ "np.int64(10)" ] }, - "execution_count": 4, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -127,7 +128,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 4, "id": "a8887198-0dbd-471d-bd1e-836d34def83a", "metadata": {}, "outputs": [ @@ -195,7 +196,7 @@ "4 60 55-64" ] }, - "execution_count": 6, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -224,7 +225,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 15, "id": "f9beff06-ce08-479d-b63d-56ca8aaf6338", "metadata": {}, "outputs": [ @@ -256,43 +257,43 @@ " \n", " \n", " count\n", - " 9.900000e+02\n", - " 9.900000e+02\n", + " 1.000000e+03\n", + " 1.000000e+03\n", " \n", " \n", " mean\n", - " 1.076580e-17\n", - " 1.130409e-16\n", + " -4.618528e-17\n", + " -3.552714e-17\n", " \n", " \n", " std\n", - " 1.000505e+00\n", - " 1.000505e+00\n", + " 1.000500e+00\n", + " 1.000500e+00\n", " \n", " \n", " min\n", - " -1.679483e+00\n", - " -1.699762e+00\n", + " -1.684915e+00\n", + " -1.703831e+00\n", " \n", " \n", " 25%\n", - " -8.839714e-01\n", - " -8.598235e-01\n", + " -8.885765e-01\n", + " -8.621512e-01\n", " \n", " \n", " 50%\n", - " 6.927133e-04\n", - " -1.794981e-02\n", + " 3.871853e-03\n", + " -1.077505e-02\n", " \n", " \n", " 75%\n", - " 8.853568e-01\n", - " 8.703721e-01\n", + " 8.860227e-01\n", + " 8.687217e-01\n", " \n", " \n", " max\n", - " 1.735732e+00\n", - " 1.772241e+00\n", + " 1.733849e+00\n", + " 1.775369e+00\n", " \n", " \n", "\n", @@ -300,17 +301,17 @@ ], "text/plain": [ " bmi blood_pressure\n", - "count 9.900000e+02 9.900000e+02\n", - "mean 1.076580e-17 1.130409e-16\n", - "std 1.000505e+00 1.000505e+00\n", - "min -1.679483e+00 -1.699762e+00\n", - "25% -8.839714e-01 -8.598235e-01\n", - "50% 6.927133e-04 -1.794981e-02\n", - "75% 8.853568e-01 8.703721e-01\n", - "max 1.735732e+00 1.772241e+00" + "count 1.000000e+03 1.000000e+03\n", + "mean -4.618528e-17 -3.552714e-17\n", + "std 1.000500e+00 1.000500e+00\n", + "min -1.684915e+00 -1.703831e+00\n", + "25% -8.885765e-01 -8.621512e-01\n", + "50% 3.871853e-03 -1.077505e-02\n", + "75% 8.860227e-01 8.687217e-01\n", + "max 1.733849e+00 1.775369e+00" ] }, - "execution_count": 7, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -342,7 +343,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 16, "id": "8bc14115-e855-4233-9058-eff0ce5c9386", "metadata": {}, "outputs": [ @@ -399,8 +400,8 @@ " 51\n", " no\n", " low\n", - " 0.487601\n", - " 1.629026\n", + " 0.484421\n", + " 1.631857\n", " 226.4\n", " no\n", " 5\n", @@ -426,8 +427,8 @@ " 92\n", " no\n", " moderate\n", - " -1.487463\n", - " 1.396785\n", + " -1.492695\n", + " 1.399135\n", " 170.9\n", " yes\n", " 2\n", @@ -453,8 +454,8 @@ " 14\n", " no\n", " none\n", - " 0.528748\n", - " 0.568459\n", + " 0.525611\n", + " 0.569092\n", " 279.9\n", " yes\n", " 4\n", @@ -480,8 +481,8 @@ " 71\n", " yes\n", " low\n", - " 1.667153\n", - " -0.101170\n", + " 1.665199\n", + " -0.101925\n", " 280.7\n", " yes\n", " 0\n", @@ -507,8 +508,8 @@ " 60\n", " no\n", " none\n", - " -1.446316\n", - " 0.649743\n", + " -1.451505\n", + " 0.650544\n", " 212.8\n", " yes\n", " 5\n", @@ -535,14 +536,14 @@ ], "text/plain": [ " age family_history alcohol_consumption bmi blood_pressure cholesterol_level travelled_overseas number_of_children cancer_risk age_group_15-24 age_group_25-34 age_group_35-44 age_group_45-54 age_group_55-64 age_group_65-74 age_group_75-84 age_group_85+ smoking_history_former smoking_history_never diet_good diet_poor exercise_frequency_low exercise_frequency_moderate exercise_frequency_none\n", - "0 51 no low 0.487601 1.629026 226.4 no 5 moderate False False False True False False False False False True False True False False True\n", - "1 92 no moderate -1.487463 1.396785 170.9 yes 2 low False False False False False False False True False True False True False False False\n", - "2 14 no none 0.528748 0.568459 279.9 yes 4 high False False False False False False False False False False False False False False True\n", - "3 71 yes low 1.667153 -0.101170 280.7 yes 0 moderate False False False False False True False False True False False True False False False\n", - "4 60 no none -1.446316 0.649743 212.8 yes 5 moderate False False False False True False False False True False False False False False True" + "0 51 no low 0.484421 1.631857 226.4 no 5 moderate False False False True False False False False False True False True False False True\n", + "1 92 no moderate -1.492695 1.399135 170.9 yes 2 low False False False False False False False True False True False True False False False\n", + "2 14 no none 0.525611 0.569092 279.9 yes 4 high False False False False False False False False False False False False False False True\n", + "3 71 yes low 1.665199 -0.101925 280.7 yes 0 moderate False False False False False True False False True False False True False False False\n", + "4 60 no none -1.451505 0.650544 212.8 yes 5 moderate False False False False True False False False True False False False False False True" ] }, - "execution_count": 8, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -568,7 +569,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 17, "id": "a5174be9-c40b-457e-afd5-1ec97c70ed0a", "metadata": { "scrolled": true @@ -580,7 +581,7 @@ "((693, 23), (148, 23), (149, 23))" ] }, - "execution_count": 9, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -621,7 +622,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 18, "id": "c94e2161-e95d-4a84-864d-bc1388bd4d48", "metadata": {}, "outputs": [ @@ -631,7 +632,7 @@ "(693, 21)" ] }, - "execution_count": 10, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -651,12 +652,12 @@ "id": "49174e92-2e15-461a-844f-ffa90c0d7c99", "metadata": {}, "source": [ - "# Part 3: Train and evaluate ML model - Task 1: Train ML model 1" + "# Part 3: Train and evaluate ML model - Task 1: Train ML model 1 - MLPClassifier" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 19, "id": "b95cb28a-5312-4f55-8485-61c4e95e782e", "metadata": {}, "outputs": [], @@ -677,7 +678,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 20, "id": "9a44bcdd-8605-4e21-9a7a-1a3296f46909", "metadata": {}, "outputs": [ @@ -708,7 +709,7 @@ "dtype: object" ] }, - "execution_count": 13, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -720,7 +721,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 21, "id": "f16e2e40-e065-44ca-b944-e9a2921d89db", "metadata": {}, "outputs": [ @@ -728,7 +729,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/tmp/ipykernel_82/146862157.py:2: Pandas4Warning: For backward compatibility, 'str' dtypes are included by select_dtypes when 'object' dtype is specified. This behavior is deprecated and will be removed in a future version. Explicitly pass 'str' to `include` to select them, or to `exclude` to remove them and silence this warning.\n", + "/tmp/ipykernel_81/146862157.py:2: Pandas4Warning: For backward compatibility, 'str' dtypes are included by select_dtypes when 'object' dtype is specified. This behavior is deprecated and will be removed in a future version. Explicitly pass 'str' to `include` to select them, or to `exclude` to remove them and silence this warning.\n", "See https://pandas.pydata.org/docs/user_guide/migration-3-strings.html#string-migration-select-dtypes for details on how to write code that works with pandas 2 and 3.\n", " X_train.select_dtypes(include=['object']).head()\n" ] @@ -797,7 +798,7 @@ "869 no low" ] }, - "execution_count": 14, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -809,12 +810,12 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 22, "id": "f62a9503-664a-43d9-9afa-0029695acce8", "metadata": {}, "outputs": [], "source": [ - "# BUG FIXING - Rayyan Hodges\n", + "# BUG FIXING\n", "\n", "# Force all non-numeric columns to be one-hot encoded\n", "X_train = pd.get_dummies(X_train)\n", @@ -828,14 +829,14 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 23, "id": "cfcddd52-1a78-4c07-8f5d-036682a8cad6", "metadata": {}, "outputs": [ { "data": { "text/html": [ - "
MLPClassifier(hidden_layer_sizes=(64, 32), max_iter=300, random_state=42)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.