From 5b2b0cc5e082442ee0b26875d476619ab61a27ab Mon Sep 17 00:00:00 2001 From: 202210715329 MUHAMMAD IQBAL SALMAN <202210715329@mhs.ubharajaya.ac.id> Date: Sat, 14 Nov 2026 12:00:33 +0700 Subject: [PATCH] Upload files to "/" Source code ETS kelompok 1 --- Kelompok 1 ETS.ipynb | 1 + 1 file changed, 1 insertion(+) create mode 100644 Kelompok 1 ETS.ipynb diff --git a/Kelompok 1 ETS.ipynb b/Kelompok 1 ETS.ipynb new file mode 100644 index 0000000..788e3fe --- /dev/null +++ b/Kelompok 1 ETS.ipynb @@ -0,0 +1 @@ +{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyNE/AVfPCndZRo3VrKym5D7"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":2,"metadata":{"id":"Uy-HrhzJJ3Nn","executionInfo":{"status":"ok","timestamp":1793973707520,"user_tz":-420,"elapsed":39,"user":{"displayName":"Elfan Cris","userId":"15481999268029990356"}}},"outputs":[],"source":["import pandas as pd\n","\n","import numpy as np\n","\n","import matplotlib.pyplot as plt\n","\n","import seaborn as sns\n","\n","\n","from sklearn.model_selection import train_test_split\n","\n","from sklearn.tree import DecisionTreeClassifier\n","\n","from sklearn.ensemble import RandomForestClassifier\n","\n","from sklearn.metrics import accuracy_score, classification_report, confusion_matrix"]},{"cell_type":"code","source":["# Membaca file CSV\n","df = pd.read_csv('DataSet-Tugas-1.csv')\n","\n","# Menampilkan 5 baris pertama untuk memastikan data termuat dengan benar\n","df.head()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":206},"id":"nUVSP27_KRsM","executionInfo":{"status":"ok","timestamp":1793973715866,"user_tz":-420,"elapsed":103,"user":{"displayName":"Elfan Cris","userId":"15481999268029990356"}},"outputId":"979a4fcf-71f2-448f-e248-d2c239e3d480"},"execution_count":3,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Hematokrit Hemoglobin Jumlah Eritrosit Jumlah Lekosit Jumlah Trombosit \\\n","0 45.0 15.2 5.81 5.9 219 \n","1 45.0 15.3 5.49 6.2 312 \n","2 47.5 16.6 5.84 7.4 244 \n","3 45.4 15.0 5.33 6.7 342 \n","4 44.9 15.8 5.19 7.0 328 \n","\n"," MCH MCHC MCV SOURCE \n","0 26.2 33.8 77.5 rwj \n","1 27.9 34.0 82.0 rwj \n","2 28.4 34.9 81.3 rwj \n","3 28.1 33.0 85.2 rwj \n","4 30.4 35.2 86.5 rwj "],"text/html":["\n","
\n","
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
HematokritHemoglobinJumlah EritrositJumlah LekositJumlah TrombositMCHMCHCMCVSOURCE
045.015.25.815.921926.233.877.5rwj
145.015.35.496.231227.934.082.0rwj
247.516.65.847.424428.434.981.3rwj
345.415.05.336.734228.133.085.2rwj
444.915.85.197.032830.435.286.5rwj
\n","
\n","
\n","\n","
\n"," \n","\n"," \n","\n"," \n","
\n","\n","\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"df","summary":"{\n \"name\": \"df\",\n \"rows\": 4517,\n \"fields\": [\n {\n \"column\": \"Hematokrit\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 6.2491782216471,\n \"min\": 13.7,\n \"max\": 71.3,\n \"num_unique_values\": 357,\n \"samples\": [\n 50.9,\n 46.7,\n 58.1\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Hemoglobin\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 2.2005436286635716,\n \"min\": 3.8,\n \"max\": 24.9,\n \"num_unique_values\": 153,\n \"samples\": [\n 9.0,\n 8.4,\n 17.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Jumlah Eritrosit\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.7885816164402666,\n \"min\": 1.48,\n \"max\": 7.86,\n \"num_unique_values\": 438,\n \"samples\": [\n 6.47,\n 4.94,\n 6.54\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Jumlah Lekosit\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 5.37338679582883,\n \"min\": 1.1,\n \"max\": 76.6,\n \"num_unique_values\": 296,\n \"samples\": [\n 18.7,\n 13.0,\n 9.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Jumlah Trombosit\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 113,\n \"min\": 8,\n \"max\": 1183,\n \"num_unique_values\": 556,\n \"samples\": [\n 355,\n 421,\n 305\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"MCH\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 2.796720521352356,\n \"min\": 14.9,\n \"max\": 40.8,\n \"num_unique_values\": 210,\n \"samples\": [\n 31.0,\n 17.5,\n 23.4\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"MCHC\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1.238716289689131,\n \"min\": 26.0,\n \"max\": 39.0,\n \"num_unique_values\": 106,\n \"samples\": [\n 36.2,\n 33.5,\n 35.2\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"MCV\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 7.140812899585524,\n \"min\": 54.0,\n \"max\": 115.6,\n \"num_unique_values\": 432,\n \"samples\": [\n 115.3,\n 94.9,\n 99.7\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"SOURCE\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 2,\n \"samples\": [\n \"rwi\",\n \"rwj\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":3}]},{"cell_type":"code","source":["# Memeriksa informasi umum struktur data & tipe datanya\n","df.info()\n","\n","# Memisahkan Fitur (X) dan Target (y) secara benar:\n","# X adalah semua kolom dari awal sampai kolom ke-7 (kolom fitur laboratorium)\n","X = df.iloc[:, :-1] # atau df.drop(columns=['SOURCE'])\n","\n","# y adalah kolom terakhir yaitu 'SOURCE' (target kelas: 'rwj' / 'rwi')\n","y = df.iloc[:, -1] # atau df['SOURCE']\n","\n","# Membagi data menjadi Data Latih (80%) dan Data Uji (20%)\n","X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"raBgTpzjKSrX","executionInfo":{"status":"ok","timestamp":1793973741239,"user_tz":-420,"elapsed":1514,"user":{"displayName":"Elfan Cris","userId":"15481999268029990356"}},"outputId":"d6294b7f-6443-4551-cc4d-39fa6fcea60f"},"execution_count":4,"outputs":[{"output_type":"stream","name":"stdout","text":["\n","RangeIndex: 4517 entries, 0 to 4516\n","Data columns (total 9 columns):\n"," # Column Non-Null Count Dtype \n","--- ------ -------------- ----- \n"," 0 Hematokrit 4517 non-null float64\n"," 1 Hemoglobin 4517 non-null float64\n"," 2 Jumlah Eritrosit 4517 non-null float64\n"," 3 Jumlah Lekosit 4517 non-null float64\n"," 4 Jumlah Trombosit 4517 non-null int64 \n"," 5 MCH 4517 non-null float64\n"," 6 MCHC 4517 non-null float64\n"," 7 MCV 4517 non-null float64\n"," 8 SOURCE 4517 non-null object \n","dtypes: float64(7), int64(1), object(1)\n","memory usage: 317.7+ KB\n"]}]},{"cell_type":"code","source":["# Inisialisasi dan melatih model Decision Tree\n","model_1 = DecisionTreeClassifier(random_state=42)\n","model_1.fit(X_train, y_train)\n","\n","print(\"Model 1 (Decision Tree) berhasil dilatih!\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"YjBvt2pHKVug","executionInfo":{"status":"ok","timestamp":1793973763963,"user_tz":-420,"elapsed":36,"user":{"displayName":"Elfan Cris","userId":"15481999268029990356"}},"outputId":"1f984531-8551-451d-e94b-971d2a3da22d"},"execution_count":5,"outputs":[{"output_type":"stream","name":"stdout","text":["Model 1 (Decision Tree) berhasil dilatih!\n"]}]},{"cell_type":"code","source":["# Inisialisasi dan melatih model Random Forest (sebagai pembanding)[cite: 2]\n","model_2 = RandomForestClassifier(random_state=42)\n","model_2.fit(X_train, y_train)\n","\n","print(\"Model 2 (Random Forest) berhasil dilatih!\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"EIaNh-9tKY7Y","executionInfo":{"status":"ok","timestamp":1793973775285,"user_tz":-420,"elapsed":2669,"user":{"displayName":"Elfan Cris","userId":"15481999268029990356"}},"outputId":"7b25f28d-0c4b-4c43-f427-7acdf91068bd"},"execution_count":6,"outputs":[{"output_type":"stream","name":"stdout","text":["Model 2 (Random Forest) berhasil dilatih!\n"]}]},{"cell_type":"code","source":["# Evaluasi Model 1 (Decision Tree)\n","y_pred_1 = model_1.predict(X_test)\n","acc_1 = accuracy_score(y_test, y_pred_1)\n","print(f\"Akurasi Model 1 (Decision Tree): {acc_1 * 100:.2f}%\")\n","print(classification_report(y_test, y_pred_1))\n","print(\"-\" * 60)\n","\n","# Evaluasi Model 2 (Random Forest)\n","y_pred_2 = model_2.predict(X_test)\n","acc_2 = accuracy_score(y_test, y_pred_2)\n","print(f\"Akurasi Model 2 (Random Forest): {acc_2 * 100:.2f}%\")\n","print(classification_report(y_test, y_pred_2))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"hDiRPgx1KdY4","executionInfo":{"status":"ok","timestamp":1793973789556,"user_tz":-420,"elapsed":42,"user":{"displayName":"Elfan Cris","userId":"15481999268029990356"}},"outputId":"70ac9cfe-a29e-4d65-ff9c-4ff40d020d8a"},"execution_count":7,"outputs":[{"output_type":"stream","name":"stdout","text":["Akurasi Model 1 (Decision Tree): 65.49%\n"," precision recall f1-score support\n","\n"," rwi 0.59 0.60 0.59 381\n"," rwj 0.70 0.69 0.70 523\n","\n"," accuracy 0.65 904\n"," macro avg 0.65 0.65 0.65 904\n","weighted avg 0.66 0.65 0.66 904\n","\n","------------------------------------------------------------\n","Akurasi Model 2 (Random Forest): 74.12%\n"," precision recall f1-score support\n","\n"," rwi 0.71 0.64 0.68 381\n"," rwj 0.76 0.81 0.78 523\n","\n"," accuracy 0.74 904\n"," macro avg 0.74 0.73 0.73 904\n","weighted avg 0.74 0.74 0.74 904\n","\n"]}]}]} \ No newline at end of file