Created
February 10, 2016 21:09
-
-
Save glamp/dc7847b1ecff6db02f1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# import my tree model from the model.py file | |
from model import tree | |
from yhat import Yhat, YhatModel, preprocess | |
class TreeModel(YhatModel): | |
@preprocess(in_type=dict, out_type=dict) | |
def execute(self, data): | |
pts = np.array(data["val"]) | |
# i'm not sure what this returns but there are 2 things: | |
# http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.spatial.KDTree.query.html | |
d, i = tree.query(pts) | |
return d.tolist() | |
test = { | |
"val": [ | |
[ 0, 0 ], | |
[ 2.1, 2.9 ] | |
] | |
} | |
print TreeModel().execute(test) | |
kdtree_patch = """ | |
from scipy.spatial import kdtree | |
kdtree.node = kdtree.KDTree.node | |
kdtree.leafnode = kdtree.KDTree.leafnode | |
kdtree.innernode = kdtree.KDTree.innernode | |
""" | |
yh = Yhat("USERNAME", "APIKEY", "URL") | |
yh.deploy("TreeModel", TreeModel, globals(), patch=kdtree_patch) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.spatial import kdtree | |
import numpy as np | |
# I need to apply the patch here as well b/c i've imported kdtree | |
kdtree.node = kdtree.KDTree.node | |
kdtree.leafnode = kdtree.KDTree.leafnode | |
kdtree.innernode = kdtree.KDTree.innernode | |
x, y = np.mgrid[0:5, 2:8] | |
tree = kdtree.KDTree(zip(x.ravel(), y.ravel())) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment