Skip to content

Frequency Table

Japip edited this page Oct 18, 2024 · 5 revisions

Frequency Table

The Frequency Table module is responsible for classifying and analyzing datasets. It provides methods to calculate frequency distributions for both grouped and simple data, ensuring robust statistical analysis. Below are the key features and methods of the module:

Features

  • Data Integrity Check: The constructor checks for mixed data types (numeric and strings) and raises a ValueError if found.
  • Statistics Calculation: Computes basic statistics such as sum, mean, median, variance, standard deviation, skewness, and kurtosis.
  • Frequency Distribution: Supports both grouped and simple frequency distributions.
  • Cumulative Frequencies: Computes bottom and top cumulative frequencies for both grouped and simple data.

Classify Class

class Classify:
    def __init__(self, dataset):
        ...
  • Initialization: Takes a dataset as input and calculates key statistics, ensuring the data is valid.

Methods

  • _calculate_statistics():

    • Computes the sum, mean, median, variance, standard deviation, skewness, and kurtosis of the dataset.
  • _calculate_classes():

    • Determines the number of classes, range, interval, and base value for the frequency table.
  • roundy(x, base=5):

    • Rounds a number to the nearest specified base (default is 5).
  • reset():

    • Clears all internal attributes related to frequency distribution.
  • find_frequency(bot, top):

    • Returns the frequency of data points within the specified range.
  • populate_grouped():

    • Populates the frequency table for grouped data and calculates cumulative frequencies, relative frequencies, and mode.
  • populate_simple():

    • Populates the frequency table for simple data and calculates cumulative frequencies, relative frequencies, and mode.

Example Usage

# Example of using the Classify module
data = [1, 2, 2, 3, 4, 4, 4, 5]
classifier = Classify(data)

# Grouped frequency distribution
classifier.populate_grouped()

# Simple frequency distribution
classifier.populate_simple()

Result Object

Both populate_grouped and populate_simple methods create a Result object, which contains all relevant information about the frequency distribution.

Clone this wiki locally