In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to realize the commercial street lucky draw by python". In the daily operation, I believe that many people have doubts about how to realize the commercial street lucky draw by python. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to realize the shopping street lucky draw by python". Next, please follow the editor to study!
Simulation experiment and analysis
For the problems, first of all, a simulation experiment is carried out through python to see how many first prizes will appear in a hundred lucky draws.
Import pandas as pd
From collections import Counter
Choujiang = pd.Series (["not winning", "first prize"])
Cnt = Counter (choujiang.sample (nasty 100) replacewriting TrueJournal weights = ([99 ~ 1])
Cnt
Sample is a function in pandas, and its function is random sampling.
Replace=True indicates that there is a sample to put back.
Weights denotes value weight
Counter is a function in collections, and its function is to calculate the number of different values in array.
Run it three times, and the results are:
Counter ({'first prize': 1, 'not winning': 99})
Counter ({'not winning': 100})
Counter ({'first prize': 2, 'not winning': 98})
In conclusion, the probability of winning the lottery is 1%, which does not mean that there is bound to be a first prize for 100 times.
The above example simulates 100 electronic lotteries with a 1% winning rate. Repeat the simulation 7 times, that is, the simulation of the lucky draw within one week. By simulating the results of the 1000-week lottery by computer, we can count the number of weeks in which there are five first prizes in 1000 weeks.
Import numpy as np
# simulate the lottery for 1000 weeks
A = np.zeros (1000)
For i in range (1000):
For j in range (7):
A [I] = np.sum (choujiang.sample (nasty 100 replaceful Trueweight = ([99 ~ 1])) = "first prize") + a [I]
# draw a histogram
Import pylab
Pylab.hist (a, bins=18, normed=0,edgecolor='black',facecolor='blue',alpha=0.75)
Pylab.show ()
Np.transpose (Counter (a))
Simulate the lottery for 1000 weeks, calculate the number of times of the first prize, and draw a histogram. In the picture, the horizontal axis represents the number of times of the first prize, and the vertical axis represents the number of weeks.
Array (Counter ({7.0: 151,6.0: 140,8.0: 138,5.0: 130,9.0: 96,4.0: 91,10.0: 81,3.0: 53,11.0: 37,12.0: 26,2.0: 23,13.0: 13,14.0: 7,1.0: 7,15.0: 3,0.0: 3,18.0: 1}), dtype=object)
The above results show the frequency distribution in the figure. It can be seen that the total number of weeks with five first prizes in a week is 130,130 divided by 1000, which is 13%, that is, the number of weeks with five first prizes accounts for 13% of the total. If the occurrence of five times is fraudulent, and the occurrence of less than five times is also fraudulent, it accounts for 30% of the total, and the probability is too high. Therefore, only five first prizes in a week can not be considered fraudulent.
A few small concepts
Probability: for the lucky draw in the example, the probability of winning the lottery is 1%, but 700 draw does not necessarily lead to 7 grand prizes.
Frequency distribution table: count the number of data consistent with a certain value, or the number of data within a certain range of values, and then make a list of these statistics.
Histogram: a graphical table of frequency distribution.
Distribution of data: if the data is divided into several ranges, then the distribution of the data within each range becomes the distribution. For most of the data, the frequency of the range in which the average is located is the highest, and the greater the difference between the average and the range, the lower the frequency.
At this point, the study on "how to realize the shopping street lottery by python" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.