@@ -36,8 +36,13 @@ def __init__(self, dataset):
3636 # Formula for Standard Deviation
3737 self .deviation = (self .variance ** 0.5 )
3838
39-
40-
39+ # Formula to find Dataset Skewness
40+ self .skewness = (self .length / ((self .length - 1 ) * (self .length - 2 ))) * sum (((x - self .mean ) / self .deviation ) ** 3 for x in self .dataset )
41+
42+ # Formula to find Dataset
43+ self .kurtosis = (self .length * (self .length + 1 ) * sum (((x - self .mean ) / self .deviation ) ** 4 for x in self .dataset ) / ((self .length - 1 ) * (self .length - 2 ) * (self .length - 3 ))) - \
44+ (3 * (self .length - 1 ) ** 2 ) / ((self .length - 2 ) * (self .length - 3 ))
45+
4146 # Populate Grouped Table Frequency Data Method
4247 def PopulateGrouped (self ):
4348 # Initiating Used List
@@ -72,8 +77,8 @@ def PopulateGrouped(self):
7277 top .append (current_number )
7378
7479 # Append Class Bottom Limit
75- current_bot_limit = old_number - 0.5
76- bottom_limit .append (current_bot_limit )
80+ current_bottom_limit = old_number - 0.5
81+ bottom_limit .append (current_bottom_limit )
7782
7883 # Append Class Top Limit
7984 current_top_limit = current_number + 0.5
@@ -88,7 +93,7 @@ def PopulateGrouped(self):
8893 data_range .append (current_data_range )
8994
9095 # Adding Data Range Limit Of The Class Frequency
91- current_data_limit = f"{ current_bot_limit } ~ { current_top_limit } "
96+ current_data_limit = f"{ current_bottom_limit } ~ { current_top_limit } "
9297 data_limit .append (current_data_limit )
9398
9499 # Adding Data Midpoint of The Class Frequency
@@ -99,7 +104,7 @@ def PopulateGrouped(self):
99104 current_bot_cumulative_frequency = self .find_frequency (self .lowest , old_number )
100105 bot_cumulative_frequency .append (current_bot_cumulative_frequency )
101106
102- # Adding Bottom Cumulative Frequency of The Class
107+ # Adding Top Cumulative Frequency of The Class
103108 current_top_cumulative_frequency = self .find_frequency (old_number , self .highest )
104109 top_cumulative_frequency .append (current_top_cumulative_frequency )
105110
@@ -112,25 +117,72 @@ def PopulateGrouped(self):
112117 mode_index = [i for i , val in enumerate (frequency ) if val == max (frequency )]
113118 mode = [data_range [i ] for i in mode_index ]
114119
115- # Formula to find Dataset Skewness
116- skewness = (self .length / ((self .length - 1 ) * (self .length - 2 ))) * sum (((x - self .mean ) / self .deviation ) ** 3 for x in self .dataset )
117-
118- # Formula to find Dataset
119- kurtosis = (self .length * (self .length + 1 ) * sum (((x - self .mean ) / self .deviation ) ** 4 for x in self .dataset ) / ((self .length - 1 ) * (self .length - 2 ) * (self .length - 3 ))) - \
120- (3 * (self .length - 1 ) ** 2 ) / ((self .length - 2 ) * (self .length - 3 ))
121-
122120 # Append Processed Data into Data Attributes
123- self .grouped = ProcessedData (bottom , top , bottom_limit , top_limit ,
121+ self .grouped = ProcessedData (None , bottom , top , bottom_limit , top_limit ,
124122 frequency , data_range , data_limit , data_midpoint ,
125123 bot_cumulative_frequency , top_cumulative_frequency ,
126- relative_frequency , skewness , kurtosis , mode )
124+ relative_frequency , mode )
125+
126+ def PopulateSimple (self ):
127+ # Deleting Duplicate and Sort the Data
128+ data = sorted (set (self .dataset ))
129+
130+ # Initiating Used Variable
131+ top_limit = []
132+ bottom_limit = []
133+ frequency = []
134+ top_cumulative_frequency = []
135+ bot_cumulative_frequency = []
136+ relative_frequency = []
137+ mode = []
138+
139+ for current_class in data :
140+ # Bottom Limit of the Class
141+ current_top_limit = current_class + 0.5
142+ current_bottom_limit = current_class - 0.5
127143
144+ # Top Limit of the Class
145+ top_limit .append (current_top_limit )
146+ bottom_limit .append (current_bottom_limit )
147+
148+ # Calculate Current Class Frequency
149+ current_frequency = self .dataset .count (current_class )
150+ frequency .append (current_frequency )
151+
152+ # Calculate Current Class Bottom Cumulative Frequency
153+ current_bot_cumulative_frequency = self .find_frequency (self .lowest , current_class )
154+ bot_cumulative_frequency .append (current_bot_cumulative_frequency )
155+
156+ # Calculate Current Class Top Cumulative Frequency
157+ current_top_cumulative_frequency = self .find_frequency (current_class , self .highest )
158+ top_cumulative_frequency .append (current_top_cumulative_frequency )
159+
160+ # Calculate Current Class Relative Frequency
161+ current_relative_frequency = np .round ((current_frequency / self .length ) * 100 )
162+ relative_frequency .append (current_relative_frequency )
163+
164+ # Temukan modus
165+ mode_index = [i for i , val in enumerate (frequency ) if val == max (frequency )]
166+ mode = [data [i ] for i in mode_index ]
167+
168+ # Buat objek ProcessedData
169+ self .simple = ProcessedData (data , None , None , bottom_limit , top_limit ,
170+ frequency , None , None , None ,
171+ bot_cumulative_frequency , top_cumulative_frequency ,
172+ relative_frequency , mode )
173+
128174 # Base 5 Rounding
129175 def roundy (self , x , base = 5 ):
130176 return base * round (x / base )
131177
132178 # Function To Find Frequency in Dataset with Desired Range (Top and Down Limit)
133179 def find_frequency (self , bot , top ):
180+ try :
181+ bot = int (bot )
182+ top = int (top )
183+ except (ValueError , TypeError ) as e :
184+ print (f"Error converting to int: { e } " )
185+
134186 total_frequency = 0
135187 for i in range (bot , top + 1 ):
136188 frequency = self .dataset .count (i )
@@ -140,7 +192,8 @@ def find_frequency(self, bot, top):
140192# Processed Data Assignment
141193class ProcessedData :
142194 # Limit (L), Frequency (F), Ranges (R), Midpoint (M), Cumulative (C), Relative (R)
143- def __init__ (self , bot , top , bot_L , top_L , F , R , L , M , bot_CF , top_CF , RF , skew , kurt , mode ):
195+ def __init__ (self , data , bot , top , bot_L , top_L , F , R , L , M , bot_CF , top_CF , RF , mode ):
196+ self .classval = data
144197 self .bottom = bot
145198 self .top = top
146199 self .bottom_limit = bot_L
@@ -155,8 +208,6 @@ def __init__(self, bot, top, bot_L, top_L, F, R, L, M, bot_CF, top_CF, RF, skew,
155208 self .relative_frequency = RF
156209
157210 self .percentage_relative_frequency = [ f"{ rf * 1 :.2f} %" for rf in self .relative_frequency ]
158- self .skewness = skew
159- self .kurtosis = kurt
160211 self .mode = mode
161212
162213
0 commit comments