Python build simulation Model--number of site-independent access users

Source: Internet
Author: User

Background: It is interesting to find that some users visit the site only once every January, and we want to know how these people are changing.

Establish mathematical model: simplify the problem, according to URN model derivation formula (concrete deduction See "The Charm of data", there is time to add ...) ): N (t) =n (1-e^ (-k/n) *t), where T represents the day of the one month, and N represents the total number of potential visitors, K is the average daily number of visits calculated based on the site log, and N (t) represents the amount of users who visit this website at the end of T day.

Python simulation, and comparison with the analyzed model:

Import Mathimport random as Rndimport NumPy as Npimport matplotlib.pyplot as Pltn =1000  # Total number of potential users k =   # # Average Daily visit  Q Volume s = number   of daily possible traffic range Def trial (): Visitors_for_day = [0]  # No visitors in Day onehas_visited = [0]*n    # A Flag For each visitorfor day in range: Visitors_today = max (0,int (Rnd.gauss (K,s))) # Pick The individuals who visited today And Mark Themfor I in Rnd.sample (range (n), Visitors_today): has_visited[i] = # Find The total number if unique visitors so Farvisitors_for_day.append (sum (has_visited)) return visitors_for_dayfor T in range: R = Trial () XI = []yi = []for i in RA] Nge (Len (R)): Xi.append (i) yi.append (R[i]) print (I,r[i]) plt.plot (xi,yi, ' o ', alpha=0.3) x0 = Np.linspace (0.0,31.0,num= y0 = 1000* (MATH.E) * * ( -0.1*x0)) y_up = 1000* (n (MATH.E) * * ( -0.075*x0)) y_dn = 1000* (n (MATH.E) * * ( -0.125*x0)) Plt.plot (x0,y0, ' R ') Plt.plot (x0,y_up, ' b--', x0,y_dn, ' b--') plt.show ()

The output graph is as follows:

It seems like I'm starting to love matplotlib.

Python build simulation Model--number of site-independent access users

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.