Skip to content

Commit d6b3b9e

Browse files
Add files via upload
1 parent ca721a1 commit d6b3b9e

File tree

8 files changed

+1787
-0
lines changed

8 files changed

+1787
-0
lines changed

notebooks/FederatedLearning/data/client_0/train_data.csv

Lines changed: 200 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/FederatedLearning/data/client_0/val_data.csv

Lines changed: 87 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/FederatedLearning/data/client_1/train_data.csv

Lines changed: 199 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/FederatedLearning/data/client_1/val_data.csv

Lines changed: 87 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/FederatedLearning/data/full_data.csv

Lines changed: 570 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/FederatedLearning/data/full_train_data.csv

Lines changed: 398 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/FederatedLearning/data/full_val_data.csv

Lines changed: 173 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 9,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"(397, 32)\n"
13+
]
14+
}
15+
],
16+
"source": [
17+
"import os\n",
18+
"import pandas as pd\n",
19+
"import numpy as np\n",
20+
"from sklearn.model_selection import train_test_split\n",
21+
"\n",
22+
"def split_dataframe(df, n=2):\n",
23+
" length = len(df)\n",
24+
" indices = np.array_split(range(length), n)\n",
25+
" return [df.iloc[index] for index in indices]\n",
26+
"\n",
27+
"df = pd.read_csv(\"full_data.csv\")\n",
28+
"split_dfs = split_dataframe(df)\n",
29+
"\n",
30+
"train_full = list()\n",
31+
"val_full = list()\n",
32+
"\n",
33+
"for i, part_df in enumerate(split_dfs):\n",
34+
" train, val = train_test_split(part_df, test_size=0.3)\n",
35+
" \n",
36+
" train_full.append(train)\n",
37+
" val_full.append(val)\n",
38+
"\n",
39+
" train.to_csv(os.path.join(f\"client_{i}\", \"train_data.csv\"), index=False)\n",
40+
" val.to_csv(os.path.join(f\"client_{i}\", \"val_data.csv\"), index=False)\n",
41+
" \n",
42+
"train_full_df = pd.concat(train_full)\n",
43+
"val_full_df = pd.concat(val_full)\n",
44+
"\n",
45+
"print(train_full_df.shape)\n",
46+
"\n",
47+
"train_full_df.to_csv(os.path.join(\"full_train_data.csv\"), index=False)\n",
48+
"val_full_df.to_csv(os.path.join(\"full_val_data.csv\"), index=False)"
49+
]
50+
}
51+
],
52+
"metadata": {
53+
"kernelspec": {
54+
"display_name": "fedavg",
55+
"language": "python",
56+
"name": "python3"
57+
},
58+
"language_info": {
59+
"codemirror_mode": {
60+
"name": "ipython",
61+
"version": 3
62+
},
63+
"file_extension": ".py",
64+
"mimetype": "text/x-python",
65+
"name": "python",
66+
"nbconvert_exporter": "python",
67+
"pygments_lexer": "ipython3",
68+
"version": "3.12.8"
69+
}
70+
},
71+
"nbformat": 4,
72+
"nbformat_minor": 2
73+
}

0 commit comments

Comments
 (0)