Skip to content

Instantly share code, notes, and snippets.

@matmoody
Created April 21, 2016 04:07
Show Gist options
  • Save matmoody/63b42e843f8d699172aea5d628d06395 to your computer and use it in GitHub Desktop.
Save matmoody/63b42e843f8d699172aea5d628d06395 to your computer and use it in GitHub Desktop.
# Frequency
import collections
testlist = [1, 4, 5, 6, 7, 9, 9, 9]
c = collections.Counter(testlist)
print c
# calculate number of instances in list
count_sum = sum(c.values())
for k,v in c.iteritems():
print "Frequency of number " + str(k) + " is " + str(float(v) / count_sum))
# Generating a Box Plot
import matplotlib.pyplot as plt
%matplotlib inline
x = [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 5, 6, 6, 6, 7, 7,7,7,7, 7, 7, 8, 9, 9]
plt.boxplot(x)
plt.show()
# Generate a Histogram of data
plt.hist(x, histtype='bar')
plt.show()
# Generate QQ Plot
import scipy.stats as stats
plt.figure()
test_data = np.random.normal(size=1000)
graph1 = stats.probplot(test_data, dist='norm', plot=plt)
plt.title('Normal Distribution')
plt.show() # first graph
plt.figure
test_data2 = np.random.uniform(size=1000)
graph2 = stats.probplot(test_data2, dist='norm', plot=plt)
plt.title('Uniform Distribution')
plt.show() # second graph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment