GithubHelp home page GithubHelp logo

dsc-2-22-03-mle-gaussian-lab-data-science's Introduction

MLE with Normal Distributions - Lab

Introduction

In this lab, we shall put in practice, the mathematical formulas we saw in previous lesson to see how MLE works with normal distributions.

Objectives

You will be able to:

  • Understand and describe how MLE works with normal distributions
  • Fit a normal distribution to given data identifying mean and variance
  • Visually compare the fitted distribution vs. real distribution

Note: *A detailed derivation of all MLE equations with proofs can be seen at this website. *

MLE in Python

Let's see an example of MLE and distribution fittings with Python below. Here scipy.stats.norm.fit calculates the distribution parameters using Maximum Likelihood Estimation.

Import necessary libraries

from scipy.stats import norm # for generating sample data and fitting distributions
import matplotlib.pyplot as plt
plt.style.use('seaborn')
import numpy as np

Generate an array of 200 random sample from a normal dist with mean 0 and stdv 1

sample = None

Distribution fitting through MLE

- Use stats.norm.fit(data) to fit a distribution to above data.

- This returns a list of two parameters : (mean,: parameters[0] and std: parameters[1]) via a MLE approach

param = None

#param[0], param[1]
# (0.08241224761452863, 1.002987490235812)

Calculate the PDF from a) actual data parameters b) fitted parameters with x = np.linspace(-5,5,100)

x = np.linspace(-5,5,100)

# Generate the pdf from fitted parameters (fitted distribution)
fitted_pdf = None
# Generate the pdf without fitting (normal distribution non fitted)
normal_pdf = None

Visualize both PDFs

# Your code here 

png

#  Your comments/observations

Summary

In this short lab, we looked at Bayesian setting in a Gaussian context i.e. when the underlying random variables are normally distributed. We learned that MLE can estimate the unknown parameters of a normal distribution, by maximizing the likelihood of expected mean. The expected mean comes very close to the mean of a non-fitted normal distribution within that parameter space. We shall move ahead with this understanding towards learning how such estimations are performed in estimating means of a number of classes present in the data distribution using Naive Bayes Classifier.

dsc-2-22-03-mle-gaussian-lab-data-science's People

Contributors

loredirick avatar shakeelraja avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.