 LFD Book Forum HW2 Q1 (generating a binomial distribution)

#1
 vahuja4 Junior Member Join Date: Jan 2017 Posts: 1 HW2 Q1 (generating a binomial distribution)

Hi All,

Here is the code I wrote for hw2_q1:

from random import randint
import seaborn as sns
import numpy as np

N = 100000
v_first = np.zeros(N)
v_min = np.zeros(N)
v_rand = np.zeros(N)
#Loop starts

for i in range(N):

n,p = 10, 0.5
flips = np.random.binomial(n, p, 1000)

first_coin = 0
min_coin = np.argmin(flips)
rand_coin = np.random.randint(0,1000)

v_first[i] = flips[first_coin]
v_min[i] = flips[min_coin]
v_rand[i] = flips[rand_coin]

#Loop ends

print np.average(v_min)

My answer turns out to be 0.367, while the correct answer is 0.01. Could someone please point out where I am going wrong?
#2
 willgao Junior Member Join Date: Jun 2017 Location: Atlanta Posts: 1 Re: HW2 Q1 (generating a binomial distribution)

Quote:
 nu is the fraction, not the number of the head count. Thread Tools Show Printable Version Email this Page Display Modes Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home General     General Discussion of Machine Learning     Free Additional Material         Dynamic e-Chapters         Dynamic e-Appendices Course Discussions     Online LFD course         General comments on the course         Homework 1         Homework 2         Homework 3         Homework 4         Homework 5         Homework 6         Homework 7         Homework 8         The Final         Create New Homework Problems Book Feedback - Learning From Data     General comments on the book     Chapter 1 - The Learning Problem     Chapter 2 - Training versus Testing     Chapter 3 - The Linear Model     Chapter 4 - Overfitting     Chapter 5 - Three Learning Principles     e-Chapter 6 - Similarity Based Methods     e-Chapter 7 - Neural Networks     e-Chapter 8 - Support Vector Machines     e-Chapter 9 - Learning Aides     Appendix and Notation     e-Appendices

All times are GMT -7. The time now is 06:41 AM. The contents of this forum are to be used ONLY by readers of the Learning From Data book by Yaser S. Abu-Mostafa, Malik Magdon-Ismail, and Hsuan-Tien Lin, and participants in the Learning From Data MOOC by Yaser S. Abu-Mostafa. No part of these contents is to be communicated or made accessible to ANY other person or entity.