`L iX dZddlZddlZddlZddlmZmZddlmZddlm Z m Z ddl Z ddl mZddlmZmZdd lmZmZmZdd lmZmZdd lmZmZdd lmZmZdd lm Z ddl!m"Z"m#Z#m$Z$ddl%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+ddl,m-Z-ddl.m/Z/m0Z0ddl1m2Z2m3Z3m4Z4ddl5m6Z6ddl7m8Z8gdZ9e+e*dkre9dgz Z9e+e*dkre9dgz Z9e+e*dkre9dgz Z9e:e6jve8jve<e=e j}e9Z?e:gge jdd hz ZAd!ZBd"ZCd#ZDe(d$gd%gd%gd&d'(d3d)ZEd*ZFd+ZGGd,d-eee.ZHGd/d0ZIGd1d2ZJy)4z-Base and mixin classes for nearest neighbors.N)ABCMetaabstractmethod)partial)IntegralReal)effective_n_jobs) csr_matrixissparse) BaseEstimatorMultiOutputMixin is_classifier)DataConversionWarningEfficiencyWarning)DistanceMetricpairwise_distances_chunked)ArgKminRadiusNeighbors)PAIRWISE_DISTANCE_FUNCTIONS) check_arraygen_even_slicesget_tags)Interval StrOptionsvalidate_params) parse_versionsp_base_version)check_classification_targets)Paralleldelayed)_to_object_arraycheck_is_fitted validate_data)BallTree)KDTree) braycurtiscanberra chebyshev correlationcosinedicehammingjaccard mahalanobis minkowskirogerstanimoto russellrao seuclidean sokalsneath sqeuclideanyulez1.17 sokalmichenerz1.11 kulsinskiz1.9matching) ball_treekd_treebrute haversine nan_euclideanc|dvry|dk(r|jtjtur6t|D]&\}}t |dr d|vr |dk(||<d|z ||<(|Stj d5d|z }dddtj |}tj|d }||||<|St|r||Sy#1swYSxYw) aGet the weights from an array of distances and a parameter ``weights``. Assume weights have already been validated. Parameters ---------- dist : ndarray The input distances. weights : {'uniform', 'distance'}, callable or None The kind of weighting used. Returns ------- weights_arr : array of the same shape as ``dist`` If ``weights == 'uniform'``, then returns None. )NuniformNdistance __contains__gg?ignore)divider$axis) dtypenpobject enumeratehasattrerrstateisinfanycallable)distweights point_dist_i point_distinf_maskinf_rows ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sklearn/neighbors/_base.py _get_weightsrWQs$##* ::&) ),5dO :( j:~63*;L)3s):D&),z)9D& : H- "Tz "xx~HffXA.G$W-DM t} " "s <CCc|jdk(sJ|jdd|jddkD}tj|jdddz }|||j dk}|j ||j k(S)aReturn whether the graph's non-zero entries are sorted by data. The non-zero entries are stored in graph.data and graph.indices. For each row (or sample), the non-zero entries can be either: - sorted by indices, as after graph.sort_indices(); - sorted by data, as after _check_precomputed(graph); - not sorted. Parameters ---------- graph : sparse matrix of shape (n_samples, n_samples) Neighbors graph as given by `kneighbors_graph` or `radius_neighbors_graph`. Matrix should be of format CSR format. Returns ------- res : bool Whether input graph is sorted by data. csrNr$r)formatdatarHuniqueindptrshapesum)graph out_of_order line_changes rV_is_sorted_by_datards( <<5  ::cr?UZZ^3L))ELL2.23KkL,>,>q,AABK    k!:!>!>!@ @@ct|st|dd}|S|}|jdvr$tdj|j|jdk7}t|ddd}t || d }|S) aCheck precomputed distance matrix. If the precomputed distance matrix is sparse, it checks that the non-zero entries are sorted by distances. If not, the matrix is copied and sorted. Parameters ---------- X : {sparse matrix, array-like}, (n_samples, n_samples) Distance matrix to other samples. X may be a sparse matrix, in which case only non-zero elements may be considered neighbors. Returns ------- X : {sparse matrix, array-like}, (n_samples, n_samples) Distance matrix to other samples. X may be a sparse matrix, in which case only non-zero elements may be considered neighbors. TX)ensure_non_negative input_namerYcsccoolilzSSparse matrix in {!r} format is not supported due to its handling of explicit zerosrYzprecomputed distance matrix) accept_sparserhri)copywarn_when_not_sorted)r rr[ TypeErrorsort_graph_by_row_values)rgracopieds rV_check_precomputedrts$ A; t D ||77 --3VELL-A  \\U "F   0  E %UVRV WE Lrez sparse matrixboolean)rarorpT)prefer_skip_nested_validationc |jdk(r t|r|S|rtjdt|jdvrt d|jd|jdk7r|s t d|jd}n|r|j}tj|j}|j|jk(r|jd}|jj!|d}tj"|d }|tj$|d d d f|dzz }|j'}|j||_|j(||_|St+|j|jd d D]g\}}tj"|j||d }|j||||j|||j(||||j(||i|S) a{Sort a sparse graph such that each row is stored with increasing values. .. versionadded:: 1.2 Parameters ---------- graph : sparse matrix of shape (n_samples, n_samples) Distance matrix to other samples, where only non-zero elements are considered neighbors. Matrix is converted to CSR format if not already. copy : bool, default=False If True, the graph is copied before sorting. If False, the sorting is performed inplace. If the graph is not of CSR format, `copy` must be True to allow the conversion to CSR format, otherwise an error is raised. warn_when_not_sorted : bool, default=True If True, a :class:`~sklearn.exceptions.EfficiencyWarning` is raised when the input graph is not sorted by row values. Returns ------- graph : sparse matrix of shape (n_samples, n_samples) Distance matrix to other samples, where only non-zero elements are considered neighbors. Matrix is in CSR format. Examples -------- >>> from scipy.sparse import csr_matrix >>> from sklearn.neighbors import sort_graph_by_row_values >>> X = csr_matrix( ... [[0., 3., 1.], ... [3., 0., 2.], ... [1., 2., 0.]]) >>> X.data array([3., 1., 3., 2., 1., 2.]) >>> X_ = sort_graph_by_row_values(X) >>> X_.data array([1., 3., 2., 3., 1., 2.]) rYzPrecomputed sparse input was not sorted by row values. Use the function sklearn.neighbors.sort_graph_by_row_values to sort the input by row values, with warn_when_not_sorted=False to remove this warning.rjzSparse matrix in z> format is not supported due to its handling of explicit zeroszZThe input graph is not in CSR format. Use copy=True to allow the conversion to CSR format.rrZ mergesortkindNr$)r[rdwarningswarnrrq ValueErrorasformatrorHdiffr^maxminr_r\reshapeargsortarangeravelindiceszip) rarorprow_nnz n_samples distancesorderstartstops rVrrrrsb ||u!3E!:     ||77 /0- -    0 u%  ggell#G{{} %KKN JJ&&y"5  9;7 9%ag.;; ZZ&  e,  L u||U\\!"-=> IKE4JJuzz%5KHE%*ZZd%;E%BEJJuT "(- eD(A%(HEMM% % I LrecZjdjdk(sJtjjj krt dfzfd}|r$|j|jfS|jS)aDecompose a nearest neighbors sparse graph into distances and indices. Parameters ---------- graph : sparse matrix of shape (n_samples, n_samples) Neighbors graph as given by `kneighbors_graph` or `radius_neighbors_graph`. Matrix should be of format CSR format. n_neighbors : int Number of neighbors required for each sample. return_distance : bool Whether or not to return the distances. Returns ------- neigh_dist : ndarray of shape (n_samples, n_neighbors) Distances to nearest neighbors. Only present if `return_distance=True`. neigh_ind : ndarray of shape (n_samples, n_neighbors) Indices of nearest neighbors. rrYz%d neighbors per samples are required, but some samples have only %d neighbors in precomputed graph matrix. Decrease number of neighbors used or recompute the graph with more neighbors.c(jk(r|jddddfStjtjdf}|j dddfz }|j |djS)NrZr$clip)mode)rrrHtilerr^take)aidxra n_neighborsrr row_nnz_mins rVextractz'_kneighbors_from_graph..extractKs ;;=K '99Y+A| |O< <''"))K09a.AC 5<<T * *C66#F6+33I{K Kre) r_r[rHrr^rr}r\r)rarreturn_distancerrrrs`` @@@rV_kneighbors_from_graphr&s. AI <<5  ggell#G++-K;#< IK( )  LLuzz"GEMM$:::u}}%%rec|jdk(sJt|jj|k}|r%|j|j|j }}}n|j|k}|r t j||j}t j||j}t jdgt j|f|j }|jt j|}|r"tt j|dd}tt j||dd} |r| fS| S)aDecompose a nearest neighbors sparse graph into distances and indices. Parameters ---------- graph : sparse matrix of shape (n_samples, n_samples) Neighbors graph as given by `kneighbors_graph` or `radius_neighbors_graph`. Matrix should be of format CSR format. radius : float Radius of neighborhoods which should be strictly positive. return_distance : bool Whether or not to return the distances. Returns ------- neigh_dist : ndarray of shape (n_samples,) of arrays Distances to nearest neighbors. Only present if `return_distance=True`. neigh_ind : ndarray of shape (n_samples,) of arrays Indices of nearest neighbors. rYr)ror$rZ)r[boolr\rrr^rHcompress concatenatecumsumastypeintpr!split) raradiusrno_filter_neededr\rr^mask neigh_dist neigh_inds rV_radius_neighbors_from_graphrZs. <<5  EJJNN,67 % EMM5<eZdZUdZeeddddgeeddddgehdgeedddgeeddd dgeee je je gedgedgd Zeed <e dd Zd ZddZfdZxZS) NeighborsBasez,Base class for nearest neighbors estimators.r$Nleft)closedrboth>autor<r;r:right)rr algorithm leaf_sizepmetric metric_paramsn_jobs_parameter_constraintsc t||_||_||_||_||_||_||_||_yN)rrrrrrrr) selfrrrrrrrrs rV__init__zNeighborsBase.__init__s>' "" * rec|jdk(r\|jdk(rd}nVt|js/|jtdvst |jt rd}nd}n |j}t|jr'|jdk(rct d|jz|jt|vr6t |jt st d|jd|d |j9d |jvr*|jtjd td yyyy)Nr precomputedr<r:r;zhkd_tree does not support callable metric '%s'Function call overhead will resultin very poor performance.zMetric 'z9' not valid. Use sorted(sklearn.neighbors.VALID_METRICS['zA']) to get valid options. Metric can also be a callable function.rz\Parameter p is found in metric_params. The corresponding parameter from __init__ is ignored. stacklevel) rrrO VALID_METRICS isinstancerr}rrr{r| SyntaxWarning)r alg_checks rV_check_algorithm_metricz%NeighborsBase._check_algorithm_metrics$ >>V #{{m+# %;;- "<<dkk>:' # I DKK ~~* 026++> [[ i 8 8 KKB >B[[)U     )cT5G5G.Gvv! &" "/H )rec t|jjrdnd}|jjj rt |tttfst|||ddd|\}}t|ru|jdk(s!|jdk(rV|jddk(rD|jdk7rtjdt d d |_|j%d }nd|_t'|g|_t+j,|jt*j. |_t3|j0jdD]O}t+j4|dd|fd \}|j0dd|f<|j(j7|Q|j"sg|j(d|_|j0j9|_n3||_n+t |tttfst|||dd}|j;|j<i|_n|j<jA|_|j>jCd|jD}|jFdk(r||j>d<|jF|_$|jFdk(r|j>jKdd}|j>jKdd}|dk(r |d|_$nJ|dk(r |d|_$n;|t*jLk(r |d|_$n||j>d<||j>d<t |trF|jN|_'|jP|_(|jR|_)|jT|_*|St |tr?|jV|_'||_(d|_)|jVjd|_*|St |tr?|jV|_'||_(d|_)|jVjd|_*|S|jFdk(rstY|}|jd|jdk7r5t[dj]|jd|jd|jd|_/|jd} | dk(r t[dta|r|jbdvrtjd|jHtddvrGtg|jHs2t |jHthst[d|jHz|jA|_'d|_(d|_)|jd|_*|S|jb|_)||_'|jd|_*|jRdk(r|jFdk(sQ|jNjdd kDs5|jj1|jj|jNjddzk\rd|_)n|jHdk(r|j>ddkrd|_)n|jHdk(r#|j>jCdd|_)nV|jHtldvrd|_)n9tg|jHs|jHtldvrd|_)nd|_)|jHdk(rP|j>ddkr>|jRdk(rtjd!nt[d"|jRd#|jRdk(r4t||jnfd$|jHi|j>|_(|S|jRdk(ri|jHdk(r&|j>jCd t[d%t||jnfd$|jHi|j>|_(|S|jRdk(rd|_(|S)&N allow-nanTrYC)rn multi_outputrensure_all_finiter$r zA column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples,), for example using ravel().rF)rZr$rG)return_inverser)rrnrrr0w manhattan euclideanr)r:r;rz;Precomputed matrix must be square. Input is a {}x{} matrix.z n_samples must be greater than 0)rr<z4cannot use tree with sparse input: using brute forcer<zMetric '%s' not valid for sparse input. Use sorted(sklearn.neighbors.VALID_METRICS_SPARSE['brute']) to get valid options. Metric can also be a callable function.rzwMind that for 0 < p < 1, Minkowski metrics are not distance metrics. Continuing the execution with `algorithm='brute'`.z algorithm="zv" does not support 0 < p < 1 for the Minkowski metric. To resolve this problem either set p >= 1 or algorithm="brute".rzalgorithm='kd_tree' is not valid for metric='minkowski' with a weight parameter 'w': try algorithm='ball_tree' or algorithm='brute' instead.)8r input_tags allow_nan__sklearn_tags__ target_tagsrequiredrr&r%rr#rndimr_r{r|r outputs_2d_rrclasses_rHemptyr_yranger]appendrrreffective_metric_params_rogetrreffective_metric_popinf_fit_X_tree _fit_methodn_samples_fit_r\rtr}r[n_features_in_r rVALID_METRICS_SPARSErOrrrr) rrgyrkclasses effective_prrrs rV_fitzNeighborsBase._fits[+3D>+D+D+N+NKTX  " . . 7 7a&(M!BC$"'!%&71T"66Q;166Q;1771:?vv{ !9 2'( (-D$ '*A'+D$,Q/ " ((177"'':tww}}Q/02A-/YYqAwt-T*GTWWQT]MM((12''$(MM!$4DM"ggmmoDGa&(M!BC!&7"'  $$&    %,.D ),0,>,>,C,C,ED )3377TVVD ;;+ %1?@ @ A;~~%66 TU&&.B7.KK !7!78"4#9#9>J >BFAWAW Y&&(DKDJ&D "#''!*D K>> ggaj   v % },;;$$Q'",$$0((DKK,=,=a,@A,EE$+ **k955c:Q>'.D$**k95599#>J(3D$++}Y/GG'0D$T334--{1KK'2D$'.D$  " "k 1--c2Q67* S !!$"2"2!3477   { *!--// DJ4 )   *&&+51155c:F 4  --// DJ    (DJ rect|}d|j_|jdk(|j_|jj |j_|jdk(|j_|S)NTrr>)superrrsparserpairwise positive_onlyrrtags __class__s rVrzNeighborsBase.__sklearn_tags__saw')!%#';;-#? (,(@(@%$(KK?$B! re)NNrr0r NNr)__name__ __module__ __qualname____doc__rrrrset itertoolschainrvaluesrOdictr__annotations__rrrrr __classcell__rs@rVrrs6!1d6BDID!T&94@ !JKLxD@AtQW5t <c/)//=3G3G3I"JKLhWT" $D  (+ZhTrer) metaclassc&eZdZdZdZddZddZy)KNeighborsMixinzMixin for k-neighbors searches.cZtj|jddddf}tj||dz d}|ddd|f}||tj|||ff}|r8|j dk(rtj |||f|f}|S|||f|f}|S|}|S)aReduce a chunk of distances to the nearest neighbors. Callback to :func:`sklearn.metrics.pairwise.pairwise_distances_chunked` Parameters ---------- dist : ndarray of shape (n_samples_chunk, n_samples) The distance matrix. start : int The index in X which the first row of dist corresponds to. n_neighbors : int Number of neighbors required for each sample. return_distance : bool Whether or not to return the distances. Returns ------- dist : array of shape (n_samples_chunk, n_neighbors) Returned only if `return_distance=True`. neigh : array of shape (n_samples_chunk, n_neighbors) The neighbors indices. rNr$rEr)rHrr_ argpartitionrrsqrt)rrPrrr sample_rangerresults rV_kneighbors_reduce_funcz'KNeighborsMixin._kneighbors_reduce_funcs6yyA/48 OOD+/B a+o. lBJJtL)?J  lI56 A F reNc ~t jnDdkrtdzttj st dtztjjrdnd}du}|rjdz n,jdk(r tnt|d d d j}|kDr0|rdzd }nd}td|dd|dj dt#j$}d} j&dk(xr9t)j*n jjj,} | r>> samples = [[0., 0., 0.], [0., .5, 0.], [1., 1., .5]] >>> from sklearn.neighbors import NearestNeighbors >>> neigh = NearestNeighbors(n_neighbors=1) >>> neigh.fit(samples) NearestNeighbors(n_neighbors=1) >>> print(neigh.kneighbors([[1., 1., 1.]])) (array([[0.5]]), array([[2]])) As you can see, it returns [[0.5]], and [[2]], which means that the element is at distance 0.5 and is the third element of samples (indexes start at 0). You can also query for multiple points: >>> X = [[0., 1., 0.], [1., 0., 1.]] >>> neigh.kneighbors(X, return_distance=False) array([[1], [2]]...) Nrz Expected n_neighbors > 0. Got %dz7n_neighbors does not take %s value, enter integer valuerTr$rrYFrrrnresetrzn_neighbors < n_samples_fitzn_neighbors <= n_samples_fitz Expected z, but n_neighbors = z, n_samples_fit = z, n_samples = r<r)rgYrr metric_kwargsstrategyr)rrrsquared reduce_funcrrr:r;Q%s does not work with sparse matrices. Densify the data, or set algorithm='brute'threadspreferc3rK|].}tjj|0ywr)r rquery).0srgrrrs rV z-KNeighborsMixin.kneighbors..s9A* (()!A$ _MAs47$internal: _fit_method not recognizedrE)'r"rr}rnumbersrrqtyperrrrrrtr#rr_rrrr is_usable_forrcomputerr rrr listrrrrrHvstackrallr)rrgrrrquery_is_train n_samples_fitinequality_strrchunked_results!use_pairwise_distances_reductionsresultsrkwdsrr n_queries_r sample_mask dup_gr_nbrss```` rV kneighborszKNeighborsMixin.kneighborssh   **K A ?+MN NK)9)9:I{#$  ,4D>+D+D+N+NKTXd  A 1 K{{m+&q)!&7"' ++  &q !>!?N+,!!, -? O wwqzl,  "$++.    ' %%] T[[$BXBX * -oo++--";; /G    'DKK=,HXVW[,{OG   (",,' /K%%4!4(44"*KK!,11!    O  !9 9{ /151A1ABAhvi@A(V<AO CD D  &(+_(=% I))J/91EE))O4N (/% I# 77LIq99Y/48L#|3K &&15K-2K1 k * 9[#9I{UV;WXIZZ{+iq-I "9,, rect|| |j}|dk(r<|j||d}|jd}t j ||z}nA|dk(r-|j||d\}}t j |}ntd|d|jd}|j}||z}t jd|d z|} t||j | f||f } | S) aCompute the (weighted) graph of k-Neighbors for points in X. Parameters ---------- X : {array-like, sparse matrix} of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed', default=None The query point or points. If not provided, neighbors of each indexed point are returned. In this case, the query point is not considered its own neighbor. For ``metric='precomputed'`` the shape should be (n_queries, n_indexed). Otherwise the shape should be (n_queries, n_features). n_neighbors : int, default=None Number of neighbors for each sample. The default is the value passed to the constructor. mode : {'connectivity', 'distance'}, default='connectivity' Type of returned matrix: 'connectivity' will return the connectivity matrix with ones and zeros, in 'distance' the edges are distances between points, type of distance depends on the selected metric parameter in NearestNeighbors class. Returns ------- A : sparse-matrix of shape (n_queries, n_samples_fit) `n_samples_fit` is the number of samples in the fitted data. `A[i, j]` gives the weight of the edge connecting `i` to `j`. The matrix is of CSR format. See Also -------- NearestNeighbors.radius_neighbors_graph : Compute the (weighted) graph of Neighbors for points in X. Examples -------- >>> X = [[0], [3], [1]] >>> from sklearn.neighbors import NearestNeighbors >>> neigh = NearestNeighbors(n_neighbors=2) >>> neigh.fit(X) NearestNeighbors(n_neighbors=2) >>> A = neigh.kneighbors_graph(X) >>> A.toarray() array([[1., 0., 1.], [0., 1., 1.], [1., 0., 1.]]) connectivityFrrrATHUnsupported mode, must be one of "connectivity", or "distance" but got " " insteadr$r_) r"rr0r_rHonesrr}rrr ) rrgrrA_indr,A_datar& n_nonzeroA_indptrkneighbors_graphs rVr<z KNeighborsMixin.kneighbors_graphsd   **K > !OOA{EOJE AIWWY45F Z  OOA{DOQMFEXXf%F**.y:  KKN ++  + 99Q A {;% U[[]H -i5O  re)NNT)NNr2)rrrrr r0r<rerVrrs)'RJXQ rerc<eZdZdZdZ ddZ ddZfdZxZS)RadiusNeighborsMixinz*Mixin for radius-based neighbors searches.c ^|Dcgc]}tj||kd}}|ro|jdk(r7t|Dcgc] \}}tj|||"}}}n#t|Dcgc] \}}|||}}}||f}|S|}|Scc}wcc}}wcc}}w)aReduce a chunk of distances to the nearest neighbors. Callback to :func:`sklearn.metrics.pairwise.pairwise_distances_chunked` Parameters ---------- dist : ndarray of shape (n_samples_chunk, n_samples) The distance matrix. start : int The index in X which the first row of dist corresponds to. radius : float The radius considered when making the nearest neighbors search. return_distance : bool Whether or not to return the distances. Returns ------- dist : list of ndarray of shape (n_samples_chunk,) Returned only if `return_distance=True`. neigh : list of ndarray of shape (n_samples_chunk,) The neighbors indices. rr)rHwhererrJr) rrPrrrdrir*s rV_radius_neighbors_reduce_funcz2RadiusNeighborsMixin._radius_neighbors_reduce_funcs68<||d}||||<|||||<4|f}n|jdvrt!rtd|jztA|j*}tC|jDjFtI|dfdtKjLd|D} r?tOt-| \}}t=jP|t=jP|f}n!t=jP| }n td|s|Sr|\}}n|}tS|D] \}}||k7}||||<s||||<"r|fS|S)a Find the neighbors within a given radius of a point or points. Return the indices and distances of each point from the dataset lying in a ball with size ``radius`` around the points of the query array. Points lying on the boundary are included in the results. The result points are *not* necessarily sorted by distance to their query point. Parameters ---------- X : {array-like, sparse matrix} of (n_samples, n_features), default=None The query point or points. If not provided, neighbors of each indexed point are returned. In this case, the query point is not considered its own neighbor. radius : float, default=None Limiting distance of neighbors to return. The default is the value passed to the constructor. return_distance : bool, default=True Whether or not to return the distances. sort_results : bool, default=False If True, the distances and indices will be sorted by increasing distances before being returned. If False, the results may not be sorted. If `return_distance=False`, setting `sort_results=True` will result in an error. .. versionadded:: 0.22 Returns ------- neigh_dist : ndarray of shape (n_samples,) of arrays Array representing the distances to each point, only present if `return_distance=True`. The distance values are computed according to the ``metric`` constructor parameter. neigh_ind : ndarray of shape (n_samples,) of arrays An array of arrays of indices of the approximate nearest points from the population matrix that lie within a ball of size ``radius`` around the query points. Notes ----- Because the number of neighbors of each point is not necessarily equal, the results for multiple query points cannot be fit in a standard data array. For efficiency, `radius_neighbors` returns arrays of objects, where each object is a 1D array of indices or distances. Examples -------- In the following example, we construct a NeighborsClassifier class from an array representing our data set and ask who's the closest point to [1, 1, 1]: >>> import numpy as np >>> samples = [[0., 0., 0.], [0., .5, 0.], [1., 1., .5]] >>> from sklearn.neighbors import NearestNeighbors >>> neigh = NearestNeighbors(radius=1.6) >>> neigh.fit(samples) NearestNeighbors(radius=1.6) >>> rng = neigh.radius_neighbors([[1., 1., 1.]]) >>> print(np.asarray(rng[0][0])) [1.5 0.5] >>> print(np.asarray(rng[1][0])) [1 2] The first array returned contains the distances to all points which are closer than 1.6, while the second array returned contains their indices. In general, multiple points can be queried at the same time. z5return_distance must be True if sort_results is True.rTNrrYFrr r<r)rgr rrrrr sort_results)rrrrrrxryrrrrc3<K|]}|yw))rFNr=)rrrg delayed_queryrrrFs rVrz8RadiusNeighborsMixin.radius_neighbors..s-AadFO,WWAsrr)*r"r}rrrrrrtr#rrrr rr!rr rrrDrrrr"rr from_iterabler!rlenrHrrr r query_radiusrrr_tuplehstackrJ)rrgrrrFrr%r)r*r+rr(neigh_dist_chunksneigh_ind_chunksneigh_dist_listneigh_ind_listrriirrind ind_neighborrrHs ```` @rVradius_neighborsz%RadiusNeighborsMixin.radius_neighborsEsX  TU U+3D>+D+D+N+NKTXd  A{{m+&q)!&7"'  >[[F    ' --] T[[$BXBX * -%--++--";; /) G    'DKK=,HXVW[2&/G   (%%4& !4(44!22 /K 9 (--{{   O69?6K3!#3"&y'D'DEV'W"X!%ioo&C&CDT&U!V-o> ,^< $i/!%ioo&C&CO&T!U*>:J0;BJJz"~KHE$-bM%$8IbM%/^E%:JrN;%i/   !9 9{ /151A1AB &dkk2F#DJJ$;$;>> X = [[0], [3], [1]] >>> from sklearn.neighbors import NearestNeighbors >>> neigh = NearestNeighbors(radius=1.5) >>> neigh.fit(X) NearestNeighbors(radius=1.5) >>> A = neigh.radius_neighbors_graph(X) >>> A.toarray() array([[1., 0., 1.], [0., 1., 0.], [1., 0., 1.]]) Nr2Fr3rAT)rrFr4r5rr$rr6)r"rrUrHrr"r}r_rarrayrJr7zerosintrr ) rrgrrrFr8r9rPr,r&rrr;s rVradius_neighbors_graphz+RadiusNeighborsMixin.radius_neighbors_graphsDt  >[[F > !))!VU)KEF Z //64l0KD%^^DJ/F**.y:  KKN ++ hh61A67 tE{+ >WWSZ(F>>288AS#9299[;Q"RS65(3I};UVV 7s/Ec`t|}|jdk(|j_|S)Nr>)rrrrrrs rVrz%RadiusNeighborsMixin.__sklearn_tags__ys*w')$(KK?$B! re)NNTF)NNr2F) rrrrrDrUrZrrrs@rVr?r?s34%PGLXvFKXWtrer?)FT)Krrrr{abcrr functoolsrrrnumpyrHjoblibr scipy.sparser r baser r r exceptionsrrmetricsrr%metrics._pairwise_distances_reductionrrmetrics.pairwiserutilsrrrutils._param_validationrrr utils.fixesrrutils.multiclassrutils.parallelrr utils.validationr!r"r# _ball_treer%_kd_treer& SCIPY_METRICSr valid_metricssortedrunionrkeysrrWrdrtrrrrrrr?r=rerVrss3 '"#-AAA@; LK8;.OO  $]6**o&&M]6**k]"M]5))j\!M$$   0177 F G    + & + + -o0N N+\A6&R!" !*  #' XXv1&h-`B$mwBJ I I X aare