Regression.ipynb 60.2 KB
Newer Older
Billy Amélie's avatar
Billy Amélie committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "import matplotlib.pyplot as plt\n",
    "import os\n",
    "from pathlib import Path\n",
    "from sklearn.model_selection import KFold\n",
    "from sklearn.metrics import mean_absolute_error"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "input_directory='../osic-pulmonary-fibrosis-progression'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Patient</th>\n",
       "      <th>Weeks</th>\n",
       "      <th>FVC</th>\n",
       "      <th>Percent</th>\n",
       "      <th>Age</th>\n",
       "      <th>Sex</th>\n",
       "      <th>SmokingStatus</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ID00007637202177411956430</td>\n",
       "      <td>-4</td>\n",
       "      <td>2315</td>\n",
       "      <td>58.253649</td>\n",
       "      <td>79</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ID00007637202177411956430</td>\n",
       "      <td>5</td>\n",
       "      <td>2214</td>\n",
       "      <td>55.712129</td>\n",
       "      <td>79</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ID00007637202177411956430</td>\n",
       "      <td>7</td>\n",
       "      <td>2061</td>\n",
       "      <td>51.862104</td>\n",
       "      <td>79</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ID00007637202177411956430</td>\n",
       "      <td>9</td>\n",
       "      <td>2144</td>\n",
       "      <td>53.950679</td>\n",
       "      <td>79</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ID00007637202177411956430</td>\n",
       "      <td>11</td>\n",
       "      <td>2069</td>\n",
       "      <td>52.063412</td>\n",
       "      <td>79</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     Patient  Weeks   FVC    Percent  Age   Sex SmokingStatus\n",
       "0  ID00007637202177411956430     -4  2315  58.253649   79  Male     Ex-smoker\n",
       "1  ID00007637202177411956430      5  2214  55.712129   79  Male     Ex-smoker\n",
       "2  ID00007637202177411956430      7  2061  51.862104   79  Male     Ex-smoker\n",
       "3  ID00007637202177411956430      9  2144  53.950679   79  Male     Ex-smoker\n",
       "4  ID00007637202177411956430     11  2069  52.063412   79  Male     Ex-smoker"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Reading data\n",
    "test_df = pd.read_csv(f'{input_directory}/test.csv')\n",
    "sample_sub= pd.read_csv(f'{input_directory}/sample_submission.csv')\n",
    "train_df= pd.read_csv(f'{input_directory}/train.csv')\n",
    "train_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "patients_train_ids= train_df.Patient.unique()\n",
    "patient_test_list= test_df.Patient.unique()\n",
    "list_p = train_df.Patient.isin( patient_test_list )\n",
    "patients_train_ids = [pat for pat in patients_train_ids if not pat in list_p]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Female', 'Male']\n"
     ]
    }
   ],
   "source": [
    "le = LabelEncoder()\n",
    "le.fit(train_df['Sex'])\n",
    "print(list(le.classes_))\n",
    "train_df['Sex']=le.transform(train_df['Sex'])\n",
    "test_df['Sex']=le.transform(test_df['Sex'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Currently smokes', 'Ex-smoker', 'Never smoked']\n"
     ]
    }
   ],
   "source": [
    "le = LabelEncoder()\n",
    "le.fit(train_df['SmokingStatus'])\n",
    "print(list(le.classes_))\n",
    "train_df['SmokingStatus']=le.transform(train_df['SmokingStatus'])\n",
    "test_df['SmokingStatus']=le.transform(test_df['SmokingStatus'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# new dataframe with one row per patient for training\n",
    "\n",
    "train_data = []\n",
    "\n",
    "\n",
    "for patient in patients_train_ids :  \n",
    "    \n",
    "    #select all data related to a patient\n",
    "    patientData  = train_df[train_df['Patient'] == patient]\n",
    "    # save first measurements\n",
    "    firstMeasure = list(patientData.iloc[0, :].values)\n",
    "    \n",
    "    #for ech measurement, add fist measurement and duration since first measurement\n",
    "    for i, week in enumerate(patientData['Weeks'].iloc[1:]):\n",
    "        fvc, fvc_pctg = patientData.iloc[i, 2], patientData.iloc[i, 3]\n",
    "        trainDataPoint = firstMeasure + [week, fvc]\n",
    "        train_data.append(trainDataPoint)\n",
    "    \n",
    "    \n",
    "training_df = pd.DataFrame(train_data)\n",
    "training_df.columns = ['PatientID', 'First_week', 'First_FVC', 'First_Percent', 'Age', 'Sex', 'SmokingStatus'] + ['target_week', 'Target_FVC']\n",
    "training_df['Delta_week'] = training_df['target_week'] - training_df['First_week']\n",
    "\n",
    "#rearrange columns\n",
    "training_df = training_df[['PatientID','Age','Sex','SmokingStatus', 'First_FVC', 'First_Percent','Delta_week','Target_FVC']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PatientID</th>\n",
       "      <th>Age</th>\n",
       "      <th>Sex</th>\n",
       "      <th>SmokingStatus</th>\n",
       "      <th>First_FVC</th>\n",
       "      <th>First_Percent</th>\n",
       "      <th>Delta_week</th>\n",
       "      <th>Target_FVC</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ID00007637202177411956430</td>\n",
       "      <td>79</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2315</td>\n",
       "      <td>58.253649</td>\n",
       "      <td>9</td>\n",
       "      <td>2315</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ID00007637202177411956430</td>\n",
       "      <td>79</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2315</td>\n",
       "      <td>58.253649</td>\n",
       "      <td>11</td>\n",
       "      <td>2214</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ID00007637202177411956430</td>\n",
       "      <td>79</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2315</td>\n",
       "      <td>58.253649</td>\n",
       "      <td>13</td>\n",
       "      <td>2061</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ID00007637202177411956430</td>\n",
       "      <td>79</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2315</td>\n",
       "      <td>58.253649</td>\n",
       "      <td>15</td>\n",
       "      <td>2144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ID00007637202177411956430</td>\n",
       "      <td>79</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2315</td>\n",
       "      <td>58.253649</td>\n",
       "      <td>21</td>\n",
       "      <td>2069</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1368</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>73</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2925</td>\n",
       "      <td>71.824968</td>\n",
       "      <td>13</td>\n",
       "      <td>2976</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1369</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>73</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2925</td>\n",
       "      <td>71.824968</td>\n",
       "      <td>19</td>\n",
       "      <td>2712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1370</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>73</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2925</td>\n",
       "      <td>71.824968</td>\n",
       "      <td>31</td>\n",
       "      <td>2978</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1371</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>73</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2925</td>\n",
       "      <td>71.824968</td>\n",
       "      <td>43</td>\n",
       "      <td>2908</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1372</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>73</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2925</td>\n",
       "      <td>71.824968</td>\n",
       "      <td>59</td>\n",
       "      <td>2975</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1373 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                      PatientID  Age  Sex  SmokingStatus  First_FVC  \\\n",
       "0     ID00007637202177411956430   79    1              1       2315   \n",
       "1     ID00007637202177411956430   79    1              1       2315   \n",
       "2     ID00007637202177411956430   79    1              1       2315   \n",
       "3     ID00007637202177411956430   79    1              1       2315   \n",
       "4     ID00007637202177411956430   79    1              1       2315   \n",
       "...                         ...  ...  ...            ...        ...   \n",
       "1368  ID00426637202313170790466   73    1              2       2925   \n",
       "1369  ID00426637202313170790466   73    1              2       2925   \n",
       "1370  ID00426637202313170790466   73    1              2       2925   \n",
       "1371  ID00426637202313170790466   73    1              2       2925   \n",
       "1372  ID00426637202313170790466   73    1              2       2925   \n",
       "\n",
       "      First_Percent  Delta_week  Target_FVC  \n",
       "0         58.253649           9        2315  \n",
       "1         58.253649          11        2214  \n",
       "2         58.253649          13        2061  \n",
       "3         58.253649          15        2144  \n",
       "4         58.253649          21        2069  \n",
       "...             ...         ...         ...  \n",
       "1368      71.824968          13        2976  \n",
       "1369      71.824968          19        2712  \n",
       "1370      71.824968          31        2978  \n",
       "1371      71.824968          43        2908  \n",
       "1372      71.824968          59        2975  \n",
       "\n",
       "[1373 rows x 8 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "training_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Patient_Week</th>\n",
       "      <th>FVC</th>\n",
       "      <th>Confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ID00419637202311204720264_-12</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ID00421637202311550012437_-12</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ID00422637202311677017371_-12</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ID00423637202312137826377_-12</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ID00426637202313170790466_-12</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>705</th>\n",
       "      <td>ID00419637202311204720264_129</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>706</th>\n",
       "      <td>ID00421637202311550012437_129</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>707</th>\n",
       "      <td>ID00422637202311677017371_129</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>708</th>\n",
       "      <td>ID00423637202312137826377_129</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709</th>\n",
       "      <td>ID00426637202313170790466_129</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>710 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                      Patient_Week   FVC  Confidence\n",
       "0    ID00419637202311204720264_-12  2000         100\n",
       "1    ID00421637202311550012437_-12  2000         100\n",
       "2    ID00422637202311677017371_-12  2000         100\n",
       "3    ID00423637202312137826377_-12  2000         100\n",
       "4    ID00426637202313170790466_-12  2000         100\n",
       "..                             ...   ...         ...\n",
       "705  ID00419637202311204720264_129  2000         100\n",
       "706  ID00421637202311550012437_129  2000         100\n",
       "707  ID00422637202311677017371_129  2000         100\n",
       "708  ID00423637202312137826377_129  2000         100\n",
       "709  ID00426637202313170790466_129  2000         100\n",
       "\n",
       "[710 rows x 3 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sample_sub.head(-20) #How the result must look like "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "sample_sub[['Patient','Week']] = sample_sub['Patient_Week'].str.split('_',expand=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Patient_Week</th>\n",
       "      <th>FVC</th>\n",
       "      <th>Confidence</th>\n",
       "      <th>Patient</th>\n",
       "      <th>Week</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ID00419637202311204720264_-12</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ID00421637202311550012437_-12</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "      <td>ID00421637202311550012437</td>\n",
       "      <td>-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ID00422637202311677017371_-12</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "      <td>ID00422637202311677017371</td>\n",
       "      <td>-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ID00423637202312137826377_-12</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "      <td>ID00423637202312137826377</td>\n",
       "      <td>-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ID00426637202313170790466_-12</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>722</th>\n",
       "      <td>ID00422637202311677017371_132</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "      <td>ID00422637202311677017371</td>\n",
       "      <td>132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>723</th>\n",
       "      <td>ID00423637202312137826377_132</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "      <td>ID00423637202312137826377</td>\n",
       "      <td>132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>724</th>\n",
       "      <td>ID00426637202313170790466_132</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>725</th>\n",
       "      <td>ID00419637202311204720264_133</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>133</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>726</th>\n",
       "      <td>ID00421637202311550012437_133</td>\n",
       "      <td>2000</td>\n",
       "      <td>100</td>\n",
       "      <td>ID00421637202311550012437</td>\n",
       "      <td>133</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>727 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                      Patient_Week   FVC  Confidence  \\\n",
       "0    ID00419637202311204720264_-12  2000         100   \n",
       "1    ID00421637202311550012437_-12  2000         100   \n",
       "2    ID00422637202311677017371_-12  2000         100   \n",
       "3    ID00423637202312137826377_-12  2000         100   \n",
       "4    ID00426637202313170790466_-12  2000         100   \n",
       "..                             ...   ...         ...   \n",
       "722  ID00422637202311677017371_132  2000         100   \n",
       "723  ID00423637202312137826377_132  2000         100   \n",
       "724  ID00426637202313170790466_132  2000         100   \n",
       "725  ID00419637202311204720264_133  2000         100   \n",
       "726  ID00421637202311550012437_133  2000         100   \n",
       "\n",
       "                       Patient Week  \n",
       "0    ID00419637202311204720264  -12  \n",
       "1    ID00421637202311550012437  -12  \n",
       "2    ID00422637202311677017371  -12  \n",
       "3    ID00423637202312137826377  -12  \n",
       "4    ID00426637202313170790466  -12  \n",
       "..                         ...  ...  \n",
       "722  ID00422637202311677017371  132  \n",
       "723  ID00423637202312137826377  132  \n",
       "724  ID00426637202313170790466  132  \n",
       "725  ID00419637202311204720264  133  \n",
       "726  ID00421637202311550012437  133  \n",
       "\n",
       "[727 rows x 5 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sample_sub.head(-3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Patient</th>\n",
       "      <th>Weeks</th>\n",
       "      <th>FVC</th>\n",
       "      <th>Percent</th>\n",
       "      <th>Age</th>\n",
       "      <th>Sex</th>\n",
       "      <th>SmokingStatus</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>6</td>\n",
       "      <td>3020</td>\n",
       "      <td>70.186855</td>\n",
       "      <td>73</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ID00421637202311550012437</td>\n",
       "      <td>15</td>\n",
       "      <td>2739</td>\n",
       "      <td>82.045291</td>\n",
       "      <td>68</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ID00422637202311677017371</td>\n",
       "      <td>6</td>\n",
       "      <td>1930</td>\n",
       "      <td>76.672493</td>\n",
       "      <td>73</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ID00423637202312137826377</td>\n",
       "      <td>17</td>\n",
       "      <td>3294</td>\n",
       "      <td>79.258903</td>\n",
       "      <td>72</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>0</td>\n",
       "      <td>2925</td>\n",
       "      <td>71.824968</td>\n",
       "      <td>73</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     Patient  Weeks   FVC    Percent  Age  Sex  SmokingStatus\n",
       "0  ID00419637202311204720264      6  3020  70.186855   73    1              1\n",
       "1  ID00421637202311550012437     15  2739  82.045291   68    1              1\n",
       "2  ID00422637202311677017371      6  1930  76.672493   73    1              1\n",
       "3  ID00423637202312137826377     17  3294  79.258903   72    1              1\n",
       "4  ID00426637202313170790466      0  2925  71.824968   73    1              2"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "p= patient_test_list[0]\n",
    "patientData = test_df[test_df['Patient'] == p]\n",
    "firstMeasure = list(patientData.iloc[0, :].values)\n",
    "s_patient = sample_sub[sample_sub['Patient']==p]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will preduct, for each patient the test set, their FVC for the weeks that are in the sample set for them (this is a requirement from the competition):\n",
    "\n",
    "\"For each Patient_Week from the submission file, you must predict the FVC and a confidence\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "# create testing data\n",
    "\n",
    "testData = []\n",
    "\n",
    "for p in patient_test_list:\n",
    "    \n",
    "    patientData = test_df[test_df['Patient'] == p]\n",
    "    firstMeasure = list(patientData.iloc[0, :].values)\n",
    "    s_patient = sample_sub[sample_sub['Patient']==p]\n",
    "    allweeks= s_patient['Week'].tolist()\n",
    "    for week in allweeks:\n",
    "        testDataPoint = firstMeasure + [week]\n",
    "        testData.append(testDataPoint)\n",
    "testData = pd.DataFrame(testData)\n",
    "testData.columns = ['PatientID', 'first_week', 'First_FVC', 'First_Percent', 'Age', 'Sex', 'SmokingStatus'] + ['Target_week']\n",
    "\n",
    "testData['Delta_week'] = testData['Target_week'].map(int) - testData['first_week']\n",
    "\n",
    "#Rearange\n",
    "testData = testData[['PatientID','Age','Sex','SmokingStatus', 'First_FVC', 'First_Percent','Delta_week','Target_week']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PatientID</th>\n",
       "      <th>Age</th>\n",
       "      <th>Sex</th>\n",
       "      <th>SmokingStatus</th>\n",
       "      <th>First_FVC</th>\n",
       "      <th>First_Percent</th>\n",
       "      <th>Delta_week</th>\n",
       "      <th>Target_week</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>73</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3020</td>\n",
       "      <td>70.186855</td>\n",
       "      <td>-18</td>\n",
       "      <td>-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>73</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3020</td>\n",
       "      <td>70.186855</td>\n",
       "      <td>-17</td>\n",
       "      <td>-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>73</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3020</td>\n",
       "      <td>70.186855</td>\n",
       "      <td>-16</td>\n",
       "      <td>-10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   PatientID  Age  Sex  SmokingStatus  First_FVC  \\\n",
       "0  ID00419637202311204720264   73    1              1       3020   \n",
       "1  ID00419637202311204720264   73    1              1       3020   \n",
       "2  ID00419637202311204720264   73    1              1       3020   \n",
       "\n",
       "   First_Percent  Delta_week Target_week  \n",
       "0      70.186855         -18         -12  \n",
       "1      70.186855         -17         -11  \n",
       "2      70.186855         -16         -10  "
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "testData.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Training accuracy: 0.9414634426681496\n"
     ]
    }
   ],
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "from sklearn.neighbors import KNeighborsRegressor\n",
    "\n",
    "model = LinearRegression()\n",
    "model.fit(training_df.drop(columns = ['PatientID', 'Target_FVC']), training_df['Target_FVC'])\n",
    "print('Training accuracy:',model.score(training_df.drop(columns = ['PatientID', 'Target_FVC']), training_df['Target_FVC']))\n",
    "\n",
    "prediction_test = model.predict(testData.drop(columns = ['PatientID','Target_week']))\n",
    "prediction_train =model.predict(training_df.drop(columns = ['PatientID', 'Target_FVC']))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Evaluation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This competition is evaluated on a modified version of the Laplace Log Likelihood. In medical applications, it is useful to evaluate a model's confidence in its decisions. Accordingly, the metric is designed to reflect both the accuracy and certainty of each prediction.For each true FVC measurement, you will predict both an FVC and a confidence measure (standard deviation $\\sigma$). The metric is computed as:\n",
    "\n",
    "$\\sigma_{clipped} = max(\\sigma, 70)$,\n",
    "\n",
    "\n",
    "$\\Delta = min ( |FVC_{true} - FVC_{predicted}|, 1000 )$\n",
    "\n",
    "$metric = -   \\frac{\\sqrt{2} \\Delta}{\\sigma_{clipped}} - \\ln ( \\sqrt{2} \\sigma_{clipped} )$\n",
    "\n",
    "The final score is calculated by averaging the metric across all test set Patient_Weeks (three per patient). Note that metric values will be negative and higher is better.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "\n",
    "def score(y_true, y_pred):\n",
    "    sigma = ( y_true - y_pred ) #########\n",
    "    fvc_pred = y_pred    \n",
    "    sigma_clip = np.maximum(sigma, 70)    \n",
    "    delta = np.minimum(abs(y_true - fvc_pred),1000)\n",
    "    sq2 = math.sqrt(2)\n",
    "    metric = -(delta / sigma_clip)*sq2 - np.log(sigma_clip* sq2)\n",
    "    return (sigma, np.mean(metric))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-6.730931933436616\n"
     ]
    }
   ],
   "source": [
    "conf,score = score(prediction_train,training_df['Target_FVC'])\n",
    "print(score)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "sub = []\n",
    "for i in range(testData.shape[0]):\n",
    "    patient, week, pred = testData.loc[i, 'PatientID'], testData.loc[i, 'Target_week'], prediction_test[i]\n",
    "    confidence = 0  #TBD\n",
    "    sub.append([patient + '_' + str(week), pred, confidence])\n",
    "    \n",
    "sub = pd.DataFrame(sub)\n",
    "sub.columns = ['Patient_Week', 'FVC', 'Confidence']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "patient_test_list = patient_test_list.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Patient</th>\n",
       "      <th>Weeks</th>\n",
       "      <th>FVC</th>\n",
       "      <th>Percent</th>\n",
       "      <th>Age</th>\n",
       "      <th>Sex</th>\n",
       "      <th>SmokingStatus</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1504</th>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>6</td>\n",
       "      <td>3020</td>\n",
       "      <td>70.186855</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1505</th>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>7</td>\n",
       "      <td>2859</td>\n",
       "      <td>66.445106</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1506</th>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>9</td>\n",
       "      <td>2783</td>\n",
       "      <td>64.678814</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1507</th>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>10</td>\n",
       "      <td>2719</td>\n",
       "      <td>63.191410</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1508</th>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>13</td>\n",
       "      <td>2738</td>\n",
       "      <td>63.632983</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1509</th>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>18</td>\n",
       "      <td>2694</td>\n",
       "      <td>62.610393</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1510</th>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>31</td>\n",
       "      <td>2708</td>\n",
       "      <td>62.935763</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1511</th>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>43</td>\n",
       "      <td>2793</td>\n",
       "      <td>64.911221</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1512</th>\n",
       "      <td>ID00419637202311204720264</td>\n",
       "      <td>59</td>\n",
       "      <td>2727</td>\n",
       "      <td>63.377336</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1513</th>\n",
       "      <td>ID00421637202311550012437</td>\n",
       "      <td>15</td>\n",
       "      <td>2739</td>\n",
       "      <td>82.045291</td>\n",
       "      <td>68</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1514</th>\n",
       "      <td>ID00421637202311550012437</td>\n",
       "      <td>17</td>\n",
       "      <td>2756</td>\n",
       "      <td>82.554517</td>\n",
       "      <td>68</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1515</th>\n",
       "      <td>ID00421637202311550012437</td>\n",
       "      <td>19</td>\n",
       "      <td>2755</td>\n",
       "      <td>82.524563</td>\n",
       "      <td>68</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1516</th>\n",
       "      <td>ID00421637202311550012437</td>\n",
       "      <td>21</td>\n",
       "      <td>2820</td>\n",
       "      <td>84.471603</td>\n",
       "      <td>68</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1517</th>\n",
       "      <td>ID00421637202311550012437</td>\n",
       "      <td>23</td>\n",
       "      <td>2853</td>\n",
       "      <td>85.460101</td>\n",
       "      <td>68</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1518</th>\n",
       "      <td>ID00421637202311550012437</td>\n",
       "      <td>29</td>\n",
       "      <td>2716</td>\n",
       "      <td>81.356338</td>\n",
       "      <td>68</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1519</th>\n",
       "      <td>ID00421637202311550012437</td>\n",
       "      <td>41</td>\n",
       "      <td>2833</td>\n",
       "      <td>84.861011</td>\n",
       "      <td>68</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1520</th>\n",
       "      <td>ID00421637202311550012437</td>\n",
       "      <td>54</td>\n",
       "      <td>2771</td>\n",
       "      <td>83.003834</td>\n",
       "      <td>68</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1521</th>\n",
       "      <td>ID00421637202311550012437</td>\n",
       "      <td>70</td>\n",
       "      <td>2628</td>\n",
       "      <td>78.720345</td>\n",
       "      <td>68</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1522</th>\n",
       "      <td>ID00421637202311550012437</td>\n",
       "      <td>70</td>\n",
       "      <td>2719</td>\n",
       "      <td>81.446202</td>\n",
       "      <td>68</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1523</th>\n",
       "      <td>ID00422637202311677017371</td>\n",
       "      <td>6</td>\n",
       "      <td>1930</td>\n",
       "      <td>76.672493</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1524</th>\n",
       "      <td>ID00422637202311677017371</td>\n",
       "      <td>11</td>\n",
       "      <td>1936</td>\n",
       "      <td>76.910853</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1525</th>\n",
       "      <td>ID00422637202311677017371</td>\n",
       "      <td>13</td>\n",
       "      <td>1955</td>\n",
       "      <td>77.665660</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1526</th>\n",
       "      <td>ID00422637202311677017371</td>\n",
       "      <td>15</td>\n",
       "      <td>1848</td>\n",
       "      <td>73.414905</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1527</th>\n",
       "      <td>ID00422637202311677017371</td>\n",
       "      <td>17</td>\n",
       "      <td>1897</td>\n",
       "      <td>75.361513</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1528</th>\n",
       "      <td>ID00422637202311677017371</td>\n",
       "      <td>23</td>\n",
       "      <td>1946</td>\n",
       "      <td>77.308120</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1529</th>\n",
       "      <td>ID00422637202311677017371</td>\n",
       "      <td>35</td>\n",
       "      <td>1862</td>\n",
       "      <td>73.971079</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1530</th>\n",
       "      <td>ID00422637202311677017371</td>\n",
       "      <td>47</td>\n",
       "      <td>1713</td>\n",
       "      <td>68.051804</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1531</th>\n",
       "      <td>ID00423637202312137826377</td>\n",
       "      <td>17</td>\n",
       "      <td>3294</td>\n",
       "      <td>79.258903</td>\n",
       "      <td>72</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1532</th>\n",
       "      <td>ID00423637202312137826377</td>\n",
       "      <td>18</td>\n",
       "      <td>2777</td>\n",
       "      <td>66.819057</td>\n",
       "      <td>72</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1533</th>\n",
       "      <td>ID00423637202312137826377</td>\n",
       "      <td>19</td>\n",
       "      <td>2700</td>\n",
       "      <td>64.966314</td>\n",
       "      <td>72</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1534</th>\n",
       "      <td>ID00423637202312137826377</td>\n",
       "      <td>21</td>\n",
       "      <td>3014</td>\n",
       "      <td>72.521655</td>\n",
       "      <td>72</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1535</th>\n",
       "      <td>ID00423637202312137826377</td>\n",
       "      <td>23</td>\n",
       "      <td>2661</td>\n",
       "      <td>64.027911</td>\n",
       "      <td>72</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1536</th>\n",
       "      <td>ID00423637202312137826377</td>\n",
       "      <td>30</td>\n",
       "      <td>2778</td>\n",
       "      <td>66.843118</td>\n",
       "      <td>72</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1537</th>\n",
       "      <td>ID00423637202312137826377</td>\n",
       "      <td>42</td>\n",
       "      <td>2516</td>\n",
       "      <td>60.538980</td>\n",
       "      <td>72</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1538</th>\n",
       "      <td>ID00423637202312137826377</td>\n",
       "      <td>53</td>\n",
       "      <td>2432</td>\n",
       "      <td>58.517806</td>\n",
       "      <td>72</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1539</th>\n",
       "      <td>ID00423637202312137826377</td>\n",
       "      <td>70</td>\n",
       "      <td>2578</td>\n",
       "      <td>62.030799</td>\n",
       "      <td>72</td>\n",
       "      <td>Male</td>\n",
       "      <td>Ex-smoker</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1540</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>0</td>\n",
       "      <td>2925</td>\n",
       "      <td>71.824968</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Never smoked</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1541</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>7</td>\n",
       "      <td>2903</td>\n",
       "      <td>71.284746</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Never smoked</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1542</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>9</td>\n",
       "      <td>2916</td>\n",
       "      <td>71.603968</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Never smoked</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1543</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>11</td>\n",
       "      <td>2976</td>\n",
       "      <td>73.077301</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Never smoked</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1544</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>13</td>\n",
       "      <td>2712</td>\n",
       "      <td>66.594637</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Never smoked</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1545</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>19</td>\n",
       "      <td>2978</td>\n",
       "      <td>73.126412</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Never smoked</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1546</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>31</td>\n",
       "      <td>2908</td>\n",
       "      <td>71.407524</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Never smoked</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1547</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>43</td>\n",
       "      <td>2975</td>\n",
       "      <td>73.052745</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Never smoked</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1548</th>\n",
       "      <td>ID00426637202313170790466</td>\n",
       "      <td>59</td>\n",
       "      <td>2774</td>\n",
       "      <td>68.117081</td>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>Never smoked</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        Patient  Weeks   FVC    Percent  Age   Sex  \\\n",
       "1504  ID00419637202311204720264      6  3020  70.186855   73  Male   \n",
       "1505  ID00419637202311204720264      7  2859  66.445106   73  Male   \n",
       "1506  ID00419637202311204720264      9  2783  64.678814   73  Male   \n",
       "1507  ID00419637202311204720264     10  2719  63.191410   73  Male   \n",
       "1508  ID00419637202311204720264     13  2738  63.632983   73  Male   \n",
       "1509  ID00419637202311204720264     18  2694  62.610393   73  Male   \n",
       "1510  ID00419637202311204720264     31  2708  62.935763   73  Male   \n",
       "1511  ID00419637202311204720264     43  2793  64.911221   73  Male   \n",
       "1512  ID00419637202311204720264     59  2727  63.377336   73  Male   \n",
       "1513  ID00421637202311550012437     15  2739  82.045291   68  Male   \n",
       "1514  ID00421637202311550012437     17  2756  82.554517   68  Male   \n",
       "1515  ID00421637202311550012437     19  2755  82.524563   68  Male   \n",
       "1516  ID00421637202311550012437     21  2820  84.471603   68  Male   \n",
       "1517  ID00421637202311550012437     23  2853  85.460101   68  Male   \n",
       "1518  ID00421637202311550012437     29  2716  81.356338   68  Male   \n",
       "1519  ID00421637202311550012437     41  2833  84.861011   68  Male   \n",
       "1520  ID00421637202311550012437     54  2771  83.003834   68  Male   \n",
       "1521  ID00421637202311550012437     70  2628  78.720345   68  Male   \n",
       "1522  ID00421637202311550012437     70  2719  81.446202   68  Male   \n",
       "1523  ID00422637202311677017371      6  1930  76.672493   73  Male   \n",
       "1524  ID00422637202311677017371     11  1936  76.910853   73  Male   \n",
       "1525  ID00422637202311677017371     13  1955  77.665660   73  Male   \n",
       "1526  ID00422637202311677017371     15  1848  73.414905   73  Male   \n",
       "1527  ID00422637202311677017371     17  1897  75.361513   73  Male   \n",
       "1528  ID00422637202311677017371     23  1946  77.308120   73  Male   \n",
       "1529  ID00422637202311677017371     35  1862  73.971079   73  Male   \n",
       "1530  ID00422637202311677017371     47  1713  68.051804   73  Male   \n",
       "1531  ID00423637202312137826377     17  3294  79.258903   72  Male   \n",
       "1532  ID00423637202312137826377     18  2777  66.819057   72  Male   \n",
       "1533  ID00423637202312137826377     19  2700  64.966314   72  Male   \n",
       "1534  ID00423637202312137826377     21  3014  72.521655   72  Male   \n",
       "1535  ID00423637202312137826377     23  2661  64.027911   72  Male   \n",
       "1536  ID00423637202312137826377     30  2778  66.843118   72  Male   \n",
       "1537  ID00423637202312137826377     42  2516  60.538980   72  Male   \n",
       "1538  ID00423637202312137826377     53  2432  58.517806   72  Male   \n",
       "1539  ID00423637202312137826377     70  2578  62.030799   72  Male   \n",
       "1540  ID00426637202313170790466      0  2925  71.824968   73  Male   \n",
       "1541  ID00426637202313170790466      7  2903  71.284746   73  Male   \n",
       "1542  ID00426637202313170790466      9  2916  71.603968   73  Male   \n",
       "1543  ID00426637202313170790466     11  2976  73.077301   73  Male   \n",
       "1544  ID00426637202313170790466     13  2712  66.594637   73  Male   \n",
       "1545  ID00426637202313170790466     19  2978  73.126412   73  Male   \n",
       "1546  ID00426637202313170790466     31  2908  71.407524   73  Male   \n",
       "1547  ID00426637202313170790466     43  2975  73.052745   73  Male   \n",
       "1548  ID00426637202313170790466     59  2774  68.117081   73  Male   \n",
       "\n",
       "     SmokingStatus  \n",
       "1504     Ex-smoker  \n",
       "1505     Ex-smoker  \n",
       "1506     Ex-smoker  \n",
       "1507     Ex-smoker  \n",
       "1508     Ex-smoker  \n",
       "1509     Ex-smoker  \n",
       "1510     Ex-smoker  \n",
       "1511     Ex-smoker  \n",
       "1512     Ex-smoker  \n",
       "1513     Ex-smoker  \n",
       "1514     Ex-smoker  \n",
       "1515     Ex-smoker  \n",
       "1516     Ex-smoker  \n",
       "1517     Ex-smoker  \n",
       "1518     Ex-smoker  \n",
       "1519     Ex-smoker  \n",
       "1520     Ex-smoker  \n",
       "1521     Ex-smoker  \n",
       "1522     Ex-smoker  \n",
       "1523     Ex-smoker  \n",
       "1524     Ex-smoker  \n",
       "1525     Ex-smoker  \n",
       "1526     Ex-smoker  \n",
       "1527     Ex-smoker  \n",
       "1528     Ex-smoker  \n",
       "1529     Ex-smoker  \n",
       "1530     Ex-smoker  \n",
       "1531     Ex-smoker  \n",
       "1532     Ex-smoker  \n",
       "1533     Ex-smoker  \n",
       "1534     Ex-smoker  \n",
       "1535     Ex-smoker  \n",
       "1536     Ex-smoker  \n",
       "1537     Ex-smoker  \n",
       "1538     Ex-smoker  \n",
       "1539     Ex-smoker  \n",
       "1540  Never smoked  \n",
       "1541  Never smoked  \n",
       "1542  Never smoked  \n",
       "1543  Never smoked  \n",
       "1544  Never smoked  \n",
       "1545  Never smoked  \n",
       "1546  Never smoked  \n",
       "1547  Never smoked  \n",
       "1548  Never smoked  "
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_df_ini= pd.read_csv(f'{input_directory}/train.csv')\n",
    "train_df_ini[train_df_ini.Patient.isin(patient_test_list)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "df1 = sub.sort_values(by=['Patient_Week'], ascending=True).reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Patient_Week</th>\n",
       "      <th>FVC</th>\n",
       "      <th>Confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ID00419637202311204720264_-1</td>\n",
       "      <td>2998.380595</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ID00419637202311204720264_-10</td>\n",
       "      <td>3022.589358</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ID00419637202311204720264_-11</td>\n",
       "      <td>3025.279220</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ID00419637202311204720264_-12</td>\n",
       "      <td>3027.969083</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ID00419637202311204720264_-2</td>\n",
       "      <td>3001.070458</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>725</th>\n",
       "      <td>ID00426637202313170790466_95</td>\n",
       "      <td>2624.509718</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>726</th>\n",
       "      <td>ID00426637202313170790466_96</td>\n",
       "      <td>2621.819855</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>727</th>\n",
       "      <td>ID00426637202313170790466_97</td>\n",
       "      <td>2619.129993</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>728</th>\n",
       "      <td>ID00426637202313170790466_98</td>\n",
       "      <td>2616.440130</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>729</th>\n",
       "      <td>ID00426637202313170790466_99</td>\n",
       "      <td>2613.750268</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>730 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                      Patient_Week          FVC  Confidence\n",
       "0     ID00419637202311204720264_-1  2998.380595           0\n",
       "1    ID00419637202311204720264_-10  3022.589358           0\n",
       "2    ID00419637202311204720264_-11  3025.279220           0\n",
       "3    ID00419637202311204720264_-12  3027.969083           0\n",
       "4     ID00419637202311204720264_-2  3001.070458           0\n",
       "..                             ...          ...         ...\n",
       "725   ID00426637202313170790466_95  2624.509718           0\n",
       "726   ID00426637202313170790466_96  2621.819855           0\n",
       "727   ID00426637202313170790466_97  2619.129993           0\n",
       "728   ID00426637202313170790466_98  2616.440130           0\n",
       "729   ID00426637202313170790466_99  2613.750268           0\n",
       "\n",
       "[730 rows x 3 columns]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}