2021-06-07 python statistics

# -*- coding: utf-8 -*-
"""
Created on Mon Jun  7 02:02:24 2021

@author: Quan Wang(Sunny)
"""


import numpy as np 
import matplotlib.pyplot as plt 
import pymc as mc 

std_height = 12
mean_height = 150

n_counties = 5000
pop_generator = mc.rdiscrete_uniform
norm = mc.rnormal

#generato some artificaal population numbers

population = pop_generator(100,1500, size= n_counties)

average_across_county = np.zeros(n_counties)

for i in range(n_counties):
    average_across_county[i] = norm(mean_height, 1./std_height**2, size = population[i]).mean()
    

i_min=np.argmin(average_across_county)
i_max=np.argmax(average_across_county)

#plotpopulationvs.averag
plt.scatter(population,average_across_county,alpha=0.5,c="#7A68A6")
plt.scatter([population[i_min],population[i_max]],[average_across_county[i_min],average_across_county[i_max]],s=60,marker="o",facecolors="none",edgecolors="#A60628",linewidths=1.5,label="extremeheights")

image.png

你可能感兴趣的:(2021-06-07 python statistics)