Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Individual Project

165 views
import random #imports random library, i will use for generation random numers import csv # improts csv library, used to load my deck of tarrot cards means are taken from http://www.daily-tarot-girl.com/tarot-card-meanings/list-of-tarot-card-meanings/ import numpy as np # imports numpy library and gives it the shorthand np, I will be using std to calulate the standard deviation of my results import matplotlib.pyplot as plt # imports matplotlib a tool for plotting grapths in this case barcharts and histograms from collections import Counter # imports counter from collections, will use counter to measure the frequency of the same results produced in various sample sizes f = open('Tarot.csv', 'r') # open the file in read mode data = csv.reader(f) #reads the data in to a list named data data = [row for row in data] # creates a list the entries by each row in the data f.close() # closes file to save memory Freq = [] sets = [] class Tarot(): """ A class to make a virtual Tarot deck. Atributes: a: the number of the card in the deck name: the name of the Tarot card associated with the card number meaning: the meaning of the card """ def __init__(self, a, name, meaning): # The init method is a standard method that lets us put arguments into a class for each instance in a list. self.a = int(a) self.name = name self.meaning = meaning Deck = [Tarot(row[0],row[1], row[2]) for row in data]
def Probs(self, n): """ chooses three Tarot cards for sample size n. Arguments: n : sample size as the range is set to n+1. output: appends all the results to the list sets """ for i in range (1 , n + 1): sample = random.sample(Deck, 3) for item in sample: sets.append(item.a)
def Reading(self): """ Give a three card Tarot reading. Arguments n/a output: prints the names and the meaning of the three cards drawn """ sample = random.sample(Deck, 3) for item in sample: print '%s, %s' % (item.name, item.meaning) Reading(Deck)
The Chariot , Movement, progress, integration Justice, Fairness, equality, balance Queen of Cups, Emotionally nurturing, intuitive, sensitive
Probs(Deck, 1000)
Freq = Counter(sets) Freq
Counter({42: 53, 3: 52, 40: 52, 72: 50, 54: 49, 60: 48, 32: 47, 66: 47, 9: 45, 48: 45, 75: 45, 7: 44, 11: 44, 27: 43, 43: 43, 0: 42, 1: 42, 29: 42, 30: 42, 51: 42, 63: 42, 35: 41, 41: 41, 58: 41, 37: 40, 38: 40, 65: 40, 76: 40, 6: 39, 47: 39, 52: 39, 13: 38, 18: 38, 20: 38, 21: 38, 22: 38, 25: 38, 36: 38, 53: 38, 55: 38, 57: 38, 59: 38, 67: 38, 2: 37, 4: 37, 23: 37, 34: 37, 49: 37, 50: 37, 62: 37, 64: 37, 77: 37, 24: 36, 31: 36, 56: 36, 61: 36, 5: 35, 10: 35, 17: 35, 19: 35, 26: 35, 69: 35, 71: 35, 16: 34, 14: 33, 15: 33, 28: 33, 44: 33, 8: 32, 45: 32, 73: 31, 74: 31, 12: 30, 68: 30, 39: 29, 33: 28, 46: 27, 70: 27})
width = 0.5 # sets the width of the bars in the bar chart plt.bar(range(len(Freq)), Freq.values(), align = 'center',width = width, color = 'rgbkymc') # plt.xticks(range(len(Freq)), Freq.keys(), size = 5.5, rotation = 90) plt.title ('Frequency of Tarot cards draw for sample size of 1000.') # title of graph plt.xlabel('Card Number') # x-axis label plt.ylabel('Frequency') # y-axis label plt.show() plt.savefig('Frequency.png') # saves the graph as a seperate file
<Container object of 78 artists> ([<matplotlib.axis.XTick object at 0x7f911f7fdb50>, <matplotlib.axis.XTick object at 0x7f911f7fd1d0>, <matplotlib.axis.XTick object at 0x7f911f7fd890>, <matplotlib.axis.XTick object at 0x7f911ef56650>, <matplotlib.axis.XTick object at 0x7f911ef56d90>, <matplotlib.axis.XTick object at 0x7f911ef66510>, <matplotlib.axis.XTick object at 0x7f911ef66c50>, <matplotlib.axis.XTick object at 0x7f911ef6f3d0>, <matplotlib.axis.XTick object at 0x7f911ef6fb10>, <matplotlib.axis.XTick object at 0x7f911eef9290>, <matplotlib.axis.XTick object at 0x7f911eef99d0>, <matplotlib.axis.XTick object at 0x7f911ef02150>, <matplotlib.axis.XTick object at 0x7f911ef02890>, <matplotlib.axis.XTick object at 0x7f911ef02fd0>, <matplotlib.axis.XTick object at 0x7f911ef0d750>, <matplotlib.axis.XTick object at 0x7f911ef0de90>, <matplotlib.axis.XTick object at 0x7f911ef15610>, <matplotlib.axis.XTick object at 0x7f911ef15d50>, <matplotlib.axis.XTick object at 0x7f911ef2b4d0>, <matplotlib.axis.XTick object at 0x7f911ef2bc10>, <matplotlib.axis.XTick object at 0x7f911ef31390>, <matplotlib.axis.XTick object at 0x7f911ef31ad0>, <matplotlib.axis.XTick object at 0x7f911f2cd250>, <matplotlib.axis.XTick object at 0x7f911f2cd990>, <matplotlib.axis.XTick object at 0x7f911f2d7110>, <matplotlib.axis.XTick object at 0x7f911f2d7850>, <matplotlib.axis.XTick object at 0x7f911f2d7f90>, <matplotlib.axis.XTick object at 0x7f911f2e2710>, <matplotlib.axis.XTick object at 0x7f911f2e2e50>, <matplotlib.axis.XTick object at 0x7f911f2ea5d0>, <matplotlib.axis.XTick object at 0x7f911f2ead10>, <matplotlib.axis.XTick object at 0x7f911f2f4490>, <matplotlib.axis.XTick object at 0x7f911f2f4bd0>, <matplotlib.axis.XTick object at 0x7f911f2ff350>, <matplotlib.axis.XTick object at 0x7f911f2ffa90>, <matplotlib.axis.XTick object at 0x7f911f309210>, <matplotlib.axis.XTick object at 0x7f911f309950>, <matplotlib.axis.XTick object at 0x7f911e3eb0d0>, <matplotlib.axis.XTick object at 0x7f911e3eb810>, <matplotlib.axis.XTick object at 0x7f911e3ebf50>, <matplotlib.axis.XTick object at 0x7f911e3f66d0>, <matplotlib.axis.XTick object at 0x7f911e3f6e10>, <matplotlib.axis.XTick object at 0x7f911e400590>, <matplotlib.axis.XTick object at 0x7f911e400cd0>, <matplotlib.axis.XTick object at 0x7f911e409450>, <matplotlib.axis.XTick object at 0x7f911e409b90>, <matplotlib.axis.XTick object at 0x7f911e413310>, <matplotlib.axis.XTick object at 0x7f911e413a50>, <matplotlib.axis.XTick object at 0x7f911e41d1d0>, <matplotlib.axis.XTick object at 0x7f911e41d910>, <matplotlib.axis.XTick object at 0x7f911e0a9090>, <matplotlib.axis.XTick object at 0x7f911e0a97d0>, <matplotlib.axis.XTick object at 0x7f911e0a9f10>, <matplotlib.axis.XTick object at 0x7f911e0b4690>, <matplotlib.axis.XTick object at 0x7f911e0b4dd0>, <matplotlib.axis.XTick object at 0x7f911e0be550>, <matplotlib.axis.XTick object at 0x7f911e0bec90>, <matplotlib.axis.XTick object at 0x7f911e0c8410>, <matplotlib.axis.XTick object at 0x7f911e0c8b50>, <matplotlib.axis.XTick object at 0x7f911e0d32d0>, <matplotlib.axis.XTick object at 0x7f911e0d3a10>, <matplotlib.axis.XTick object at 0x7f911e0dd190>, <matplotlib.axis.XTick object at 0x7f911e0dd8d0>, <matplotlib.axis.XTick object at 0x7f911e026050>, <matplotlib.axis.XTick object at 0x7f911e026790>, <matplotlib.axis.XTick object at 0x7f911e026ed0>, <matplotlib.axis.XTick object at 0x7f911e031650>, <matplotlib.axis.XTick object at 0x7f911e031d90>, <matplotlib.axis.XTick object at 0x7f911e03a510>, <matplotlib.axis.XTick object at 0x7f911e03ac50>, <matplotlib.axis.XTick object at 0x7f911e0443d0>, <matplotlib.axis.XTick object at 0x7f911e044b10>, <matplotlib.axis.XTick object at 0x7f911e04e290>, <matplotlib.axis.XTick object at 0x7f911e04e9d0>, <matplotlib.axis.XTick object at 0x7f911e05a150>, <matplotlib.axis.XTick object at 0x7f911e05a890>, <matplotlib.axis.XTick object at 0x7f911e05afd0>, <matplotlib.axis.XTick object at 0x7f911e063750>], <a list of 78 Text xticklabel objects>) <matplotlib.text.Text object at 0x7f911e36aa90> <matplotlib.text.Text object at 0x7f9166d78250> <matplotlib.text.Text object at 0x7f911f7fdd90>
np.std([Freq.values()])
5.6197734868402405
Deviation = [ ] sets = [] sample_size = [] def std_of_samplesize(self): """ uses probs to find the standard deviation of sample size form 10000 to 500000 in 10000 increments Arguments: uses the probs def to take sample size of the range and outputs the results into the list sets . output: appends size of the sample to the list sample_size takes the list sets and counts the frequency each card is draw inputs the standard deviation of the frequency a certain card is draw into list Deviation. """ for i in range(1 , 51): Probs(Deck, 10000) sample_size.append(10000 * i) Freq = Counter(sets) Deviation.append(np.std([Freq.values()]))
std_of_samplesize(Deck)
sample_size Deviation
[10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 110000, 120000, 130000, 140000, 150000, 160000, 170000, 180000, 190000, 200000, 210000, 220000, 230000, 240000, 250000, 260000, 270000, 280000, 290000, 300000, 310000, 320000, 330000, 340000, 350000, 360000, 370000, 380000, 390000, 400000, 410000, 420000, 430000, 440000, 450000, 460000, 470000, 480000, 490000, 500000] [21.238710889239162, 29.950781453322627, 39.608363828957906, 42.331322072460324, 47.16712491326799, 51.06865858377671, 51.799987053831586, 53.071738877255761, 55.469948507067556, 56.225981065211855, 58.915176547417829, 62.109132812318549, 67.246580315303504, 67.714565105420064, 72.376849088805102, 76.088355678267135, 79.3996209232849, 77.715749192707563, 78.667966258111534, 79.500896252375455, 83.544824331515741, 80.612350696482153, 83.625397461487253, 86.299407710616165, 90.776738064164988, 93.954162310057427, 96.947676975809571, 99.899298408373227, 102.12047647742509, 104.32145737779938, 101.68210507801578, 104.90622279852633, 108.62736913616102, 109.9106594339203, 111.52643613335584, 109.92807402827576, 110.10879504182276, 112.47737445065835, 113.59712889112863, 117.52427253596798, 120.19961208573898, 119.9306505725103, 123.31996036033328, 124.31646643317201, 122.66635044123549, 126.32084787355993, 125.68201319924265, 124.85085382245988, 121.4096769812616, 121.65703401385926]
StandardError = [Deviation[i] / sqrt(sample_size[i]) for i in range(len(Deviation))] StandardError
[0.21238710889239162, 0.14975390726661314*sqrt(2), 0.1320278794298597*sqrt(3), 0.21165661036230163, 0.09433424982653599*sqrt(5), 0.08511443097296119*sqrt(6), 0.0739999815054737*sqrt(7), 0.1326793471931394*sqrt(2), 0.18489982835689187, 0.05622598106521186*sqrt(10), 0.05355925140674348*sqrt(11), 0.10351522135386426*sqrt(3), 0.05172813870407962*sqrt(13), 0.04836754650387148*sqrt(14), 0.048251232725870064*sqrt(15), 0.19022088919566785, 0.046705659366638175*sqrt(17), 0.12952624865451262*sqrt(2), 0.04140419276742712*sqrt(19), 0.07950089625237546*sqrt(5), 0.03978324968167416*sqrt(21), 0.03664197758931007*sqrt(22), 0.036358868461516196*sqrt(23), 0.07191617309218014*sqrt(6), 0.18155347612832998, 0.03613621627309901*sqrt(26), 0.10771964108423286*sqrt(3), 0.0713566417202666*sqrt(7), 0.03521395740600865*sqrt(29), 0.03477381912593312*sqrt(30), 0.032800679057424446*sqrt(31), 0.1311327784981579*sqrt(2), 0.03291738458671546*sqrt(33), 0.032326664539388324*sqrt(34), 0.03186469603810167*sqrt(35), 0.18321345671379294, 0.029759133795087232*sqrt(37), 0.029599309065962722*sqrt(38), 0.02912746894644324*sqrt(39), 0.05876213626798399*sqrt(10), 0.029316978557497313*sqrt(41), 0.028554916802978645*sqrt(42), 0.02867906054891472*sqrt(43), 0.056507484742350914*sqrt(11), 0.08177756696082367*sqrt(5), 0.027461053885556506*sqrt(46), 0.026740853872179286*sqrt(47), 0.10404237818538324*sqrt(3), 0.17344239568751657, 0.12165703401385926*sqrt(2)]
︠d8d95c21-b90d-470c-b72d-657678b92371︠ x1 = sample_size y1= StandardError plt.plot(x1, y1, 'kx') plt.title ('Graph to show standard sample error.') # title of graph plt.xlabel('Sample size') # x-axis label plt.ylabel('Standard Sample Error') # y-axis label bestfit = np.polyfit(x1, y1, 3) x2 = np.arange(min(x1) - 100, max(x1) + 100, 5000) #use more points for a smoother plot (i.e creates a line consisting of 5000 points) and extends the range of x1 by the user defined amount. y2 = np.polyval(bestfit, x2) #calculates the polynomial for each x2 value, will be used to plot the best fit. plt.plot(x2, y2, label = "deg=3") # plots the cubic line of best fit plt.show() plt.savefig('Longterm.png')
[<matplotlib.lines.Line2D object at 0x7f911f2e2c50>] <matplotlib.text.Text object at 0x7f911ef0d750> <matplotlib.text.Text object at 0x7f911e737b50> <matplotlib.text.Text object at 0x7f911ef9b690> [<matplotlib.lines.Line2D object at 0x7f911f2ea050>]