Skip to content

Instantly share code, notes, and snippets.

@julifgo
Last active March 4, 2020 12:22
Show Gist options
  • Save julifgo/ceda2a16df7576b580bb580cd69f1e74 to your computer and use it in GitHub Desktop.
Save julifgo/ceda2a16df7576b580bb580cd69f1e74 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 154,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.neighbors import NearestNeighbors\n",
"X = np.array(df[['latitud','longitud']])\n",
"nbrs = NearestNeighbors(n_neighbors=1, algorithm='brute')\n",
"distances = []\n",
"for i in range(0,X.shape[0]):\n",
" nbrs.fit(np.delete(X, i ,0))\n",
" distance, index = nbrs.kneighbors(X[i].reshape(1,-1))\n",
" val = float('%.4f'%(distance[0][0]))\n",
" distances.append(val)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment