├── README.md ├── distance.m ├── distance2.m ├── Geocode.py ├── Gaussian.py └── Gaussian density.m /README.md: -------------------------------------------------------------------------------- 1 | # Baidu-API- 2 | 调用Baidu API,将中文地址转化为经纬坐标。 3 | -------------------------------------------------------------------------------- /distance.m: -------------------------------------------------------------------------------- 1 | lng=xlsread('/Users/CheneyWu/Downloads/Trans_before2015.xlsx','B1:B3045'); 2 | lat=xlsread('/Users/CheneyWu/Downloads/Trans_before2015.xlsx','C1:C3045'); 3 | n=3045; 4 | D = zeros(n,n); 5 | Dis = []; 6 | count = 1; 7 | for i = 1:n-1 8 | for j = i+1:n 9 | D(i,j) = acos(sind(lat(i)).*sind(lat(j)).*cosd(lng(i)-lng(j))+cosd(lat(i)).*cosd(lat(j))); 10 | Dis(count) = 6371004*D(i,j)*pi/180; 11 | count = count + 1; 12 | end 13 | end 14 | count 15 | 16 | -------------------------------------------------------------------------------- /distance2.m: -------------------------------------------------------------------------------- 1 | lng=xlsread('/Users/CheneyWu/Downloads/Trans_before2015.xlsx','B1:B3000'); 2 | lat=xlsread('/Users/CheneyWu/Downloads/Trans_before2015.xlsx','C1:C3000'); 3 | n=3000; 4 | D = zeros(n,n); 5 | Dis2 = []; 6 | count = 1; 7 | for i = 1:n-1 8 | for j = i+1:n 9 | D(i,j) = acos(sind(lat(i)).*sind(lat(j)).*cosd(lng(i)-lng(j))+cosd(lat(i)).*cosd(lat(j))); 10 | Dis2(count) = 6371004*D(i,j)*pi/180; 11 | count = count + 1; 12 | end 13 | end 14 | %xlswrite('/Users/CheneyWu/Downloads/result.csv',Dis2') 15 | count -------------------------------------------------------------------------------- /Geocode.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Wed Feb 21 20:53:30 2018 4 | 5 | @author: lenovo 6 | """ 7 | 8 | import pandas 9 | import requests 10 | import time 11 | 12 | def sleeptime(hour,min,sec): 13 | return hour*3600 + min*60 + sec 14 | 15 | 16 | second = sleeptime(0,0,5) 17 | 18 | 19 | def geocodeB(address): 20 | base = "http://api.map.baidu.com/geocoder/v2/?address=" + address + "&output=json&ak=OKWAWaari951BdpxcQNvz1p8KUZ9nGLE" 21 | response = requests.get(base) 22 | answer = response.json() 23 | return answer['result']['location']['lng'],answer['result']['location']['lat'] 24 | 25 | 26 | datab = pandas.read_excel('/Users/CheneyWu/Downloads/Trans_2012-2016.xlsx') 27 | database = datab.ad 28 | 29 | geocode = [] 30 | for i in range(19,25): 31 | time.sleep(second) 32 | for j in range(200*i,200*i+200): 33 | address = datab.ad[j] 34 | try: 35 | geocode.append(geocodeB(address)) 36 | except: 37 | geocode.append('ConnectionError)') 38 | print(geocode) -------------------------------------------------------------------------------- /Gaussian.py: -------------------------------------------------------------------------------- 1 | #coding:utf-8 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | import seaborn as sns 5 | import pandas as pd 6 | from sklearn.neighbors import KernelDensity 7 | ''' 8 | np.random.seed(1) 9 | N = 20 10 | X = np.concatenate((np.random.normal(0, 1, 6),np.random.normal(5, 1, 14)))[:, np.newaxis] 11 | X_plot = np.linspace(-5, 10, 1000)[:, np.newaxis] 12 | bins = np.linspace(-5, 10, 10) 13 | fig, ax = plt.subplots(2, 2, sharex=True, sharey=True) 14 | fig.subplots_adjust(hspace=0.05, wspace=0.05) 15 | 16 | # 直方图 1 'Histogram' 17 | ax[0, 0].hist(X[:, 0], bins=bins, fc='#AAAAFF', normed=True) 18 | ax[0, 0].text(-3.5, 0.31, 'Histogram') 19 | 20 | # 直方图 2 'Histogram, bins shifted' 21 | ax[0, 1].hist(X[:, 0], bins=bins + 0.75, fc='#AAAAFF', normed=True) 22 | ax[0, 1].text(-3.5, 0.31, 'Histogram, bins shifted') 23 | 24 | # 核密度估计 1 'tophat KDE' 25 | kde = KernelDensity(kernel='tophat', bandwidth=0.75).fit(X) 26 | log_dens = kde.score_samples(X_plot) 27 | ax[1, 0].fill(X_plot[:, 0], np.exp(log_dens), fc='#AAAAFF') 28 | ax[1, 0].text(-3.5, 0.31, 'Tophat Kernel Density') 29 | 30 | # 核密度估计 2 'Gaussian KDE' 31 | kde = KernelDensity(kernel='gaussian', bandwidth=0.75).fit(X) 32 | log_dens = kde.score_samples(X_plot) 33 | ax[1, 1].fill(X_plot[:, 0], np.exp(log_dens), fc='#AAAAFF') 34 | ax[1, 1].text(-3.5, 0.31, 'Gaussian Kernel Density') 35 | for axi in ax.ravel(): 36 | axi.plot(X[:, 0], np.zeros(X.shape[0]) - 0.01, '+k') 37 | axi.set_xlim(-4, 9) 38 | axi.set_ylim(-0.02, 0.34) 39 | for axi in ax[:, 0]: 40 | axi.set_ylabel('Normalized Density') 41 | for axi in ax[1, :]: 42 | axi.set_xlabel('x') 43 | plt.show() 44 | ''' 45 | 46 | sns.set(style="white", palette="muted", color_codes=True) 47 | 48 | train = pd.read_csv('result.csv')#导入数据集 49 | ax1=sns.kdeplot(train,color='r') -------------------------------------------------------------------------------- /Gaussian density.m: -------------------------------------------------------------------------------- 1 | 2 | x1 = [8,4,0,6,1,1,4231,3,1,1,0,0,1353,0,1,1,0,0,9,0,1,0,1,2,0,0,90,0,0,0,2,33,0,4,3,1,0,1,10251,0,0,94,3,0,10,124,0,4,10,2,0,1,0,0,0,1,0,32,0,1,0,0,2,0,0,0,0,2,2,0,0,1,649,1,0,0,0,2,1,0,0,5,1,2,2,0,449,1,88,0,1,2,5,1,1,0,2,4834,2,4,1,0,2,0,2943,0,1,5534,1,2,0,2,3,677,0,2,0,1,0,0,595,3,0,1770,1,2,2,0,0,3,2466,3,0,2,2,0,1,6,1,2,51467,1,0,0,0,1,1298,0,0,2,14,1,3,0,3]; 3 | xi = [0:1000]; 4 | f1=ksdensity(x1,xi,'Width',50); 5 | %plot(xi1,f1) 6 | 7 | x2 = [3,1,3,2,2,0,0,2,0,0,0,1,0,5,216,2073,5,1,0,5,1,0,0,3,0,7,0,0,0,4,0,0,1,3,146,2,592,162,310,6,2,1,1,0,0,1,1,20,6,1,2378]; 8 | f2=ksdensity(x2,xi,'Width',50); 9 | %plot(xi2,f2,'LineWidth',2) 10 | 11 | x3 = [224,27,10,5,1,5,1,2,0,10,0,4,7,74,4,2348,9,3,13,3,1,0,0,2,152,150,1,188,13,3,3,11,16,62,1,16,2,4297,65,14,371,1,3,16,3,0,1,5,8,13,204,1,134,5,6,1,9,0,2,0,53,11,3,1,2,18,0,1,5,2,4,2,27,8,0,12,3,0,2,2588,1,3,553,2,1,2,4,8,3,5,1,6,0,3,0,3,3,4,2,3,3,0,1,2,739,4,4,6,2,3,2,1280,7,258,101,22,2,7,0,1,475,3,7,1,43,899,1,8,0,3,3297,2,0,3,0,3,2,4,5,1,1,8,1,3,0,6,4,7,4,5,0,3,0,1,2,6,0,22,0,1127,3,4,1,1,3,2,20,5,6,3,5,2,10,2,0,7,10,1,0,10,4,2,0,0,3,1,6,17,4,56,0,2,2,2,0,1,2,0,6,0,9,29,14,4,2,405,10,3,5,3,4,1,8,3,4,1,8,2,9,0,4,4,5,8,6,1,0,164,8,0,12,120,0,1,0,1,6,2,2,3,7,0,5,0,2,1,3,1,5,5,6,2,0,8,3,3,0,0,1,4,2,2,5,1,10,3,3,1,4,4,1,3,8,1,3,6,1770,1,1,0,4,8,1]; 12 | f3=ksdensity(x3,xi,'Width',50); 13 | 14 | x4 = [0,0,2,0,0,1,1,0,1,1,4,1,0,1,0,0,0,0,2,1,0,0,2,0,0,0,0,2,768,1,2,7,3,3,0,0,0,2,1,3,0,1,1,1,0,0,1,0,0,0,0,13,12686,6,1,0,0,2,0]; 15 | f4=ksdensity(x4,xi,'Width',50); 16 | 17 | x5 = [2,0,3,1,2,1,1,0,3,5271,1,1,0,1,1,0,2,1251,0,7354,2,64,0,1,1,1,0,670,2,2,1075,3,1,1,1,0,7,1,1,9,1,0,2,2,1,1,2,0,2,1,1,0,6,1,1,29,6,5,1,0,0,0,0,643,1,5,1,1,3,5,5,7,2,1,3,1,1,0,1,1467,3,1,4,1,2,1,1,4,1,1,1,1,123,1,3,2,2,1,4,1,1,1,2,1552,1,1,2,1471,0,18,4,2,7,5,2529,3,1,3,2848,1,5091,3,37,2,2,1,1,0,1,1,9,0,0,0,1,6,0,0,16,3,9,1737,8,0,3,1,0,1,1,2,1,1,3,1,1,502,0,1,4,4,27,1,11,7,4,5782,2,2,1,3,1,1,1,1,1,20,109,0,1,1,6,21377,0,1,27,3,2129,1399,2,51,0,1,1,2749,2,1,4,12,3102,1,29,39763,1630,2,4,3,1,2,1,0,2,1199,0,0,0,3,2,2,1,4,1388,4,2,3282,2,1088,3,2,1,33977,6,2,3,4,2,3,0,3,1,1768,3,2325,3,16,12355,9997,3,2600,29950,2121,3,1,2,5,5,6,38,4,8349,24,5,2,6,5,1,1,9,1,28,14532,9,1,2,2,3,1,2,83,2,26,6,0,2,2,4,2,3665,22,5,2,4,2]; 18 | f5=ksdensity(x5,xi,'Width',50); 19 | 20 | x6 = [0,0,0,0,0,772,0,2,1,0,0,0,170,1,2,0,2,1,0,617,0,0,0,4670,1,0,0,0,0,0,2,1,272,2,1,0,1,0,805,139,0,0,0,5,0,1226,63,2,0,0,0,0,2952,0,0,0,0,0,0,0,0,612,203,33,221,0,1,3,185,2695,2659,6,1,34,2165,0,0,0,0,0,567,0,0,0,90,432,0,3,0,0,0,0,0,117,0,2646,1,0,998,0,1,1,418,0,1,1,0,264,1,1,0,0,0,0,0,0,0,917,1,0,1,2,0,336,1,0,0,0,1,0,698,115,0,1,1,140,241,89,0,0,0,0,0,0,0,686,1511,0,1,2,0,1,0,654,0,1,2,0,0,0,3,327,0,1,2,1,2,0,196,1,75,1,4,0,2,4,0,100,401,1,0,0,1,0,1,0,0,1,0,2,0,1,0,1,2,0,1,1]; 21 | f6=ksdensity(x6,xi,'Width',50); 22 | 23 | x7 = [0,22,2,0,2,1,0,0,1,0,16,1,0,0,0,2,0,0,0,11,1,0,1,2,3,0,287,0,0,1,1,1,0,4,0,0,0,1,0,0,2,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,20,2,1,9,0,0,0,0,3,0,1,0,2,0,4,2,2,1,6,1,1,60,3,0,0,255,0,0,0,0,6,0,0,1,0,0,23,0,0,0,3,1,1,0,116,2,0,25,1,1,3,0,1,1,0,0,0,1,9,0,0,5,1,7,4,328,0,0,1,0,1,0,0,0,0,66,0,2,1,0,1,0,3,0,3,2,0,0,2,0,2,0,0,27,0,2,1,1,1,2,5,0,1,2,0,1,0,0,1,5,1,0,1,1,1,0,1,0,0,1,5,1,0,1,1,100,5,5,1,0,8,4,0,2,1,0,5874,31,1558948,9,137,45,21,11,252,0,0,1,2,0,0,1,0,0,14,0,9,1,2,2,1,0,0,3,1,1,4,2,739,633,0,66,0,2,5,50,1,2,1,0,75,1,1,2,2,0,1,0,2,2,0,4,4,2,276,15,1,7,2,1,17,1,1,1,87,92,3,73,1948,0,0,55,0,0,0,0,0,1,3,1,2,1211,2,0,1,0,0,1,3,0,0,4,0,1,72,1,3,6,2,2,2,5,7,0,1,0,5,10,2,19,1,764,1,6,1,4,873,7,16,3,4,4,2,5,0,26,57,107,115,3,12,5,11713,4111,199,3,6,50,0,1,5,2,39,3,3,1,0,495,4,1124,1,0,8,5,2,0,0,6,2,11,1,3,0,0,1,3,1,0,5,0,1,0,3,2,0,33,2,73,2,532,1,7,22,2,0,1,1,1,0,2,424,22,1,2755,2,2,1,0,1,1,4,0,5,15,0,37,3,0,2,0,0,6,1,5,6,3,2,1,135,0,3,3,5,1,5,6,3,2,1,135,0,3,3,3673,10,2,2,0,12,0,3,2,4,71,30,185,1,19,0,21,0,0,14,99,2,2,1,2,12,1,6,7,1,2,3,1,6,0,0,1,23,45,2,2,3,0,1,1,44,0,1,4,5,9,2,1984,2589,8,5,1,7,10,29,4,40,6,6,4,1,0,4,2,0,1,1136,0,13,42,1,2,2,0,2,0,0,24,2,5,2,2,0,1,0,2,0,0,24,2,5,2,2,0,310,2,14,0,578,162,0,2,2,0,12,1,147,13,0,249,3,6064,17,17,0,1,0,1,2,0,3,3,2,7,2,4070,25,2059,24,16,101,3889,107320,5696,1680]; 24 | f7=ksdensity(x7,xi,'Width',50); 25 | 26 | h1=plot(xi,f1,'LineWidth',2); 27 | hold on; 28 | h2=plot(xi,f2,'LineWidth',2); 29 | hold on; 30 | h3=plot(xi,f3,'LineWidth',2); 31 | hold on; 32 | h4=plot(xi,f4,'LineWidth',2); 33 | hold on; 34 | h5=plot(xi,f5,'LineWidth',2); 35 | hold on; 36 | h6=plot(xi,f6,'LineWidth',2); 37 | hold on; 38 | h7=plot(xi,f7,'LineWidth',2); 39 | xlabel('???');ylabel('????'); 40 | title('????????'); 41 | legend([h1,h2,h3,h4,h5,h6,h7],'??','??','??','??','??','??','??') 42 | 43 | for i = 1:100 44 | if f1(i)==0.0024 45 | 46 | end 47 | end 48 | 49 | 50 | for i = 1:100 51 | if f2(i)==2.0850e-04 + 2.4853e-13i 52 | ans=f2(i)/xi2(i); 53 | end 54 | end 55 | ans 56 | 57 | n=5047; 58 | u=89.8540; 59 | kA = 0; 60 | fi = []; 61 | d = [1:1000]; 62 | for i = 1:1000 63 | f = ksdensity((Dis2.-d(i))/u); 64 | kA = kA + f; 65 | end 66 | kA = (1/(n*(n-1)/u))*kA; 67 | plot(xi,kA) 68 | 69 | 70 | ub = []; 71 | lb = []; 72 | u=450.8540; 73 | n=5047; 74 | temp = zeros(100,100); 75 | m=[]; 76 | for k=1:100 77 | randnum=randperm(length(Dis2)); 78 | data=Dis(randnum(1:length(Dis2))); 79 | [f,xi] = ksdensity(data,'width',u); 80 | temp(k,:)=f; 81 | end 82 | temp 83 | ub = []; 84 | lb = []; 85 | for i=1:100 86 | m=temp(:,i); 87 | m=m'; 88 | m=sort(m) 89 | ub(i) = m(5); 90 | lb(i) = m(95); 91 | end 92 | plot(xi,ub) 93 | hold on 94 | plot(xi,lb) 95 | --------------------------------------------------------------------------------