เมื่อเราได้ Dataset ใหม่มา สิ่งแรกที่เราควรทำ คือ Exploratory Data Analysis (EDA) ทำความเข้าใจข้อมูล ในแต่ละ Feaure เช่น ข้อมูลเป็นชนิดอะไร, ข้อมูลเป็นแบบต่อเนื่องหรือไม่ต่อเนื่อง, ช่วงของข้อมูลกว้างแค่ไหน, การกระจายของข้อมูลเป็นอย่างไร, มีข้อมูลขาดหายไปเยอะแค่ไหน, แต่ละ Feature เชื่อมโยงกันอย่างไร
การวิเคราะห์ทั้งหมดนี้ค่อนข้างซับซ้อน และซ้ำซ้อนเหมือนกันในทุก ๆ Dataset จะมีวิธีไหนที่จะทำให้งานซ้ำ ๆ เหล่านี้ง่ายขึ้น
Pandas DataFrame.describe() ในการวิเคราะห์ข้อมูลแบบตาราง ปกติเราจะใช้ Pandas DataFrame และฟังก์ชันแรก ๆ ที่เราจะใช้ดูภาพรวมของตารางข้อมูล ก็คือ datarame.describe()
แต่ข้อเสียของ describe คือ output ออกมาเป็นตารางเดียวง่าย ๆ ที่มีข้อมูลน้อยเกินไป ทำให้เราต้องเขียนโปรแกรมเพิ่ม เพื่อเปรียบเทียบ เชื่อมโยงข้อมูลที่เราอยากรู้เอง ซึ่งก็เป็นงานซ้ำ ๆ กันที่ต้องทำคล้าย ๆ กันในทุก ๆ Dataset
Correlations of Adult Data Set Pandas Profiling เปรียบเทียบกับ DataFrame.describe() ที่ Output ออกมาเป็นตารางเดียวง่าย ๆ แต่ Pandas Profiling จะวิเคราะห์ข้อมูล Feature ต่าง ๆ ใน DataFrame แล้วจัดทำ Report เต็มรูปแบบ Output ออกมาเป็น HTML เป็นกราฟสวยงาม มีรายละเอียดดังนี้
Essentials : type, unique values, missing valuesQuantile statistics like minimum value, Q1, median, Q3, maximum, range, interquartile rangeDescriptive statistics like mean, mode, standard deviation, sum, median absolute deviation, coefficient of variation, kurtosis, skewnessMost frequent values Histogram Correlations highlighting of highly correlated variables, Spearman, Pearson and Kendall matricesMissing values matrix, count, heatmap and dendrogram of missing valuesเรามาเริ่มกันเลยดีกว่า
Install pandas_profiling ถ้ายังไม่ได้ Install
สำรวจข้อมูล ดูความสัมพันธ์เชื่อมโยงระหว่างข้อมูล ก่อนที่จะจัดเตรียมข้อมูล ป้อนให้กับโมเดลต่อไป
Out[0]:
Dataset info
Number of variables 15 Number of observations 32561 Total Missing (%) 0.2% Total size in memory 3.7 MiB Average record size in memory 120.0 B
Variables types
Numeric 6 Categorical 9 Boolean 0 Date 0 Text (Unique) 0 Rejected 0 Unsupported 0
Distinct count 73 Unique (%) 0.2% Missing (%) 0.0% Missing (n) 0 Infinite (%) 0.0% Infinite (n) 0
Mean 38.582 Minimum 17 Maximum 90 Zeros (%) 0.0%
Quantile statistics
Minimum 17 5-th percentile 19 Q1 28 Median 37 Q3 48 95-th percentile 63 Maximum 90 Range 73 Interquartile range 20
Descriptive statistics
Standard deviation 13.64 Coef of variation 0.35355 Kurtosis -0.16613 Mean 38.582 MAD 11.189 Skewness 0.55874 Sum 1256257 Variance 186.06 Memory size 254.5 KiB
Value Count Frequency (%) 36 898 2.8%
31 888 2.7%
34 886 2.7%
23 877 2.7%
35 876 2.7%
33 875 2.7%
28 867 2.7%
30 861 2.6%
37 858 2.6%
25 841 2.6%
Other values (63) 23834 73.2%
Minimum 5 values
Value Count Frequency (%) 17 395 1.2%
18 550 1.7%
19 712 2.2%
20 753 2.3%
21 720 2.2%
Maximum 5 values
Value Count Frequency (%) 85 3 0.0%
86 1 0.0%
87 1 0.0%
88 3 0.0%
90 43 0.1%
Distinct count 119 Unique (%) 0.4% Missing (%) 0.0% Missing (n) 0 Infinite (%) 0.0% Infinite (n) 0
Mean 1077.6 Minimum 0 Maximum 99999 Zeros (%) 91.7%
Quantile statistics
Minimum 0 5-th percentile 0 Q1 0 Median 0 Q3 0 95-th percentile 5013 Maximum 99999 Range 99999 Interquartile range 0
Descriptive statistics
Standard deviation 7385.3 Coef of variation 6.8532 Kurtosis 154.8 Mean 1077.6 MAD 1977.4 Skewness 11.954 Sum 35089324 Variance 54543000 Memory size 254.5 KiB
Value Count Frequency (%) 0 29849 91.7%
15024 347 1.1%
7688 284 0.9%
7298 246 0.8%
99999 159 0.5%
5178 97 0.3%
3103 97 0.3%
4386 70 0.2%
5013 69 0.2%
8614 55 0.2%
Other values (109) 1288 4.0%
Minimum 5 values
Value Count Frequency (%) 0 29849 91.7%
114 6 0.0%
401 2 0.0%
594 34 0.1%
914 8 0.0%
Maximum 5 values
Value Count Frequency (%) 25236 11 0.0%
27828 34 0.1%
34095 5 0.0%
41310 2 0.0%
99999 159 0.5%
Distinct count 92 Unique (%) 0.3% Missing (%) 0.0% Missing (n) 0 Infinite (%) 0.0% Infinite (n) 0
Mean 87.304 Minimum 0 Maximum 4356 Zeros (%) 95.3%
Quantile statistics
Minimum 0 5-th percentile 0 Q1 0 Median 0 Q3 0 95-th percentile 0 Maximum 4356 Range 4356 Interquartile range 0
Descriptive statistics
Standard deviation 402.96 Coef of variation 4.6156 Kurtosis 20.377 Mean 87.304 MAD 166.46 Skewness 4.5946 Sum 2842700 Variance 162380 Memory size 254.5 KiB
Value Count Frequency (%) 0 31042 95.3%
1902 202 0.6%
1977 168 0.5%
1887 159 0.5%
1848 51 0.2%
1485 51 0.2%
2415 49 0.2%
1602 47 0.1%
1740 42 0.1%
1590 40 0.1%
Other values (82) 710 2.2%
Minimum 5 values
Value Count Frequency (%) 0 31042 95.3%
155 1 0.0%
213 4 0.0%
323 3 0.0%
419 3 0.0%
Maximum 5 values
Value Count Frequency (%) 3004 2 0.0%
3683 2 0.0%
3770 2 0.0%
3900 2 0.0%
4356 3 0.0%
Distinct count 16 Unique (%) 0.0% Missing (%) 0.0% Missing (n) 0
HS-grad 10501
Some-college 7291
Bachelors 5355
Other values (13) 9414
Distinct count 17 Unique (%) 0.1% Missing (%) 1.5% Missing (n) 487 Infinite (%) 0.0% Infinite (n) 0
Mean 10.08 Minimum 1 Maximum 16 Zeros (%) 0.0%
Quantile statistics
Minimum 1 5-th percentile 5 Q1 9 Median 10 Q3 12 95-th percentile 14 Maximum 16 Range 15 Interquartile range 3
Descriptive statistics
Standard deviation 2.573 Coef of variation 0.25526 Kurtosis 0.62843 Mean 10.08 MAD 1.9024 Skewness -0.31347 Sum 323300 Variance 6.6203 Memory size 254.5 KiB
Value Count Frequency (%) 9.0 10349 31.8%
10.0 7184 22.1%
13.0 5277 16.2%
14.0 1692 5.2%
11.0 1365 4.2%
7.0 1153 3.5%
12.0 1049 3.2%
6.0 916 2.8%
4.0 640 2.0%
15.0 565 1.7%
Other values (6) 1884 5.8%
Minimum 5 values
Value Count Frequency (%) 1.0 51 0.2%
2.0 166 0.5%
3.0 328 1.0%
4.0 640 2.0%
5.0 506 1.6%
Maximum 5 values
Value Count Frequency (%) 12.0 1049 3.2%
13.0 5277 16.2%
14.0 1692 5.2%
15.0 565 1.7%
16.0 408 1.3%
Distinct count 21648 Unique (%) 66.5% Missing (%) 0.0% Missing (n) 0 Infinite (%) 0.0% Infinite (n) 0
Mean 189780 Minimum 12285 Maximum 1484705 Zeros (%) 0.0%
Quantile statistics
Minimum 12285 5-th percentile 39460 Q1 117830 Median 178360 Q3 237050 95-th percentile 379680 Maximum 1484705 Range 1472420 Interquartile range 119220
Descriptive statistics
Standard deviation 105550 Coef of variation 0.55617 Kurtosis 6.2188 Mean 189780 MAD 77608 Skewness 1.447 Sum 6179373392 Variance 11141000000 Memory size 254.5 KiB
Value Count Frequency (%) 203488 13 0.0%
123011 13 0.0%
164190 13 0.0%
113364 12 0.0%
121124 12 0.0%
148995 12 0.0%
126675 12 0.0%
111483 11 0.0%
155659 11 0.0%
190290 11 0.0%
Other values (21638) 32441 99.6%
Minimum 5 values
Value Count Frequency (%) 12285 1 0.0%
13769 1 0.0%
14878 1 0.0%
18827 1 0.0%
19214 1 0.0%
Maximum 5 values
Value Count Frequency (%) 1226583 1 0.0%
1268339 1 0.0%
1366120 1 0.0%
1455435 1 0.0%
1484705 1 0.0%
Distinct count 94 Unique (%) 0.3% Missing (%) 0.0% Missing (n) 0 Infinite (%) 0.0% Infinite (n) 0
Mean 40.437 Minimum 1 Maximum 99 Zeros (%) 0.0%
Quantile statistics
Minimum 1 5-th percentile 18 Q1 40 Median 40 Q3 45 95-th percentile 60 Maximum 99 Range 98 Interquartile range 5
Descriptive statistics
Standard deviation 12.347 Coef of variation 0.30535 Kurtosis 2.9167 Mean 40.437 MAD 7.5832 Skewness 0.22764 Sum 1316684 Variance 152.46 Memory size 254.5 KiB
Value Count Frequency (%) 40 15217 46.7%
50 2819 8.7%
45 1824 5.6%
60 1475 4.5%
35 1297 4.0%
20 1224 3.8%
30 1149 3.5%
55 694 2.1%
25 674 2.1%
48 517 1.6%
Other values (84) 5671 17.4%
Minimum 5 values
Value Count Frequency (%) 1 20 0.1%
2 32 0.1%
3 39 0.1%
4 54 0.2%
5 60 0.2%
Maximum 5 values
Value Count Frequency (%) 95 2 0.0%
96 5 0.0%
97 2 0.0%
98 11 0.0%
99 85 0.3%
marital-statusCategorical
Distinct count 7 Unique (%) 0.0% Missing (%) 0.0% Missing (n) 0
Married-civ-spouse 14976
Never-married 10683
Divorced 4443
Other values (4)
2459
native-countryCategorical
Distinct count 42 Unique (%) 0.1% Missing (%) 0.0% Missing (n) 0
United-States 29170
Mexico
643 ?
583Other values (39)
2165
Distinct count 16 Unique (%) 0.0% Missing (%) 1.6% Missing (n) 512
Prof-specialty 4073
Craft-repair
4028 Exec-managerial
4009Other values (12) 19939
Distinct count 5 Unique (%) 0.0% Missing (%) 0.0% Missing (n) 0
White 27816
Black
3124 Asian-Pac-Islander
1039Other values (2)
582
Distinct count 6 Unique (%) 0.0% Missing (%) 0.0% Missing (n) 0
Husband 13193
Not-in-family 8305
Own-child 5068
Other values (3) 5995
Distinct count 2 Unique (%) 0.0% Missing (%) 0.0% Missing (n) 0
Distinct count 2 Unique (%) 0.0% Missing (%) 0.0% Missing (n) 0
Distinct count 9 Unique (%) 0.0% Missing (%) 0.0% Missing (n) 0
Private 22696
Self-emp-not-inc
2541 Local-gov
2093Other values (6) 5231
age workclass fnlwgt education education-num marital-status occupation relationship race sex capital-gain capital-loss hours-per-week native-country salary 0 49 Private 101320 Assoc-acdm 12.0 Married-civ-spouse NaN Wife White Female 0 1902 40 United-States >=50k 1 44 Private 236746 Masters 14.0 Divorced Exec-managerial Not-in-family White Male 10520 0 45 United-States >=50k 2 38 Private 96185 HS-grad NaN Divorced NaN Unmarried Black Female 0 0 32 United-States <50k 3 38 Self-emp-inc 112847 Prof-school 15.0 Married-civ-spouse Prof-specialty Husband Asian-Pac-Islander Male 0 0 40 United-States >=50k 4 42 Self-emp-not-inc 82297 7th-8th NaN Married-civ-spouse Other-service Wife Black Female 0 0 50 United-States <50k
ดูรายการ Variable ที่ถูก Reject
เราสามารถ Save Profile Report เอาไว้ดูวันหลัง หรือเอาไปใช้งานนำเสนออื่น ๆ ได้
The ultimate test of your knowledge is your capacity to convey it to another.