-
Notifications
You must be signed in to change notification settings - Fork 0
/
.ipynb
3665 lines (3665 loc) · 817 KB
/
.ipynb
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
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# TensorPRO (Tensorflow Privacy Remindful Optimization)\n",
"## Alessio Proietti IN550 Final Exam"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Abstract:\n",
"L' idea di base è capire se un cliente in un determinato contesto socioeconomico contattato dalla banca sottoscriverà o no un deposito. \n",
"Il task è di apprendimento supervisionato, le label sono nella colonna 'y'.\n",
"\n",
"Il dataset https://archive.ics.uci.edu/ml/datasets/Bank+Marketing è stato preliminarmente esplorato.\n",
"In una seconda fase è stato standardizzata ogni feature numerica, quelle categoriali sono state codificate con la strategia one hot encoding. \n",
"\n",
"Il dataset era fortemente sbilanciato, nuove istanze per l' allenamento sono state generate con l' algoritmo ADASYN. In conclusione è stata allenata una rete con ottimizzazione ADAM in modalità differential privacy e si sono confrontate delle metriche con la versione non differential private di ADAM."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Fase Esplorativa"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# importo alcune libraries di cui avrò bisogno fin dall' inizio\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"# libs per visualizzazione\n",
"import seaborn as sns \n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline \n",
"sns.set(color_codes=True)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"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>age</th>\n",
" <th>job</th>\n",
" <th>marital</th>\n",
" <th>education</th>\n",
" <th>default</th>\n",
" <th>housing</th>\n",
" <th>loan</th>\n",
" <th>contact</th>\n",
" <th>month</th>\n",
" <th>day_of_week</th>\n",
" <th>...</th>\n",
" <th>campaign</th>\n",
" <th>pdays</th>\n",
" <th>previous</th>\n",
" <th>poutcome</th>\n",
" <th>emp.var.rate</th>\n",
" <th>cons.price.idx</th>\n",
" <th>cons.conf.idx</th>\n",
" <th>euribor3m</th>\n",
" <th>nr.employed</th>\n",
" <th>y</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>56</td>\n",
" <td>housemaid</td>\n",
" <td>married</td>\n",
" <td>basic.4y</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>telephone</td>\n",
" <td>may</td>\n",
" <td>mon</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>999</td>\n",
" <td>0</td>\n",
" <td>nonexistent</td>\n",
" <td>1.1</td>\n",
" <td>93.994</td>\n",
" <td>-36.4</td>\n",
" <td>4.857</td>\n",
" <td>5191.0</td>\n",
" <td>no</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>57</td>\n",
" <td>services</td>\n",
" <td>married</td>\n",
" <td>high.school</td>\n",
" <td>unknown</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>telephone</td>\n",
" <td>may</td>\n",
" <td>mon</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>999</td>\n",
" <td>0</td>\n",
" <td>nonexistent</td>\n",
" <td>1.1</td>\n",
" <td>93.994</td>\n",
" <td>-36.4</td>\n",
" <td>4.857</td>\n",
" <td>5191.0</td>\n",
" <td>no</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>37</td>\n",
" <td>services</td>\n",
" <td>married</td>\n",
" <td>high.school</td>\n",
" <td>no</td>\n",
" <td>yes</td>\n",
" <td>no</td>\n",
" <td>telephone</td>\n",
" <td>may</td>\n",
" <td>mon</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>999</td>\n",
" <td>0</td>\n",
" <td>nonexistent</td>\n",
" <td>1.1</td>\n",
" <td>93.994</td>\n",
" <td>-36.4</td>\n",
" <td>4.857</td>\n",
" <td>5191.0</td>\n",
" <td>no</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>40</td>\n",
" <td>admin.</td>\n",
" <td>married</td>\n",
" <td>basic.6y</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>telephone</td>\n",
" <td>may</td>\n",
" <td>mon</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>999</td>\n",
" <td>0</td>\n",
" <td>nonexistent</td>\n",
" <td>1.1</td>\n",
" <td>93.994</td>\n",
" <td>-36.4</td>\n",
" <td>4.857</td>\n",
" <td>5191.0</td>\n",
" <td>no</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>56</td>\n",
" <td>services</td>\n",
" <td>married</td>\n",
" <td>high.school</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>yes</td>\n",
" <td>telephone</td>\n",
" <td>may</td>\n",
" <td>mon</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>999</td>\n",
" <td>0</td>\n",
" <td>nonexistent</td>\n",
" <td>1.1</td>\n",
" <td>93.994</td>\n",
" <td>-36.4</td>\n",
" <td>4.857</td>\n",
" <td>5191.0</td>\n",
" <td>no</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 21 columns</p>\n",
"</div>"
],
"text/plain": [
" age job marital education default housing loan contact \\\n",
"0 56 housemaid married basic.4y no no no telephone \n",
"1 57 services married high.school unknown no no telephone \n",
"2 37 services married high.school no yes no telephone \n",
"3 40 admin. married basic.6y no no no telephone \n",
"4 56 services married high.school no no yes telephone \n",
"\n",
" month day_of_week ... campaign pdays previous poutcome emp.var.rate \\\n",
"0 may mon ... 1 999 0 nonexistent 1.1 \n",
"1 may mon ... 1 999 0 nonexistent 1.1 \n",
"2 may mon ... 1 999 0 nonexistent 1.1 \n",
"3 may mon ... 1 999 0 nonexistent 1.1 \n",
"4 may mon ... 1 999 0 nonexistent 1.1 \n",
"\n",
" cons.price.idx cons.conf.idx euribor3m nr.employed y \n",
"0 93.994 -36.4 4.857 5191.0 no \n",
"1 93.994 -36.4 4.857 5191.0 no \n",
"2 93.994 -36.4 4.857 5191.0 no \n",
"3 93.994 -36.4 4.857 5191.0 no \n",
"4 93.994 -36.4 4.857 5191.0 no \n",
"\n",
"[5 rows x 21 columns]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_csv('https://raw.githubusercontent.com/alessio-proietti/2021-IN550-EXAM/main/data.csv', sep=';')\n",
"df.head(5)"
]
},
{
"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>age</th>\n",
" <th>job</th>\n",
" <th>marital</th>\n",
" <th>education</th>\n",
" <th>default</th>\n",
" <th>housing</th>\n",
" <th>loan</th>\n",
" <th>contact</th>\n",
" <th>month</th>\n",
" <th>day_of_week</th>\n",
" <th>...</th>\n",
" <th>campaign</th>\n",
" <th>pdays</th>\n",
" <th>previous</th>\n",
" <th>poutcome</th>\n",
" <th>emp.var.rate</th>\n",
" <th>cons.price.idx</th>\n",
" <th>cons.conf.idx</th>\n",
" <th>euribor3m</th>\n",
" <th>nr.employed</th>\n",
" <th>y</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>41183</th>\n",
" <td>73</td>\n",
" <td>retired</td>\n",
" <td>married</td>\n",
" <td>professional.course</td>\n",
" <td>no</td>\n",
" <td>yes</td>\n",
" <td>no</td>\n",
" <td>cellular</td>\n",
" <td>nov</td>\n",
" <td>fri</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>999</td>\n",
" <td>0</td>\n",
" <td>nonexistent</td>\n",
" <td>-1.1</td>\n",
" <td>94.767</td>\n",
" <td>-50.8</td>\n",
" <td>1.028</td>\n",
" <td>4963.6</td>\n",
" <td>yes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>41184</th>\n",
" <td>46</td>\n",
" <td>blue-collar</td>\n",
" <td>married</td>\n",
" <td>professional.course</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>cellular</td>\n",
" <td>nov</td>\n",
" <td>fri</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>999</td>\n",
" <td>0</td>\n",
" <td>nonexistent</td>\n",
" <td>-1.1</td>\n",
" <td>94.767</td>\n",
" <td>-50.8</td>\n",
" <td>1.028</td>\n",
" <td>4963.6</td>\n",
" <td>no</td>\n",
" </tr>\n",
" <tr>\n",
" <th>41185</th>\n",
" <td>56</td>\n",
" <td>retired</td>\n",
" <td>married</td>\n",
" <td>university.degree</td>\n",
" <td>no</td>\n",
" <td>yes</td>\n",
" <td>no</td>\n",
" <td>cellular</td>\n",
" <td>nov</td>\n",
" <td>fri</td>\n",
" <td>...</td>\n",
" <td>2</td>\n",
" <td>999</td>\n",
" <td>0</td>\n",
" <td>nonexistent</td>\n",
" <td>-1.1</td>\n",
" <td>94.767</td>\n",
" <td>-50.8</td>\n",
" <td>1.028</td>\n",
" <td>4963.6</td>\n",
" <td>no</td>\n",
" </tr>\n",
" <tr>\n",
" <th>41186</th>\n",
" <td>44</td>\n",
" <td>technician</td>\n",
" <td>married</td>\n",
" <td>professional.course</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>cellular</td>\n",
" <td>nov</td>\n",
" <td>fri</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>999</td>\n",
" <td>0</td>\n",
" <td>nonexistent</td>\n",
" <td>-1.1</td>\n",
" <td>94.767</td>\n",
" <td>-50.8</td>\n",
" <td>1.028</td>\n",
" <td>4963.6</td>\n",
" <td>yes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>41187</th>\n",
" <td>74</td>\n",
" <td>retired</td>\n",
" <td>married</td>\n",
" <td>professional.course</td>\n",
" <td>no</td>\n",
" <td>yes</td>\n",
" <td>no</td>\n",
" <td>cellular</td>\n",
" <td>nov</td>\n",
" <td>fri</td>\n",
" <td>...</td>\n",
" <td>3</td>\n",
" <td>999</td>\n",
" <td>1</td>\n",
" <td>failure</td>\n",
" <td>-1.1</td>\n",
" <td>94.767</td>\n",
" <td>-50.8</td>\n",
" <td>1.028</td>\n",
" <td>4963.6</td>\n",
" <td>no</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 21 columns</p>\n",
"</div>"
],
"text/plain": [
" age job marital education default housing loan \\\n",
"41183 73 retired married professional.course no yes no \n",
"41184 46 blue-collar married professional.course no no no \n",
"41185 56 retired married university.degree no yes no \n",
"41186 44 technician married professional.course no no no \n",
"41187 74 retired married professional.course no yes no \n",
"\n",
" contact month day_of_week ... campaign pdays previous \\\n",
"41183 cellular nov fri ... 1 999 0 \n",
"41184 cellular nov fri ... 1 999 0 \n",
"41185 cellular nov fri ... 2 999 0 \n",
"41186 cellular nov fri ... 1 999 0 \n",
"41187 cellular nov fri ... 3 999 1 \n",
"\n",
" poutcome emp.var.rate cons.price.idx cons.conf.idx euribor3m \\\n",
"41183 nonexistent -1.1 94.767 -50.8 1.028 \n",
"41184 nonexistent -1.1 94.767 -50.8 1.028 \n",
"41185 nonexistent -1.1 94.767 -50.8 1.028 \n",
"41186 nonexistent -1.1 94.767 -50.8 1.028 \n",
"41187 failure -1.1 94.767 -50.8 1.028 \n",
"\n",
" nr.employed y \n",
"41183 4963.6 yes \n",
"41184 4963.6 no \n",
"41185 4963.6 no \n",
"41186 4963.6 yes \n",
"41187 4963.6 no \n",
"\n",
"[5 rows x 21 columns]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.tail(5)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"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>job</th>\n",
" <th>marital</th>\n",
" <th>education</th>\n",
" <th>default</th>\n",
" <th>housing</th>\n",
" <th>loan</th>\n",
" <th>contact</th>\n",
" <th>month</th>\n",
" <th>day_of_week</th>\n",
" <th>poutcome</th>\n",
" <th>y</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>41188</td>\n",
" <td>41188</td>\n",
" <td>41188</td>\n",
" <td>41188</td>\n",
" <td>41188</td>\n",
" <td>41188</td>\n",
" <td>41188</td>\n",
" <td>41188</td>\n",
" <td>41188</td>\n",
" <td>41188</td>\n",
" <td>41188</td>\n",
" </tr>\n",
" <tr>\n",
" <th>unique</th>\n",
" <td>12</td>\n",
" <td>4</td>\n",
" <td>8</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>10</td>\n",
" <td>5</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>top</th>\n",
" <td>admin.</td>\n",
" <td>married</td>\n",
" <td>university.degree</td>\n",
" <td>no</td>\n",
" <td>yes</td>\n",
" <td>no</td>\n",
" <td>cellular</td>\n",
" <td>may</td>\n",
" <td>thu</td>\n",
" <td>nonexistent</td>\n",
" <td>no</td>\n",
" </tr>\n",
" <tr>\n",
" <th>freq</th>\n",
" <td>10422</td>\n",
" <td>24928</td>\n",
" <td>12168</td>\n",
" <td>32588</td>\n",
" <td>21576</td>\n",
" <td>33950</td>\n",
" <td>26144</td>\n",
" <td>13769</td>\n",
" <td>8623</td>\n",
" <td>35563</td>\n",
" <td>36548</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" job marital education default housing loan contact \\\n",
"count 41188 41188 41188 41188 41188 41188 41188 \n",
"unique 12 4 8 3 3 3 2 \n",
"top admin. married university.degree no yes no cellular \n",
"freq 10422 24928 12168 32588 21576 33950 26144 \n",
"\n",
" month day_of_week poutcome y \n",
"count 41188 41188 41188 41188 \n",
"unique 10 5 3 2 \n",
"top may thu nonexistent no \n",
"freq 13769 8623 35563 36548 "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Con questo posso avere un quadro colonne non numeriche\n",
"df.describe(include = 'object')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"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>age</th>\n",
" <th>duration</th>\n",
" <th>campaign</th>\n",
" <th>pdays</th>\n",
" <th>previous</th>\n",
" <th>emp.var.rate</th>\n",
" <th>cons.price.idx</th>\n",
" <th>cons.conf.idx</th>\n",
" <th>euribor3m</th>\n",
" <th>nr.employed</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>41188.00000</td>\n",
" <td>41188.000000</td>\n",
" <td>41188.000000</td>\n",
" <td>41188.000000</td>\n",
" <td>41188.000000</td>\n",
" <td>41188.000000</td>\n",
" <td>41188.000000</td>\n",
" <td>41188.000000</td>\n",
" <td>41188.000000</td>\n",
" <td>41188.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>40.02406</td>\n",
" <td>258.285010</td>\n",
" <td>2.567593</td>\n",
" <td>962.475454</td>\n",
" <td>0.172963</td>\n",
" <td>0.081886</td>\n",
" <td>93.575664</td>\n",
" <td>-40.502600</td>\n",
" <td>3.621291</td>\n",
" <td>5167.035911</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>10.42125</td>\n",
" <td>259.279249</td>\n",
" <td>2.770014</td>\n",
" <td>186.910907</td>\n",
" <td>0.494901</td>\n",
" <td>1.570960</td>\n",
" <td>0.578840</td>\n",
" <td>4.628198</td>\n",
" <td>1.734447</td>\n",
" <td>72.251528</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>17.00000</td>\n",
" <td>0.000000</td>\n",
" <td>1.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-3.400000</td>\n",
" <td>92.201000</td>\n",
" <td>-50.800000</td>\n",
" <td>0.634000</td>\n",
" <td>4963.600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>32.00000</td>\n",
" <td>102.000000</td>\n",
" <td>1.000000</td>\n",
" <td>999.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-1.800000</td>\n",
" <td>93.075000</td>\n",
" <td>-42.700000</td>\n",
" <td>1.344000</td>\n",
" <td>5099.100000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>38.00000</td>\n",
" <td>180.000000</td>\n",
" <td>2.000000</td>\n",
" <td>999.000000</td>\n",
" <td>0.000000</td>\n",
" <td>1.100000</td>\n",
" <td>93.749000</td>\n",
" <td>-41.800000</td>\n",
" <td>4.857000</td>\n",
" <td>5191.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>47.00000</td>\n",
" <td>319.000000</td>\n",
" <td>3.000000</td>\n",
" <td>999.000000</td>\n",
" <td>0.000000</td>\n",
" <td>1.400000</td>\n",
" <td>93.994000</td>\n",
" <td>-36.400000</td>\n",
" <td>4.961000</td>\n",
" <td>5228.100000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>98.00000</td>\n",
" <td>4918.000000</td>\n",
" <td>56.000000</td>\n",
" <td>999.000000</td>\n",
" <td>7.000000</td>\n",
" <td>1.400000</td>\n",
" <td>94.767000</td>\n",
" <td>-26.900000</td>\n",
" <td>5.045000</td>\n",
" <td>5228.100000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" age duration campaign pdays previous \\\n",
"count 41188.00000 41188.000000 41188.000000 41188.000000 41188.000000 \n",
"mean 40.02406 258.285010 2.567593 962.475454 0.172963 \n",
"std 10.42125 259.279249 2.770014 186.910907 0.494901 \n",
"min 17.00000 0.000000 1.000000 0.000000 0.000000 \n",
"25% 32.00000 102.000000 1.000000 999.000000 0.000000 \n",
"50% 38.00000 180.000000 2.000000 999.000000 0.000000 \n",
"75% 47.00000 319.000000 3.000000 999.000000 0.000000 \n",
"max 98.00000 4918.000000 56.000000 999.000000 7.000000 \n",
"\n",
" emp.var.rate cons.price.idx cons.conf.idx euribor3m nr.employed \n",
"count 41188.000000 41188.000000 41188.000000 41188.000000 41188.000000 \n",
"mean 0.081886 93.575664 -40.502600 3.621291 5167.035911 \n",
"std 1.570960 0.578840 4.628198 1.734447 72.251528 \n",
"min -3.400000 92.201000 -50.800000 0.634000 4963.600000 \n",
"25% -1.800000 93.075000 -42.700000 1.344000 5099.100000 \n",
"50% 1.100000 93.749000 -41.800000 4.857000 5191.000000 \n",
"75% 1.400000 93.994000 -36.400000 4.961000 5228.100000 \n",
"max 1.400000 94.767000 -26.900000 5.045000 5228.100000 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Posso estrarre informazioni di base sulle colonne numeriche\n",
"df.describe()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"age int64\n",
"job object\n",
"marital object\n",
"education object\n",
"default object\n",
"housing object\n",
"loan object\n",
"contact object\n",
"month object\n",
"day_of_week object\n",
"duration int64\n",
"campaign int64\n",
"pdays int64\n",
"previous int64\n",
"poutcome object\n",
"emp.var.rate float64\n",
"cons.price.idx float64\n",
"cons.conf.idx float64\n",
"euribor3m float64\n",
"nr.employed float64\n",
"y object\n",
"dtype: object"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Stampo i tipi di tutte le variabili per capire con cosa ho a che fare\n",
"df.dtypes"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"age 0\n",
"job 0\n",
"marital 0\n",
"education 0\n",
"default 0\n",
"housing 0\n",
"loan 0\n",
"contact 0\n",
"month 0\n",
"day_of_week 0\n",
"duration 0\n",
"campaign 0\n",
"pdays 0\n",
"previous 0\n",
"poutcome 0\n",
"emp.var.rate 0\n",
"cons.price.idx 0\n",
"cons.conf.idx 0\n",
"euribor3m 0\n",
"nr.employed 0\n",
"y 0\n",
"dtype: int64\n"
]
}
],
"source": [
"# Voglio contare i campi nulli o comunque capire se ce ne sono\n",
"print(df.isnull().sum())"
]
},
{
"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>age</th>\n",
" <th>duration</th>\n",
" <th>campaign</th>\n",
" <th>pdays</th>\n",
" <th>previous</th>\n",
" <th>emp.var.rate</th>\n",
" <th>cons.price.idx</th>\n",
" <th>cons.conf.idx</th>\n",
" <th>euribor3m</th>\n",
" <th>nr.employed</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>age</th>\n",
" <td>1.000000</td>\n",
" <td>-0.000866</td>\n",
" <td>0.004594</td>\n",
" <td>-0.034369</td>\n",
" <td>0.024365</td>\n",
" <td>-0.000371</td>\n",
" <td>0.000857</td>\n",
" <td>0.129372</td>\n",
" <td>0.010767</td>\n",
" <td>-0.017725</td>\n",
" </tr>\n",
" <tr>\n",
" <th>duration</th>\n",
" <td>-0.000866</td>\n",
" <td>1.000000</td>\n",
" <td>-0.071699</td>\n",
" <td>-0.047577</td>\n",
" <td>0.020640</td>\n",
" <td>-0.027968</td>\n",
" <td>0.005312</td>\n",
" <td>-0.008173</td>\n",
" <td>-0.032897</td>\n",
" <td>-0.044703</td>\n",
" </tr>\n",
" <tr>\n",
" <th>campaign</th>\n",
" <td>0.004594</td>\n",
" <td>-0.071699</td>\n",
" <td>1.000000</td>\n",
" <td>0.052584</td>\n",
" <td>-0.079141</td>\n",
" <td>0.150754</td>\n",
" <td>0.127836</td>\n",
" <td>-0.013733</td>\n",
" <td>0.135133</td>\n",
" <td>0.144095</td>\n",
" </tr>\n",
" <tr>\n",
" <th>pdays</th>\n",
" <td>-0.034369</td>\n",
" <td>-0.047577</td>\n",
" <td>0.052584</td>\n",
" <td>1.000000</td>\n",
" <td>-0.587514</td>\n",
" <td>0.271004</td>\n",
" <td>0.078889</td>\n",
" <td>-0.091342</td>\n",
" <td>0.296899</td>\n",
" <td>0.372605</td>\n",
" </tr>\n",
" <tr>\n",
" <th>previous</th>\n",
" <td>0.024365</td>\n",
" <td>0.020640</td>\n",
" <td>-0.079141</td>\n",
" <td>-0.587514</td>\n",
" <td>1.000000</td>\n",
" <td>-0.420489</td>\n",
" <td>-0.203130</td>\n",
" <td>-0.050936</td>\n",
" <td>-0.454494</td>\n",
" <td>-0.501333</td>\n",
" </tr>\n",
" <tr>\n",
" <th>emp.var.rate</th>\n",
" <td>-0.000371</td>\n",
" <td>-0.027968</td>\n",
" <td>0.150754</td>\n",
" <td>0.271004</td>\n",
" <td>-0.420489</td>\n",
" <td>1.000000</td>\n",
" <td>0.775334</td>\n",
" <td>0.196041</td>\n",
" <td>0.972245</td>\n",
" <td>0.906970</td>\n",
" </tr>\n",
" <tr>\n",
" <th>cons.price.idx</th>\n",
" <td>0.000857</td>\n",
" <td>0.005312</td>\n",
" <td>0.127836</td>\n",
" <td>0.078889</td>\n",
" <td>-0.203130</td>\n",
" <td>0.775334</td>\n",
" <td>1.000000</td>\n",
" <td>0.058986</td>\n",
" <td>0.688230</td>\n",
" <td>0.522034</td>\n",
" </tr>\n",
" <tr>\n",
" <th>cons.conf.idx</th>\n",
" <td>0.129372</td>\n",
" <td>-0.008173</td>\n",
" <td>-0.013733</td>\n",
" <td>-0.091342</td>\n",
" <td>-0.050936</td>\n",
" <td>0.196041</td>\n",
" <td>0.058986</td>\n",
" <td>1.000000</td>\n",
" <td>0.277686</td>\n",
" <td>0.100513</td>\n",