def prediction_curve(dmat, vals, steps, radius):
"""Return MSE from predicting values from neighbors at radial steps."""
# Set null distances (greater than some threshold) to 0.
# Not in general a great idea, but fine here because we don't
# do anything with identity edges, and sums will be faster
# if we don't have to worry about nans
dmat = np.nan_to_num(dmat)
error_vals = []
for step in steps:
neighbors = (np.abs(dmat - step) < radius).astype(np.float)
neighbors /= neighbors.sum(axis=1, keepdims=True)
predicted = neighbors.dot(vals)
m = ~np.isnan(predicted)
error_vals.append(mean_squared_error(vals[m], predicted[m]))
return np.array(error_vals)
spatial_analysis.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录