-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.py
1363 lines (1122 loc) · 66.7 KB
/
MainWindow.py
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
from PyQt5 import QtCore, QtGui, QtWidgets
import seaborn as sns
import pandas as pd
from PyQt5.QtWidgets import QTableWidgetItem, QMessageBox, QVBoxLayout, QLabel, QComboBox, QApplication, QFileDialog, QMainWindow
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split, cross_validate
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
from sklearn.metrics import mean_squared_error, mean_absolute_error, accuracy_score, r2_score, classification_report, confusion_matrix
import joblib
import numpy as np
import Predict
import DataInfo
import warnings
warnings.filterwarnings("ignore")
pd.set_option("display.max_columns", None)
pd.set_option("display.max_rows", None)
pd.set_option("display.width", 500)
pd.set_option("display.float_format", lambda x: "%.4f" % x)
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(QMainWindow):
def __init__(self):
super(Ui_MainWindow, self).__init__()
self.dataFrame = None
self.setupUi(self)
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1090, 1000)
MainWindow.setMinimumSize(QtCore.QSize(1090, 1000))
MainWindow.setMaximumSize(QtCore.QSize(1090, 1000))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setGeometry(QtCore.QRect(11, 12, 291, 951))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.groupBox.sizePolicy().hasHeightForWidth())
self.groupBox.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.groupBox.setFont(font)
self.groupBox.setTitle("")
self.groupBox.setObjectName("groupBox")
self.verticalLayout_6 = QtWidgets.QVBoxLayout(self.groupBox)
self.verticalLayout_6.setObjectName("verticalLayout_6")
self.formLayout = QtWidgets.QFormLayout()
self.formLayout.setObjectName("formLayout")
self.txt_head_number = QtWidgets.QLineEdit(self.groupBox)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.txt_head_number.sizePolicy().hasHeightForWidth())
self.txt_head_number.setSizePolicy(sizePolicy)
self.txt_head_number.setObjectName("txt_head_number")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.SpanningRole, self.txt_head_number)
self.btn_tail = QtWidgets.QPushButton(self.groupBox)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.btn_tail.sizePolicy().hasHeightForWidth())
self.btn_tail.setSizePolicy(sizePolicy)
self.btn_tail.setObjectName("btn_tail")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.btn_tail)
self.btn_head = QtWidgets.QPushButton(self.groupBox)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.btn_head.sizePolicy().hasHeightForWidth())
self.btn_head.setSizePolicy(sizePolicy)
self.btn_head.setObjectName("btn_head")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.btn_head)
self.btn_shape = QtWidgets.QPushButton(self.groupBox)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.btn_shape.sizePolicy().hasHeightForWidth())
self.btn_shape.setSizePolicy(sizePolicy)
self.btn_shape.setObjectName("btn_shape")
self.formLayout.setWidget(5, QtWidgets.QFormLayout.LabelRole, self.btn_shape)
self.txt_shape = QtWidgets.QLineEdit(self.groupBox)
self.txt_shape.setEnabled(True)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.txt_shape.sizePolicy().hasHeightForWidth())
self.txt_shape.setSizePolicy(sizePolicy)
self.txt_shape.setObjectName("txt_shape")
self.formLayout.setWidget(5, QtWidgets.QFormLayout.FieldRole, self.txt_shape)
self.btn_data_types = QtWidgets.QPushButton(self.groupBox)
self.btn_data_types.setObjectName("btn_data_types")
self.formLayout.setWidget(6, QtWidgets.QFormLayout.SpanningRole, self.btn_data_types)
self.btn_none_values = QtWidgets.QPushButton(self.groupBox)
self.btn_none_values.setObjectName("btn_none_values")
self.formLayout.setWidget(7, QtWidgets.QFormLayout.SpanningRole, self.btn_none_values)
self.btn_data_describe = QtWidgets.QPushButton(self.groupBox)
self.btn_data_describe.setObjectName("btn_data_describe")
self.formLayout.setWidget(8, QtWidgets.QFormLayout.SpanningRole, self.btn_data_describe)
self.btn_data_information = QtWidgets.QPushButton(self.groupBox)
self.btn_data_information.setObjectName("btn_data_information")
self.formLayout.setWidget(9, QtWidgets.QFormLayout.SpanningRole, self.btn_data_information)
self.cBox_datasetNames = QtWidgets.QComboBox(self.groupBox)
self.cBox_datasetNames.setObjectName("cBox_datasetNames")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.SpanningRole, self.cBox_datasetNames)
self.btn_load_data = QtWidgets.QPushButton(self.groupBox)
self.btn_load_data.setObjectName("btn_load_data")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.SpanningRole, self.btn_load_data)
self.verticalLayout_6.addLayout(self.formLayout)
self.groupBox_3 = QtWidgets.QGroupBox(self.groupBox)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.groupBox_3.sizePolicy().hasHeightForWidth())
self.groupBox_3.setSizePolicy(sizePolicy)
self.groupBox_3.setObjectName("groupBox_3")
self.layoutWidget = QtWidgets.QWidget(self.groupBox_3)
self.layoutWidget.setGeometry(QtCore.QRect(10, 23, 251, 189))
self.layoutWidget.setObjectName("layoutWidget")
self.formLayout_2 = QtWidgets.QFormLayout(self.layoutWidget)
self.formLayout_2.setContentsMargins(0, 0, 0, 0)
self.formLayout_2.setObjectName("formLayout_2")
self.btn_FillNoneValues = QtWidgets.QPushButton(self.layoutWidget)
self.btn_FillNoneValues.setObjectName("btn_FillNoneValues")
self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.btn_FillNoneValues)
self.btn_Encode = QtWidgets.QPushButton(self.layoutWidget)
self.btn_Encode.setObjectName("btn_Encode")
self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.btn_Encode)
self.txt_TargetName = QtWidgets.QLineEdit(self.layoutWidget)
self.txt_TargetName.setObjectName("txt_TargetName")
self.formLayout_2.setWidget(2, QtWidgets.QFormLayout.SpanningRole, self.txt_TargetName)
self.txt_zeroColumnNames = QtWidgets.QLineEdit(self.layoutWidget)
self.txt_zeroColumnNames.setText("")
self.txt_zeroColumnNames.setDragEnabled(True)
self.txt_zeroColumnNames.setObjectName("txt_zeroColumnNames")
self.formLayout_2.setWidget(1, QtWidgets.QFormLayout.SpanningRole, self.txt_zeroColumnNames)
self.btn_RFModel = QtWidgets.QPushButton(self.layoutWidget)
self.btn_RFModel.setObjectName("btn_RFModel")
self.formLayout_2.setWidget(3, QtWidgets.QFormLayout.SpanningRole, self.btn_RFModel)
self.btn_Predict = QtWidgets.QPushButton(self.layoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.btn_Predict.sizePolicy().hasHeightForWidth())
self.btn_Predict.setSizePolicy(sizePolicy)
self.btn_Predict.setObjectName("btn_Predict")
self.formLayout_2.setWidget(4, QtWidgets.QFormLayout.SpanningRole, self.btn_Predict)
self.verticalLayout_6.addWidget(self.groupBox_3)
self.verticalLayout_3 = QtWidgets.QVBoxLayout()
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.ckBox_summary_plot = QtWidgets.QCheckBox(self.groupBox)
self.ckBox_summary_plot.setObjectName("ckBox_summary_plot")
self.horizontalLayout.addWidget(self.ckBox_summary_plot)
self.txt_summary_name = QtWidgets.QLineEdit(self.groupBox)
self.txt_summary_name.setObjectName("txt_summary_name")
self.horizontalLayout.addWidget(self.txt_summary_name)
self.verticalLayout_2.addLayout(self.horizontalLayout)
self.verticalLayout_3.addLayout(self.verticalLayout_2)
self.btn_num_summary = QtWidgets.QPushButton(self.groupBox)
self.btn_num_summary.setObjectName("btn_num_summary")
self.verticalLayout_3.addWidget(self.btn_num_summary)
self.verticalLayout_6.addLayout(self.verticalLayout_3)
self.verticalLayout_4 = QtWidgets.QVBoxLayout()
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.verticalLayout_5 = QtWidgets.QVBoxLayout()
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.ckBox_plot_target = QtWidgets.QCheckBox(self.groupBox)
self.ckBox_plot_target.setObjectName("ckBox_plot_target")
self.horizontalLayout_2.addWidget(self.ckBox_plot_target)
self.txt_target_summary_name = QtWidgets.QLineEdit(self.groupBox)
self.txt_target_summary_name.setObjectName("txt_target_summary_name")
self.horizontalLayout_2.addWidget(self.txt_target_summary_name)
self.verticalLayout_5.addLayout(self.horizontalLayout_2)
self.txt_target = QtWidgets.QLineEdit(self.groupBox)
self.txt_target.setObjectName("txt_target")
self.verticalLayout_5.addWidget(self.txt_target)
self.btn_target_summary = QtWidgets.QPushButton(self.groupBox)
self.btn_target_summary.setObjectName("btn_target_summary")
self.verticalLayout_5.addWidget(self.btn_target_summary)
self.verticalLayout_4.addLayout(self.verticalLayout_5)
self.verticalLayout_6.addLayout(self.verticalLayout_4)
self.btn_correlation_analysis = QtWidgets.QPushButton(self.groupBox)
self.btn_correlation_analysis.setObjectName("btn_correlation_analysis")
self.verticalLayout_6.addWidget(self.btn_correlation_analysis)
self.btn_refresh_table = QtWidgets.QPushButton(self.groupBox)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.btn_refresh_table.setFont(font)
self.btn_refresh_table.setObjectName("btn_refresh_table")
self.verticalLayout_6.addWidget(self.btn_refresh_table)
self.groupBox_2 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_2.setGeometry(QtCore.QRect(312, 12, 771, 951))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.groupBox_2.sizePolicy().hasHeightForWidth())
self.groupBox_2.setSizePolicy(sizePolicy)
self.groupBox_2.setTitle("")
self.groupBox_2.setObjectName("groupBox_2")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.groupBox_2)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.table_data = QtWidgets.QTableWidget(self.groupBox_2)
self.table_data.setObjectName("table_data")
self.table_data.setColumnCount(0)
self.table_data.setRowCount(0)
self.horizontalLayout_3.addWidget(self.table_data)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
MainWindow.setTabOrder(self.btn_load_data, self.txt_head_number)
MainWindow.setTabOrder(self.txt_head_number, self.btn_tail)
MainWindow.setTabOrder(self.btn_tail, self.btn_shape)
MainWindow.setTabOrder(self.btn_shape, self.btn_data_types)
MainWindow.setTabOrder(self.btn_data_types, self.btn_none_values)
MainWindow.setTabOrder(self.btn_none_values, self.btn_data_describe)
MainWindow.setTabOrder(self.btn_data_describe, self.btn_data_information)
MainWindow.setTabOrder(self.btn_data_information, self.txt_summary_name)
MainWindow.setTabOrder(self.txt_summary_name, self.ckBox_summary_plot)
MainWindow.setTabOrder(self.ckBox_summary_plot, self.btn_num_summary)
MainWindow.setTabOrder(self.btn_num_summary, self.txt_target_summary_name)
MainWindow.setTabOrder(self.txt_target_summary_name, self.ckBox_plot_target)
MainWindow.setTabOrder(self.ckBox_plot_target, self.btn_target_summary)
MainWindow.setTabOrder(self.btn_target_summary, self.btn_correlation_analysis)
MainWindow.setTabOrder(self.btn_correlation_analysis, self.table_data)
MainWindow.setTabOrder(self.table_data, self.txt_shape)
self.btn_load_data.clicked.connect(self.load_data)
self.btn_shape.clicked.connect(self.show_shape)
self.btn_head.clicked.connect(self.show_df_head)
self.btn_tail.clicked.connect(self.show_df_tail)
self.btn_data_types.clicked.connect(self.show_data_types)
self.btn_refresh_table.clicked.connect(self.refresh_table)
self.btn_none_values.clicked.connect(self.show_none_sums)
self.btn_data_describe.clicked.connect(self.data_describe)
self.btn_data_information.clicked.connect(self.show_data_info)
self.btn_num_summary.clicked.connect(self.column_summary)
self.btn_target_summary.clicked.connect(self.target_summary)
self.btn_correlation_analysis.clicked.connect(self.correlation_analysis)
self.btn_FillNoneValues.clicked.connect(self.fill_NA_Values)
self.btn_Encode.clicked.connect(self.encode_df)
self.btn_RFModel.clicked.connect(self.RF_Model)
self.btn_Predict.clicked.connect(self.Predict)
self.load_seaborn_datasets()
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Data Visualizer Program"))
self.txt_head_number.setToolTip(_translate("MainWindow", "Numeric value of for your choice of first or last of dataset"))
self.txt_head_number.setPlaceholderText(_translate("MainWindow", "5"))
self.btn_tail.setToolTip(_translate("MainWindow", "Shows the last rows of the dataset for desired number"))
self.btn_tail.setText(_translate("MainWindow", "Tail"))
self.btn_head.setToolTip(_translate("MainWindow", "Shows the first rows of dataset for desired number"))
self.btn_head.setText(_translate("MainWindow", "Head"))
self.btn_shape.setToolTip(_translate("MainWindow", "Shows the row and column number"))
self.btn_shape.setText(_translate("MainWindow", "Shape"))
self.btn_data_types.setToolTip(_translate("MainWindow", "Shows the data types of columns in dataset"))
self.btn_data_types.setText(_translate("MainWindow", "Data Types"))
self.btn_none_values.setToolTip(_translate("MainWindow", "Shows the sum of none values for each column in dataset"))
self.btn_none_values.setText(_translate("MainWindow", "None Values"))
self.btn_data_describe.setToolTip(_translate("MainWindow", "Shows the statistical values of columns"))
self.btn_data_describe.setText(_translate("MainWindow", "Data Describe"))
self.btn_data_information.setToolTip(_translate("MainWindow", "Shows the information for each column"))
self.btn_data_information.setText(_translate("MainWindow", "Data Information"))
self.btn_load_data.setToolTip(_translate("MainWindow", "Loads the example dataset from the seaborn library"))
self.btn_load_data.setText(_translate("MainWindow", "Load Data"))
self.groupBox_3.setTitle(_translate("MainWindow", "Create Machine Learning Model"))
self.btn_FillNoneValues.setText(_translate("MainWindow", "Fill NA Values"))
self.btn_Encode.setText(_translate("MainWindow", "Encode"))
self.txt_TargetName.setPlaceholderText(_translate("MainWindow", "Target Name"))
self.txt_zeroColumnNames.setPlaceholderText(_translate("MainWindow", "Column Names Exception"))
self.btn_RFModel.setText(_translate("MainWindow", "RF Model"))
self.btn_Predict.setText(_translate("MainWindow", "Predict"))
self.ckBox_summary_plot.setText(_translate("MainWindow", "Plot"))
self.txt_summary_name.setToolTip(_translate("MainWindow", "To see all categorical or numerical column summaries, dont click plot. To see the plot for specific column summary click plot"))
self.txt_summary_name.setPlaceholderText(_translate("MainWindow", "Column Name"))
self.btn_num_summary.setToolTip(_translate("MainWindow", "Shows the column summary"))
self.btn_num_summary.setText(_translate("MainWindow", "Column Summary"))
self.ckBox_plot_target.setText(_translate("MainWindow", "Plot"))
self.txt_target_summary_name.setToolTip(_translate("MainWindow", "Targeted column for target analysis"))
self.txt_target_summary_name.setPlaceholderText(_translate("MainWindow", "Targeted Column"))
self.txt_target.setToolTip(_translate("MainWindow", "Actual target in dataset"))
self.txt_target.setPlaceholderText(_translate("MainWindow", "Target"))
self.btn_target_summary.setToolTip(_translate("MainWindow", "Shows the target analysis"))
self.btn_target_summary.setText(_translate("MainWindow", "Target Summary"))
self.btn_correlation_analysis.setToolTip(_translate("MainWindow", "Shows the correlation analysis of dataset"))
self.btn_correlation_analysis.setText(_translate("MainWindow", "Correlation Analysis"))
self.btn_refresh_table.setToolTip(_translate("MainWindow", "Refresh the table to beginning"))
self.btn_refresh_table.setText(_translate("MainWindow", "Refresh Table"))
def load_seaborn_datasets(self):
datasets_name = sns.get_dataset_names()
self.cBox_datasetNames.addItem("None")
self.cBox_datasetNames.addItems(datasets_name)
def load_data(self):
"""
Load data from a dataset specified by the user input and populate a QTableWidget.
This method interacts with a graphical user interface (GUI) to load a dataset using
the Seaborn library, display the data in a table widget, and handle any potential errors.
Returns:
DataFrame or None: Loaded DataFrame if successful, None otherwise.
"""
try:
data_name = self.cBox_datasetNames.currentText()
if data_name == "None":
try:
dataset_path, _ = QFileDialog.getOpenFileName(None, "Select Dataset File", "", "CSV Files (*.csv);;All Files (*)")
if not dataset_path:
QMessageBox.warning(None, "Error", "No file selected.")
return None
self.dataFrame = pd.read_csv(dataset_path)
# Get the dimensions of the DataFrame
num_rows, num_cols = self.dataFrame.shape
# Clear any existing content in the table widget
self.table_data.clear()
# Set the number of rows and columns in the table widget
self.table_data.setRowCount(num_rows)
self.table_data.setColumnCount(num_cols)
# Set column names based on the DataFrame's columns
column_names = list(self.dataFrame.columns)
self.table_data.setHorizontalHeaderLabels(column_names)
# Populate the table widget with data from the DataFrame
for i in range(num_rows):
for j in range(num_cols):
item = QTableWidgetItem(str(self.dataFrame.iat[i, j]))
self.table_data.setItem(i, j, item)
return self.dataFrame
except Exception as e:
# If an error occurs, display a warning message with details of the error
QMessageBox.warning(None, "Error", f"An error occurred: {e}")
return None
data = sns.load_dataset(data_name)
self.dataFrame = pd.DataFrame(data)
# Get the dimensions of the DataFrame
num_rows, num_cols = self.dataFrame.shape
# Clear any existing content in the table widget
self.table_data.clear()
# Set the number of rows and columns in the table widget
self.table_data.setRowCount(num_rows)
self.table_data.setColumnCount(num_cols)
# Set column names based on the DataFrame's columns
column_names = list(self.dataFrame.columns)
self.table_data.setHorizontalHeaderLabels(column_names)
# Populate the table widget with data from the DataFrame
for i in range(num_rows):
for j in range(num_cols):
item = QTableWidgetItem(str(self.dataFrame.iat[i, j]))
self.table_data.setItem(i, j, item)
return self.dataFrame
except Exception as e:
# If an error occurs, display a warning message with details of the error
QMessageBox.warning(None, "Error", f"An error occurred: {e}")
return None
""""
def open_data(self):
Load data from a dataset specified by the user input and populate a QTableWidget.
This method interacts with a graphical user interface (GUI) to load a dataset using
the Seaborn library, display the data in a table widget, and handle any potential errors.
Returns:
DataFrame or None: Loaded DataFrame if successful, None otherwise.
try:
dataset_path, _ = QFileDialog.getOpenFileName(None, "Select Dataset File", "", "CSV Files (*.csv);;All Files (*)")
if not dataset_path:
QMessageBox.warning(None, "Error", "No file selected.")
return None
self.dataFrame = pd.read_csv(dataset_path)
# Get the dimensions of the DataFrame
num_rows, num_cols = self.dataFrame.shape
# Clear any existing content in the table widget
self.table_data.clear()
# Set the number of rows and columns in the table widget
self.table_data.setRowCount(num_rows)
self.table_data.setColumnCount(num_cols)
# Set column names based on the DataFrame's columns
column_names = list(self.dataFrame.columns)
self.table_data.setHorizontalHeaderLabels(column_names)
# Populate the table widget with data from the DataFrame
for i in range(num_rows):
for j in range(num_cols):
item = QTableWidgetItem(str(self.dataFrame.iat[i, j]))
self.table_data.setItem(i, j, item)
return self.dataFrame
except Exception as e:
# If an error occurs, display a warning message with details of the error
QMessageBox.warning(None, "Error", f"An error occurred: {e}")
return None
"""
def show_shape(self):
"""
Display the shape (number of rows and columns) of the loaded dataset.
This method interacts with a graphical user interface (GUI) to load a dataset
using the Seaborn library, calculate the number of rows and columns in the dataset,
and display the shape in a text field.
Returns:
None
Raises:
QMessageBox.warning: If an error occurs during data loading or shape calculation,
a warning message dialog is displayed to the user with details
of the error.
"""
try:
if self.dataFrame is not None:
# Calculate the number of rows and columns in the DataFrame
num_rows, num_cols = self.dataFrame.shape
# Create a string representation of the shape (number of rows and columns)
shape = f"{num_rows} - {num_cols}"
# Set the shape string in the text field and disable further editing
self.txt_shape.setText(shape)
self.txt_shape.setEnabled(False)
except Exception as e:
# If an error occurs, display a warning message with details of the error
QMessageBox.warning(None, "Error", f"An error occurred: {e}")
def show_df_head(self):
"""
Display the first few rows of the loaded dataset in a QTableWidget.
This method interacts with a graphical user interface (GUI) to load a dataset
using the Seaborn library, retrieve the specified number of rows to display,
and populate a table widget with the selected rows of the DataFrame.
Returns:
None
Raises:
QMessageBox.warning: If an error occurs during data loading or display,
a warning message dialog is displayed to the user with
details of the error.
"""
try:
if self.dataFrame is not None:
if self.txt_head_number.text() == "":
QMessageBox.warning(None, "Error", f"Please type a head number.")
else:
# Retrieve the specified number of rows to display
head = int(self.txt_head_number.text())
# Get the first few rows of the DataFrame
head_dataFrame = self.dataFrame.head(head)
# Get the dimensions of the DataFrame
num_rows, num_cols = head_dataFrame.shape
# Set the number of rows and columns in the table widget
self.table_data.setRowCount(num_rows)
self.table_data.setColumnCount(num_cols)
# Set column names in the table widget
column_names = list(head_dataFrame.columns)
self.table_data.setHorizontalHeaderLabels(column_names)
# Populate the table widget with data from the DataFrame
for i in range(num_rows):
for j in range(num_cols):
item = QTableWidgetItem(str(head_dataFrame.iat[i, j]))
self.table_data.setItem(i, j, item)
except ValueError as ve:
# Handle ValueError (e.g., invalid input for row count)
QMessageBox.warning(None, "Value Error", f"An error occurred: {ve}")
except TypeError as te:
# Handle TypeError (e.g., invalid type conversion)
QMessageBox.warning(None, "Type Error", f"An error occurred: {te}")
except Exception as e:
# Handle any other unexpected exceptions
QMessageBox.warning(None, "Error", f"An error occurred: {e}")
def show_df_tail(self):
"""
Display the last few rows of the loaded dataset in a QTableWidget.
This method interacts with a graphical user interface (GUI) to load a dataset
using the Seaborn library, retrieve the specified number of rows from the end,
and populate a table widget with the selected rows of the DataFrame.
Returns:
None
Raises:
QMessageBox.warning: If an error occurs during data loading or display,
a warning message dialog is displayed to the user with
details of the error.
"""
try:
if self.dataFrame is not None:
if self.txt_head_number.text() == "":
QMessageBox.warning(None, "Error", f"Please type a tail number.")
else:
# Retrieve the specified number of rows from the end to display
tail = int(self.txt_head_number.text())
# Get the last few rows of the DataFrame
tail_dataFrame = self.dataFrame.tail(tail)
# Get the dimensions of the DataFrame
num_rows, num_cols = tail_dataFrame.shape
# Set the number of rows and columns in the table widget
self.table_data.setRowCount(num_rows)
self.table_data.setColumnCount(num_cols)
# Set column names in the table widget
column_names = list(tail_dataFrame.columns)
self.table_data.setHorizontalHeaderLabels(column_names)
# Populate the table widget with data from the DataFrame
for i in range(num_rows):
for j in range(num_cols):
item = QTableWidgetItem(str(tail_dataFrame.iat[i, j]))
self.table_data.setItem(i, j, item)
except ValueError as ve:
# Handle ValueError (e.g., invalid input for row count)
QMessageBox.warning(None, "Value Error", f"An error occurred: {ve}")
except TypeError as te:
# Handle TypeError (e.g., invalid type conversion)
QMessageBox.warning(None, "Type Error", f"An error occurred: {te}")
except Exception as e:
# Handle any other unexpected exceptions
QMessageBox.warning(None, "Error", f"An error occurred: {e}")
def show_data_types(self):
"""
Display the data types of columns in the loaded dataset in a QTableWidget.
This method interacts with a graphical user interface (GUI) to load a dataset
using the Seaborn library, retrieve the data types of columns, and display them
in a table widget.
Returns:
None
Raises:
QMessageBox.warning: If an error occurs during data loading or display,
a warning message dialog is displayed to the user with
details of the error.
"""
try:
if self.dataFrame is not None:
# Get the column names from the DataFrame
column_names = list(self.dataFrame.columns)
# Clear existing content and set column names in the table widget
self.table_data.clear()
self.table_data.setColumnCount(len(column_names))
self.table_data.setHorizontalHeaderLabels(column_names)
# Retrieve the data types of columns from the DataFrame
dataTypes = self.dataFrame.dtypes
# Display data types in the first row of the table widget
for i, column_name in enumerate(column_names):
item = QTableWidgetItem(str(dataTypes[column_name]))
self.table_data.setItem(0, i, item)
except ValueError as ve:
# Handle ValueError (e.g., invalid input or operation)
QMessageBox.warning(None, "Value Error", f"An error occurred: {ve}")
except TypeError as te:
# Handle TypeError (e.g., invalid type conversion)
QMessageBox.warning(None, "Type Error", f"An error occurred: {te}")
except Exception as e:
# Handle any other unexpected exceptions
QMessageBox.warning(None, "Error", f"An error occurred: {e}")
def refresh_table(self):
"""
Refresh the table widget with the latest data from the dataset.
This method interacts with a graphical user interface (GUI) to reload the dataset
and update the table widget with the latest data. It also enables the data name
input field for further changes.
Returns:
None
"""
try:
# Clear any existing content in the table widget
self.table_data.clear()
self.txt_data_name.setEnabled(True)
num_rows, num_cols = self.dataFrame.shape
self.table_data.setRowCount(num_rows)
self.table_data.setColumnCount(num_cols)
column_names = list(self.dataFrame.columns)
self.table_data.setHorizontalHeaderLabels(column_names)
# Populate the table widget with data from the DataFrame
for i in range(num_rows):
for j in range(num_cols):
item = QTableWidgetItem(str(self.dataFrame.iat[i, j]))
self.table_data.setItem(i, j, item)
except Exception as e:
# Handle any unexpected exceptions
QMessageBox.warning(None, "Error", f"An error occurred: {e}")
def show_none_sums(self):
"""
Display the number of null values in each column of the loaded dataset in a QTableWidget.
This method interacts with a graphical user interface (GUI) to load a dataset
using the Seaborn library, count the number of null values in each column,
and display the counts in a table widget.
Returns:
None
Raises:
QMessageBox.warning: If an error occurs during data loading or display,
a warning message dialog is displayed to the user with
details of the error.
"""
try:
zero_columns = self.txt_zeroColumnNames.text()
zero_columns_list = [item.strip() for item in zero_columns.split(',')]
zero_columns = [col for col in self.dataFrame.columns if (self.dataFrame[col].min() == 0) and col not in zero_columns_list]
for col in zero_columns:
self.dataFrame[col] = np.where(self.dataFrame[col] == 0, np.nan, self.dataFrame[col])
if self.dataFrame is not None:
# Get the column names from the DataFrame
column_names = list(self.dataFrame.columns)
# Clear existing content, set column names, and define row count in the table widget
self.table_data.clear()
self.table_data.setColumnCount(len(column_names))
self.table_data.setRowCount(1)
self.table_data.setHorizontalHeaderLabels(column_names)
# Count the number of null values in each column and display in the first row
for i, column_name in enumerate(column_names):
num_nulls = self.dataFrame[column_name].isnull().sum()
item = QTableWidgetItem(str(num_nulls))
self.table_data.setItem(0, i, item)
except ValueError as ve:
# Handle ValueError (e.g., invalid input or operation)
QMessageBox.warning(None, "Value Error", f"An error occurred: {ve}")
except TypeError as te:
# Handle TypeError (e.g., invalid type conversion)
QMessageBox.warning(None, "Type Error", f"An error occurred: {te}")
except Exception as e:
# Handle any other unexpected exceptions
QMessageBox.warning(None, "Error", f"An error occurred: {e}")
def data_describe(self):
"""
Display descriptive statistics of the loaded dataset in a QTableWidget.
This method interacts with a graphical user interface (GUI) to load a dataset
using the Seaborn library, compute descriptive statistics, and display them
in a table widget.
Returns:
None
Raises:
QMessageBox.warning: If an error occurs during data loading or display,
a warning message dialog is displayed to the user with
details of the error.
"""
try:
if self.dataFrame is not None:
# Clear existing content in the table widget
self.table_data.clear()
# Compute descriptive statistics and transpose the result for easier display
described_data = self.dataFrame.describe().T
# Set the number of rows and columns in the table widget
self.table_data.setRowCount(len(described_data))
self.table_data.setColumnCount(len(described_data.columns))
# Set column names in the table widget
column_names = described_data.columns
self.table_data.setHorizontalHeaderLabels(column_names)
# Set index names in the table widget
index_names = described_data.index.tolist()
self.table_data.setVerticalHeaderLabels(index_names)
# Populate the table widget with the described data
for i, (_, row) in enumerate(described_data.iterrows()):
for j, value in enumerate(row):
# Format value to have only two digits after the decimal point
formatted_value = "{:.2f}".format(value)
item = QTableWidgetItem(formatted_value)
self.table_data.setItem(i, j, item)
except ValueError as ve:
# Handle ValueError (e.g., invalid input or operation)
QMessageBox.warning(None, "Value Error", f"An error occurred: {ve}")
except TypeError as te:
# Handle TypeError (e.g., invalid type conversion)
QMessageBox.warning(None, "Type Error", f"An error occurred: {te}")
except Exception as e:
# Handle any other unexpected exceptions
QMessageBox.warning(None, "Error", f"An error occurred: {e}")
def show_data_info(self):
"""
Display information about each column in the loaded dataset in a QMessageBox.
This method interacts with a graphical user interface (GUI) to load a dataset
using the Seaborn library, gather information about each column (such as data type,
non-null count, and total count), and display the information in a message box.
Returns:
None
Raises:
QMessageBox.warning: If an error occurs during data loading or display,
a warning message dialog is displayed to the user with
details of the error.
"""
try:
if self.dataFrame is not None:
info_text = ""
for column_name in self.dataFrame.columns:
# Gather column information
data_type = str(self.dataFrame[column_name].dtype)
non_null_count = self.dataFrame[column_name].notnull().sum()
total_count = len(self.dataFrame[column_name])
# Append column information to the info_text
info_text += (f"Column Name: {column_name}\n"
f"Data Type: {data_type}\n"
f"Non-null Count: {non_null_count}/{total_count}\n"
f"----------------------------------------------\n")
# Create and show the DataInfo dialog
self.dataInfoForm = DataInfo.Ui_DataInfo(info_text)
self.dataInfoForm.setupUi()
self.dataInfoForm.load_DataInfo()
self.dataInfoForm.show()
except ValueError as ve:
QMessageBox.warning(None, "Value Error", f"An error occurred: {ve}")
except TypeError as te:
QMessageBox.warning(None, "Type Error", f"An error occurred: {te}")
except Exception as e:
QMessageBox.warning(None, "Error", f"An error occurred: {e}")
def grab_col_names(self, dataframe, cat_th=10, car_th=20):
"""
Identify and categorize column names based on their data types and cardinality.
This method takes a DataFrame as input and categorizes its columns into four groups:
categorical columns, numeric columns, categorical columns with high cardinality,
and numeric columns treated as categorical based on a threshold.
Args:
dataframe (pd.DataFrame): The DataFrame to analyze.
cat_th (int): Threshold for considering numeric columns as categorical.
Default is 10.
car_th (int): Threshold for considering categorical columns as high cardinality.
Default is 20.
Returns:
tuple: A tuple containing four lists:
1. Categorical columns
2. Numeric columns
3. Categorical columns with high cardinality
4. Numeric columns treated as categorical
Raises:
QMessageBox.warning: If an error occurs during column categorization,
a warning message dialog is displayed with details of the error.
"""
try:
# Categorical columns
cat_cols = [col for col in dataframe.columns if dataframe[col].dtype in ['category', 'object', 'bool']]
# Numeric but treated as categorical
num_but_cat = [col for col in dataframe.columns if dataframe[col].nunique() < cat_th
and dataframe[col].dtype in ['uint8', 'int64', 'float64']]
# Categorical but cardinal
cat_but_car = [col for col in dataframe.columns if dataframe[col].nunique() > car_th
and dataframe[col].dtype in ['category', 'object']]
cat_cols += num_but_cat
# Remove overlapping columns
cat_cols = [col for col in cat_cols if col not in cat_but_car]
# Numeric columns
num_cols = [col for col in dataframe.columns if col not in cat_cols]
return cat_cols, num_cols, cat_but_car, num_but_cat
except Exception as e:
# Handle any other unexpected exceptions
QMessageBox.warning(None, "Error", f"An error occurred: {e}")
def column_summary(self):
"""
Generate summaries for categorical and numerical columns in the dataset.
This method interacts with a graphical user interface (GUI) to load a dataset
using the Seaborn library, categorize columns, and provide summaries based on user input.
Returns:
None
Raises:
QMessageBox.warning: If an error occurs during data loading or display,
a warning message dialog is displayed to the user with
details of the error.
"""
try:
if self.dataFrame is not None:
# Get categorical and numerical columns
cat_cols, num_cols, _, _ = self.grab_col_names(self.dataFrame)
col_name = self.txt_summary_name.text()
info_text = ""
if col_name == "":
# Gather categorical data information
for column_name in self.dataFrame.columns:
ratios = 100 * self.dataFrame[column_name].value_counts() / len(self.dataFrame)
info_text += (
f"Ratio of {column_name}:\n{ratios}\n"
f"---------------------------------------------------------\n"
)
self.dataInfoForm = DataInfo.Ui_DataInfo(info_text)
self.dataInfoForm.setupUi()
self.dataInfoForm.load_DataInfo()
self.dataInfoForm.show()
# Check if the specified column name is in numerical columns
elif col_name != "":
if col_name in cat_cols:
# Generate summary for categorical column
if self.ckBox_summary_plot.isChecked():
# Show count plot with percentages
ax = sns.countplot(x=col_name, data=self.dataFrame)
for p in ax.patches:
height = p.get_height()
ratio = height / len(self.dataFrame) * 100
ax.annotate(f'{height} ({ratio:.2f}%)', (p.get_x() + p.get_width() / 2., height),
ha='center', va='center', fontsize=11, color='black', xytext=(0, 5),
textcoords='offset points')
plt.show(block=True)
else:
ratios = 100 * self.dataFrame[col_name].value_counts() / len(self.dataFrame)
info_text = (
f"Ratio of {column_name}:\n{ratios}\n"
f"---------------------------------------------------------\n"
)
self.dataInfoForm = DataInfo.Ui_DataInfo(info_text)
self.dataInfoForm.setupUi()
self.dataInfoForm.load_DataInfo()
self.dataInfoForm.show()
elif col_name in num_cols:
# Generate summary for numerical column
if self.ckBox_summary_plot.isChecked():
# Show histogram with KDE
sns.histplot(x=col_name, data=self.dataFrame, kde=True)
plt.show(block=True)
else:
ratios = 100 * self.dataFrame[col_name].value_counts() / len(self.dataFrame)
info_text = (
f"Ratio of {col_name}:\n{ratios}\n"
f"---------------------------------------------------------\n"
)
self.dataInfoForm = DataInfo.Ui_DataInfo(info_text)
self.dataInfoForm.setupUi()
self.dataInfoForm.load_DataInfo()
self.dataInfoForm.show()
else:
# Display a message for invalid column name
QMessageBox.warning(None, "Invalid Input", "The specified column name is not found in categorical or numerical columns.")
return
except ValueError as ve:
QMessageBox.warning(None, "Value Error", f"An error occurred: {ve}")
except TypeError as te:
QMessageBox.warning(None, "Type Error", f"An error occurred: {te}")
except Exception as e:
QMessageBox.warning(None, "Error", f"An error occurred: {e}")
def target_summary(self):
"""
Generate summary statistics of the target variable grouped by another column.
This method interacts with a graphical user interface (GUI) to load a dataset
using the Seaborn library, extract categorical and numerical columns, and generate
summary statistics of the target variable grouped by a specified column.
Returns:
None
Raises:
QMessageBox.warning: If an error occurs during data loading or display,
a warning message dialog is displayed to the user with
details of the error.
"""