-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
301faf0
commit 680acac
Showing
21 changed files
with
109,279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# pdm | ||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
#pdm.lock | ||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
# in version control. | ||
# https://pdm.fming.dev/#use-with-ide | ||
.pdm.toml | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
#.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"from sklearn.model_selection import train_test_split\n", | ||
"df_train, df_temp = train_test_split(df, test_size=split_size, shuffle=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"from sklearn.model_selection import train_test_split\n", | ||
"\n", | ||
"# Load your DataFrame (replace 'your_data.csv' with your actual data file)\n", | ||
"df = pd.read_csv('train.csv')\n", | ||
"\n", | ||
"# Split the DataFrame into 5 random parts\n", | ||
"num_splits = 3\n", | ||
"split_size = 1.0 / num_splits\n", | ||
"\n", | ||
"# Create empty lists to store the splits\n", | ||
"# data_splits = []\n", | ||
"\n", | ||
"# Loop to create 5 random splits\n", | ||
"for i in range(num_splits):\n", | ||
" # Split the data into a training set and a temporary set (remaining data)\n", | ||
" df_train, df_temp = train_test_split(df, test_size=split_size, shuffle=True)\n", | ||
" \n", | ||
" # Append the training set to the list of splits\n", | ||
" # data_splits.append(df_train)\n", | ||
" df_train.to_csv(f'train_split{i}.csv', index=False)\n", | ||
" \n", | ||
" # Update df to the remaining data for the next iteration\n", | ||
" df = df_temp\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "env", | ||
"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.11.4" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import warnings | ||
import flwr as fl | ||
import pandas as pd | ||
from sklearn.model_selection import train_test_split | ||
from sklearn.linear_model import LogisticRegression | ||
from sklearn.metrics import log_loss | ||
import os | ||
import flwr as fl | ||
import tensorflow as tf | ||
import keras | ||
import numpy as np | ||
from sklearn.metrics import accuracy_score | ||
import utils | ||
|
||
import warnings | ||
warnings.filterwarnings("ignore") | ||
if __name__ == "__main__": | ||
df_train=pd.read_csv("train_split0.csv",encoding='utf-8') | ||
# X, y = utils.preprocess(df_train) | ||
x_subclass, y_subclass = utils.preprocess(df_train) | ||
X_train, X_test, y_train, y_test = train_test_split(x_subclass, y_subclass, test_size=0.1) | ||
# Make TensorFlow log less verbose | ||
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" | ||
|
||
model3 = keras.Sequential() | ||
model3.add(keras.layers.Dense(100, input_dim = 26, activation = 'relu')) | ||
model3.add(keras.layers.Dense(48, activation = 'relu')) | ||
model3.add(keras.layers.Dense(16, activation = 'relu')) | ||
model3.add(keras.layers.Dense(8, activation = 'relu')) | ||
model3.add(keras.layers.Dense(9, activation = "softmax")) | ||
|
||
model3.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy', 'Precision', 'Recall']) | ||
|
||
epochs = 100 | ||
batch_size = 25 | ||
|
||
|
||
# Define Flower client | ||
class HospitalClient(fl.client.NumPyClient): | ||
def get_parameters(self, config): | ||
return model3.get_weights() | ||
|
||
def fit(self, parameters, config): | ||
model3.set_weights(parameters) | ||
model3.fit(X_train, y_train, epochs=epochs, batch_size=batch_size, validation_split=0.1, shuffle=True) | ||
return model3.get_weights(), len(X_train), {} | ||
|
||
# def evaluate(self, parameters, config): | ||
# model3.set_weights(parameters) | ||
# loss, accuracy, _, _ = model3.evaluate(X_test, y_test) | ||
# print(f"accuracy of test: {accuracy} ") | ||
# return loss, len(X_test), {"accuracy": accuracy} | ||
def evaluate(self, parameters, config): | ||
model3.set_weights(parameters) | ||
y = model3.predict(X_test) | ||
predicted_labels = np.argmax(y, axis=1) | ||
true_labels = np.argmax(y_test, axis=1) | ||
accuracy = accuracy_score(true_labels, predicted_labels) | ||
# loss = log_loss(true_labels, y) | ||
loss, _, _, _ = model3.evaluate(X_test, y_test) | ||
print(f"accuracy of test: {accuracy} ") | ||
return loss, len(X_test), {"accuracy": accuracy} | ||
|
||
|
||
# Start Flower client | ||
fl.client.start_numpy_client(server_address="localhost:3000", client=HospitalClient()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
import warnings | ||
import flwr as fl | ||
import pandas as pd | ||
from sklearn.model_selection import train_test_split | ||
from sklearn.linear_model import LogisticRegression | ||
from sklearn.metrics import log_loss | ||
import os | ||
import flwr as fl | ||
import tensorflow as tf | ||
import keras | ||
from sklearn.metrics import accuracy_score | ||
import numpy as np | ||
|
||
|
||
import utils | ||
|
||
import warnings | ||
warnings.filterwarnings("ignore") | ||
if __name__ == "__main__": | ||
df_train=pd.read_csv("train_split1.csv",encoding='utf-8') | ||
# X, y = utils.preprocess(df_train) | ||
x_subclass, y_subclass = utils.preprocess(df_train) | ||
X_train, X_test, y_train, y_test = train_test_split(x_subclass, y_subclass, test_size=0.1) | ||
# Make TensorFlow log less verbose | ||
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" | ||
|
||
model3 = keras.Sequential() | ||
model3.add(keras.layers.Dense(100, input_dim = 26, activation = 'relu')) | ||
model3.add(keras.layers.Dense(48, activation = 'relu')) | ||
model3.add(keras.layers.Dense(16, activation = 'relu')) | ||
model3.add(keras.layers.Dense(8, activation = 'relu')) | ||
model3.add(keras.layers.Dense(9, activation = "softmax")) | ||
|
||
model3.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy', 'Precision', 'Recall']) | ||
|
||
epochs = 100 | ||
batch_size = 25 | ||
|
||
|
||
# Define Flower client | ||
class HospitalClient(fl.client.NumPyClient): | ||
def get_parameters(self, config): | ||
return model3.get_weights() | ||
|
||
def fit(self, parameters, config): | ||
model3.set_weights(parameters) | ||
model3.fit(X_train, y_train, epochs=epochs, batch_size=batch_size, validation_split=0.1, shuffle=True) | ||
return model3.get_weights(), len(X_train), {} | ||
|
||
def evaluate(self, parameters, config): | ||
model3.set_weights(parameters) | ||
y = model3.predict(X_test) | ||
predicted_labels = np.argmax(y, axis=1) | ||
true_labels = np.argmax(y_test, axis=1) | ||
accuracy = accuracy_score(true_labels, predicted_labels) | ||
# loss = log_loss(true_labels, y) | ||
loss, _, _, _ = model3.evaluate(X_test, y_test) | ||
print(f"accuracy of test: {accuracy} ") | ||
return loss, len(X_test), {"accuracy": accuracy} | ||
|
||
|
||
# Start Flower client | ||
fl.client.start_numpy_client(server_address="localhost:3000", client=HospitalClient()) |
Oops, something went wrong.