-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
41 lines (34 loc) · 1.18 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import kmeans
import trainer
import json
import markov
import configGeojson
# Import all data
if __name__ == "__main__":
datafilenames = ['data/2010.json', 'data/2011.json', 'data/2012.json', 'data/2013.json']
datafiles = []
for filename in datafilenames:
with open(filename) as data_file:
data = json.load(data_file)
datafiles.append(data)
k = kmeans.KMeans(datafiles[0]) # train on first year
neighborhoodDict = k.classifyNeighborhoods(datafiles)
paramNames, statesDict = k.getParams()
print paramNames
print statesDict
# form is {'tract':<tract>, 'states':[<list of states over time>]}
# Bayesian
# input: {'tract':<tract>, 'states':[<list of states over time>]}
# outputs: kxk matrix
# [[from state 1 to all others], ...]
probMatrix, testData = trainer.trainModel(neighborhoodDict)
# trainer.visualize(probMatrix)
# Model stuff
# input: neighborhoodDict, probMatrix
# output: json {'tract':<tract>, 'states':[<list of states over time>]}
# this will fill in the list
m = markov.Markov(neighborhoodDict, probMatrix)
outputDict = m.runSim()
# Export for viz
# want json {'tract':<tract>, 'states':[<list of states over time>]}
configGeojson.configureGeojson(outputDict)