diff --git a/dashboard/__pycache__/overview.cpython-312.pyc b/dashboard/__pycache__/overview.cpython-312.pyc index 8f2f26704cc6e3bfa9550e84daca8bd42c99817e..321b88fb7c5348f1282cb7d830f742620755193b 100644 Binary files a/dashboard/__pycache__/overview.cpython-312.pyc and b/dashboard/__pycache__/overview.cpython-312.pyc differ diff --git a/dashboard/__pycache__/test_functions.cpython-312-pytest-7.4.4.pyc b/dashboard/__pycache__/test_functions.cpython-312-pytest-7.4.4.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7b251e8ae104625150abdd6fdcdb1aab1d7d6bf2 Binary files /dev/null and b/dashboard/__pycache__/test_functions.cpython-312-pytest-7.4.4.pyc differ diff --git a/dashboard/overview.py b/dashboard/overview.py index 53bedb6ccf9b492d412f8f27f420e605c7d9a2ec..4348d7562bc22eb897fb701c25576fe92ae3cd9f 100644 --- a/dashboard/overview.py +++ b/dashboard/overview.py @@ -18,9 +18,25 @@ def data_overview(): if dataset_choice == "Selected Features": st.subheader("Selected Features Dataset") st.dataframe(df_filtered) + + #option to download the datase + csv = df_filtered.to_csv(index=False).encode('utf-8') + st.download_button( + label="Download Selected Features CSV", + data=csv, + file_name='selected_features.csv', + mime='text/csv') else: st.subheader("Full Dataset") st.dataframe(df_full) + + csv = df_full.to_csv(index=False).encode('utf-8') + st.download_button( + label="Download Full Dataset CSV", + data=csv, + file_name='full_dataset.csv', + mime='text/csv') + st.subheader("Diagnosis Distribution") fig = plot_distribution(df_full) diff --git a/dashboard/svc_model.pkl b/dashboard/svc_model.pkl index 1211b96082066ce1860ec90dee3b7c028dedb81c..993875ad9624a1a5d5d9defc956661a4f656d2ae 100644 Binary files a/dashboard/svc_model.pkl and b/dashboard/svc_model.pkl differ diff --git a/dashboard/test_functions.py b/dashboard/test_functions.py new file mode 100644 index 0000000000000000000000000000000000000000..3bf110fb7216ba56c34a9509f147099760ae31b4 --- /dev/null +++ b/dashboard/test_functions.py @@ -0,0 +1,35 @@ +import pytest +import pandas as pd +from visuals import load_full_data, create_grouped_features, plot_distribution, plot_correlation_with_diagnosis + +# Test Data Loading +def test_load_full_data(): + df = load_full_data() + assert isinstance(df, pd.DataFrame) + assert not df.empty + assert "Diagnosis" in df.columns + +# Test Feature Grouping +def test_create_grouped_features(): + df = load_full_data() + grouped = create_grouped_features(df) + assert isinstance(grouped, dict) + assert "Cognitive" in grouped + assert isinstance(grouped["Cognitive"], pd.DataFrame) + +# Test Distribution Plotting +def test_plot_distribution_returns_figure(): + df = load_full_data() + fig = plot_distribution(df) + assert fig is not None + assert hasattr(fig, "savefig") + +# Test Correlation Plotting +def test_plot_correlation_with_diagnosis(): + df = load_full_data() + groups = create_grouped_features(df) + y = df["Diagnosis"] + group_df = groups["Clinical"] + fig = plot_correlation_with_diagnosis(group_df, y, "Clinical") + assert fig is not None + assert hasattr(fig, "savefig") diff --git a/models.ipynb b/models.ipynb index a8ee4d9fe10b4d070cc078142c15cf28135ab078..0b7a5e1a19eba599d2dd560f10e7966d43bd8e4b 100644 --- a/models.ipynb +++ b/models.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 161, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -20,12 +20,13 @@ "from sklearn.model_selection import cross_val_score, KFold\n", "from sklearn.svm import SVC\n", "from scipy.stats import randint\n", - "from sklearn.metrics import classification_report, confusion_matrix, accuracy_score" + "from sklearn.metrics import classification_report, confusion_matrix, accuracy_score\n", + "import pickle" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, "outputs": [ { @@ -156,7 +157,7 @@ "9 ['BehavioralProblems', 'DifficultyCompletingTa... " ] }, - "execution_count": 162, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -169,7 +170,7 @@ }, { "cell_type": "code", - "execution_count": 163, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -183,7 +184,7 @@ " 'MMSE']" ] }, - "execution_count": 163, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -197,7 +198,7 @@ }, { "cell_type": "code", - "execution_count": 164, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -583,7 +584,7 @@ "[2149 rows x 35 columns]" ] }, - "execution_count": 164, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -595,7 +596,7 @@ }, { "cell_type": "code", - "execution_count": 165, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -774,7 +775,7 @@ "[2149 rows x 7 columns]" ] }, - "execution_count": 165, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -787,7 +788,7 @@ }, { "cell_type": "code", - "execution_count": 166, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -835,7 +836,7 @@ }, { "cell_type": "code", - "execution_count": 167, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -865,7 +866,7 @@ }, { "cell_type": "code", - "execution_count": 168, + "execution_count": 29, "metadata": {}, "outputs": [ { @@ -902,7 +903,7 @@ }, { "cell_type": "code", - "execution_count": 169, + "execution_count": 30, "metadata": {}, "outputs": [], "source": [ @@ -926,7 +927,7 @@ }, { "cell_type": "code", - "execution_count": 170, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ @@ -970,7 +971,7 @@ }, { "cell_type": "code", - "execution_count": 171, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ @@ -999,7 +1000,7 @@ }, { "cell_type": "code", - "execution_count": 172, + "execution_count": 33, "metadata": {}, "outputs": [ { @@ -1143,7 +1144,7 @@ }, { "cell_type": "code", - "execution_count": 173, + "execution_count": 34, "metadata": {}, "outputs": [ { @@ -1202,7 +1203,7 @@ ], "source": [ "\n", - "modelsvc = SVC(kernel='rbf', gamma='auto', C=10)\n", + "modelsvc = SVC(kernel='rbf', gamma='auto', C=10, probability=True)\n", "modelsvc.fit(X_train_scaled, y_train)\n", "y_predsvc = modelsvc.predict(X_test_scaled)\n", "accuracysvc = accuracy_score(y_test, y_predsvc)\n", @@ -1281,7 +1282,7 @@ }, { "cell_type": "code", - "execution_count": 174, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -1419,7 +1420,7 @@ }, { "cell_type": "code", - "execution_count": 175, + "execution_count": 36, "metadata": {}, "outputs": [ { @@ -1432,7 +1433,7 @@ " 'F1-Score': [0.9531150398295376, 0.9273908901898491, 0.9461287249795657]}" ] }, - "execution_count": 175, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -1443,7 +1444,7 @@ }, { "cell_type": "code", - "execution_count": 176, + "execution_count": 37, "metadata": {}, "outputs": [ { @@ -1517,7 +1518,7 @@ }, { "cell_type": "code", - "execution_count": 177, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ @@ -1533,17 +1534,17 @@ }, { "cell_type": "code", - "execution_count": 178, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# import pickle\n", + "\n", "# # Save models\n", "# with open(\"rf_model.pkl\", \"wb\") as f:\n", "# pickle.dump(modelr, f)\n", "\n", - "# with open(\"svc_model.pkl\", \"wb\") as f:\n", - "# pickle.dump(modelsvc, f)\n", + "#with open(\"svc_model.pkl\", \"wb\") as f:\n", + " #pickle.dump(modelsvc, f)\n", "\n", "# with open(\"dt_model.pkl\", \"wb\") as f:\n", "# pickle.dump(modeld, f)\n" @@ -1551,7 +1552,7 @@ }, { "cell_type": "code", - "execution_count": 179, + "execution_count": 40, "metadata": {}, "outputs": [], "source": [ @@ -1562,7 +1563,7 @@ }, { "cell_type": "code", - "execution_count": 180, + "execution_count": 41, "metadata": {}, "outputs": [ { @@ -1575,7 +1576,7 @@ " 'F1-Score': [0.9531150398295376, 0.9273908901898491, 0.9461287249795657]}" ] }, - "execution_count": 180, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } diff --git a/requirements.txt b/requirements.txt index 74d8ac9b16aa965e7b59055cb4cc63dca78f3568..2def18ebde8b6d4042bca573997cf49b3994c58e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,5 @@ Pillow scikit-learn scipy deap +pytest +pickle