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