<jupyter_start><jupyter_text>Building a Gaussian ClassIn the following notebook I will explain how to build a class that can output useful mathematical information.I will first break the problem into parts and explain the mathematics behind each function.Than I will put everything together to create a class.  Provided is an outline of what will be covered:- Mean- Standard deviation- Histograms- Probability density function  Dependecies<jupyter_code>import math
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>The MeanExplain the mean  The Standard DeviationExplain the standard deviation  HistogramsExplain histograms  Probabilty Density FunctionExplain the probability density function  Putting it all together<jupyter_code>class Gaussian():
    '''
    Gaussian distribution class for calculating and
    visualizing a Gaussian distributions
    
    -----------------------------------------------
    Attributes:
        mean (float) - returns the mean value of the distribution
        stdev (float) - returns the standard deviation of the distribution
        data_list (list of floats) - returns a list of floats extracted from the data file
    '''
    def __init__(self, mu = 0, sigma = 1):
        
        self.mean = mu
        self.stdev = sigma
        self.data = []
        
    def calculate_mean(self):
        
        '''
        Function to calculate the mean of the data set.
        
        Returns:
            float - Mean of the data set
        '''
        
        avg = 1.0 * sum(self.data) / len(self.data)
        
        self.mean = avg
        
        return self.mean
    
    def calculate_stdev(self, sample=True):
        
        '''
        Function to calculate the standard deviation of the data set.
        
        Args:
            sample(bool) - weather the data represents a sample or population
            
        Returns:
            float - standard deviation of the data set
        
        '''
        if sample:
            n = len(self.data) - 1
        else:
            n = len(self.data)
            
        mean = self.mean
        
        sigma = 0
        
        for number in self.data:
            sigma += (number - mean)**2
            
        sigma = math.sqrt(sigma / n)
        
        self.stdev = sigma
        
        return self.stdev
    
    def read_data_file(self, file_name, sample=True):
        '''
        Function to read in data from a txt file. The txt file should have one
        number (float) per line. The numbers are stored in the data attribute.
        After reading in the file, the mean and standard deviation are calculated.
        
        Args:
            file_name(string) - name of a file to read from
            
        Returns:
            None
        
        '''
        
        with open(file_name) as file:
            data_list = []
            line = file.readline()
            while line:
                data_list.append(int(line))
                line = file.readline()
        file.close()
        
        self.data = data_list
        self.mean = self.calculate_mean()
        self.stdev = self.calculate_stdev()
        
    def plot_histogram(self):
        
        '''
        Function to output a histogram of the instance variable data using
        matplotlib pyplot library.
        
        Args:
            None
            
        Returns:
            None
        '''
        plt.hist(self.data)
        plt.title("Histogram of Data")
        plt.xlabel("Data")
        plt.ylabel("Counts")
        
    def pdf(self, x):
        '''
        Probability density function calculator for the gaussian distribution.
        
        Args:
            x(float) - Point for calculating the probability density function
            
        Returns:
            float - Probability density function output
        
        '''
        
        return (1.0 / (self.stdev * math.sqrt(2*math.pi))) * math.exp(-0.5 * ((x - self.mean) / self.stdev)**2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07882382011366444, 'fraction_numerical': 0.0032122559920929085, 'mean_word_length': 1.616677440206852, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '454490', 'license': 'MIT', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1010, 'n_words': 359, 'path': 'Gaussian-Notebook.ipynb', 'repo_name': 'RNEnriquez/Building-Packages-with-Python', 'size': '4047'}