Download presentation
Presentation is loading. Please wait.
1
Programming with data Lab 3
Wednesday, 14 Nov. 2018 Stelios Sotiriadis Prof. Alessandro Provetti
2
Visualization and Probabilities
3
Matplotlib For 2D data, visualization is readily available.
Against the range domain: from matplotlib import pyplot as plt plt.plot(values, color='green', marker='o', linestyle='solid') plt.title("Visualization of my list") plt.xlabel('position') plt.ylabel('value') plt.show()
4
Matplotlib import matplotlib.pyplot as plt plt.plot([1,2,3,4,5,6], [1,4,9,16,25,36], 'ro') plt.axis([0, 6, 0, 20]) plt.show()
5
Lab exercises
6
Present your results on binSearch
Generate lists of random integers, in ascending order, for n=1k, 2k, 4k, 8k. Generate random keys. Time the cumulative time of search only, find the average for each size. Plot it using matplotlib Save on a file
7
How platform and I/O influence timing
Run the same experiment by: omitting any print command Are results drastically different? Run the same experiment on a different computer. Plot the new results over a shorter range, a percentage of the previous results.
8
Exercise 1: Probabilities
Consult Joel Grus’ Data Science from Scratch for the ‘probability of having two baby girls example’ Run the program!
9
Exercise 2: Simulate coin tosses
Develop a function simulateTosses(n) that simulates n coin tosses as many as the user wants. Coin toss can be Head or Tail (randomly decided) e.g. simulateTosses(100) The output is the probability of having heads or tails in n tosses, in our example the probability of heads in 100 tosses could be for example 0.49 etc. Develop a function to run 100 times the simulateTosses(100). In other words, 100 repetitions where each one is the probability of heads when we toss 100 times. The function could be called: moreSimulations(n1,n2), where n1 refers to the number of times we want to simulate the simulateTosses(n). Generate a diagram like this (x axis: 0-n(100), y axis: 0-1). What do you observe? Increase the numbers! coinTosser.py
10
Exercise 3: Study secretary problem
The probability of selecting the best applicant in the classical secretary problem converges toward 1/e ≈ (approx.) Study the secretary.py code. The code solves the secretary problem in Python! Run the secretary problem by comparing two optimal stopping strategies n/e and 𝑛 . secretary.py | secretary1.py
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.