hw08A.solution.pdf - lab09.solution CS 237 Homework 8 A Displaying Multivariate Data General Instructions Please complete this notebook by filling in

hw08A.solution.pdf - lab09.solution CS 237 Homework 8 A...

This preview shows page 1 - 4 out of 25 pages.

6/22/2019 lab09.solution 127.0.0.1:8889/notebooks/lab09.solution.ipynb 1/25 CS 237 Homework 8 A: Displaying Multivariate Data General Instructions Please complete this notebook by filling in solutions where indicated. Be sure to "Run All" from the Cell menu before submitting. You may use ordinary ASCII text to write your solutions, or (preferably) Latex. A nice introduction to Latex in Jupyter notebooks may be found here: (- primer/) As with previous homeworks, just upload a PDF file of this notebook. Instructions for converting to PDF may be found on the class web page right under the link for homework 1.
Image of page 1

Subscribe to view the full document.

6/22/2019 lab09.solution 127.0.0.1:8889/notebooks/lab09.solution.ipynb 2/25 In [1]: # General useful imports import numpy as np from numpy import arange,linspace, mean, var, std, sin, cos from numpy.random import random, randint, uniform, choice, binomial, geometric, poisson import math from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from matplotlib import cm import matplotlib.mlab as mlab from matplotlib.ticker import LinearLocator, FormatStrFormatter from collections import Counter #import pandas as pd % matplotlib inline # Basic Numpy statistical functions X = [1,2,3] # mean of a list mean(X) # might need to use np.mean, np.var, and np.std # population variance var(X) # sample variance ddof = delta degrees of freedom, df = len(X) - ddof var(X,ddof=1) # population standard deviation std(X) # sample standard deviation std(X,ddof=1) # Scipy statistical functions # Scipy Stats Library Functions, see: # from scipy.stats import norm,t,binom,geom,expon,poisson,uniform,bernoulli # Uniform over interval [0..1) # generate n random variates n=1000 uniform.rvs(size=n) # Bernoulli # generate n random variates p=0.5 bernoulli.rvs(p,size=n) # Binomial: X ~ B(n,p) # Example parameters k = 4 n = 10 p = 0.5 # Probability Mass Function: P(X = x) binom.pmf(k, n, p) # Cumulative Distribution Function: P(X <= x) binom.cdf(k, n, p)
Image of page 2
6/22/2019 lab09.solution 127.0.0.1:8889/notebooks/lab09.solution.ipynb 3/25 # Generate n random variates binom.rvs(n, p, size=n) # Geometric Distribution X ~ G(p) # Probability Mass Function: P(X = k) geom.pmf(k,p) # Cumulative Distribution Function: P(X <= k) geom.cdf(k,p) # Generate n random variates geom.rvs(p,size=n) # my own version of the previous which only generates rvs up to # a limit -- this is not the same as the original distribution but # useful for displaying data in which you want to fix the size of the display def geom_rvs(p=0.5,size=1,limit=20): if size ==1: x = geom.rvs(p) while x > = limit: x = geom.rvs(p) return x else : lst = [0] * size for k in range(size): x = geom.rvs(p) while x > = limit: x = geom.rvs(p) lst[k] = x return lst # Poisson Distribution X ~ Poisson(lam) lam = 2 k=3 # P(X = k) poisson.pmf(k,lam) # P(X <= k) poisson.cdf(k,lam) # P(X > k) poisson.sf(k,lam) # Generate n random variates poisson.rvs(lam,size=n) # Exponential # Example parameters lam = 2 # rate parameter beta = 1 / lam # mean k = 2 # Probability density function expon.pdf(k,scale=beta) # Cumulative Distribution Function: P(X <= k) expon.cdf(k,scale=beta) # P(X > k) expon.sf(k,scale=beta)
Image of page 3

Subscribe to view the full document.

Image of page 4

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes