Ivory Coast Mobile Data - socrateslab/zh GitHub Wiki
http://localhost:8888/notebooks/GitHub/datalab/code/IvorycoastMobile.ipynb
num = [1050, 423, 170, 95, 55, 36, 21, 17, 13, 10, 8, 6, 5, 4, 2, 1]
lb = range(1, 17)
def plotBoxPower(num, lb, colorline, label):
x = np.log(lb)
y = np.log(num)
xx = sm.add_constant(x, prepend=True)
res = sm.OLS(y,xx).fit()
constant,beta = res.params
r2 = res.rsquared
plt.plot(lb, num, colorline, label= label)
plt.plot(np.exp(x), np.exp(constant + x*beta),"-")
#plt.xlim =[2, 32]
plt.legend(loc=1,fontsize=10, numpoints=1)
plt.yscale('log');plt.xscale('log')
#plt.xticks([2, 4, 8, 16, 32], ['2', '4', '8', '16', '32'])
plt.xlabel(r'$l_{B}$')
plt.ylabel(r'Number of Boxes')
plt.axis('tight')
lb_max = (np.log(1)-constant)/beta
print constant, beta, r2, lb_max
def plotBoxExponential(num, lb, colorline, label):
x = lb
y = np.log(num)
xx = sm.add_constant(x, prepend=True)
res = sm.OLS(y,xx).fit()
constant,beta = res.params
r2 = res.rsquared
plt.plot(lb, num, colorline, label=label)
plt.plot(xx, np.exp(constant+xx*beta), 'r-')
plt.legend(loc=1,fontsize=10, numpoints=1)
plt.yscale('log')
plt.xlabel(r'$l_{B}$')
plt.ylabel(r'Number of Boxes')
lb_max = (np.log(1)-constant)/beta
print constant, beta, r2, lb_max
plotBoxPower(num, lb, 'ro', 'Ivory Coast Base Station' )