freediscovery.neighbors.NearestNeighborRanker¶

class
freediscovery.neighbors.
NearestNeighborRanker
(radius=1.0, algorithm='brute', leaf_size=30, n_jobs=1)[source]¶ A nearest neighbor ranker.
The distance is returned in terms of cosine_similarity
Parameters:  radius (float, optional (default = 1.0)) – Range of parameter space to use by default for
radius_neighbors()
queries.  algorithm ({'auto', 'ball_tree', 'kd_tree', 'brute'}, optional) –
Algorithm used to compute the nearest neighbors:
 ‘ball_tree’ will use
BallTree
 ‘kd_tree’ will use
KDtree
 ‘brute’ will use a bruteforce search.
 ‘auto’ will attempt to decide the most appropriate algorithm
based on the values passed to
fit()
method.
Note: fitting on sparse input will override the setting of this parameter, using brute force.
 ‘ball_tree’ will use
 leaf_size (int, optional (default = 30)) – Leaf size passed to BallTree or KDTree. This can affect the speed of the construction and query, as well as the memory required to store the tree. The optimal value depends on the nature of the problem.
 n_jobs (int, optional (default = 1)) – The number of parallel jobs to run for neighbors search.
If
1
, then the number of jobs is set to the number of CPU cores.  method (str, def) – If “unsupervised” only distances to the positive samples are used in the ranking. If “supervised” both the distance to the positive and negative documents are used for ranking (i.e. if a document is slightly further away from a positive document than from a negative one, it will be considered negative with a very low score)

fit
(X, y)[source]¶ Fit the model using X as training data :param X: Training data, shape [n_samples, n_features], :type X: {arraylike, sparse matrix, BallTree, KDTree}

get_params
(deep=True)[source]¶ Get parameters for this estimator.
Parameters: deep (boolean, optional) – If True, will return the parameters for this estimator and contained subobjects that are estimators. Returns: params – Parameter names mapped to their values. Return type: mapping of string to any

kneighbors
(X=None, batch_size=5000)[source]¶ Finds the Kneighbors of a point. Returns indices of and distances to the neighbors of each point. :param X: the input array :type X: arraylike, shape (n_samples, n_features) :param batch_size: the batch size :type batch_size: int
Returns:  S_cos (array [n_samples, n_categories]) – the cosine similarity to closest point in each category
 indices (array [n_samples, n_categories]) – Indices of the nearest points in the population matrix.
 ——–

score
(X, y, sample_weight=None)[source]¶ Returns the ROC score of the prediction. Best possible score is 1.0 and the worst in 0.
Parameters:  X (arraylike, shape = (n_samples, n_features)) – Test samples.
 y (arraylike, shape = (n_samples)) – True values for X.
 sample_weight (arraylike, shape = [n_samples], optional) – Sample weights.
Returns: score – ROC score of self.decision_function(X) wrt. y.
Return type: float

set_params
(**params)[source]¶ Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form
<component>__<parameter>
so that it’s possible to update each component of a nested object.Returns: Return type: self
 radius (float, optional (default = 1.0)) – Range of parameter space to use by default for