本文整理匯總了Python中sklearn.neighbors.BallTree方法的典型用法代碼示例。如果您正苦於以下問題:Python neighbors.BallTree方法的具體用法?Python neighbors.BallTree怎麽用?Python neighbors.BallTree使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在模塊sklearn.neighbors的用法示例。

在下文中一共展示了neighbors.BallTree方法的19個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。

示例1: avgdigamma

​點讚 6

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def avgdigamma(data, dvec, leaf_size=16):

"""Convenience function for finding expectation value of given

some number of neighbors in some radius in a marginal space.

Parameters

----------

points : numpy.ndarray

dvec : array_like (n_points,)

Returns

-------

avgdigamma : float

expectation value of

"""

tree = BallTree(data, leaf_size=leaf_size, p=float('inf'))

n_points = tree.query_radius(data, dvec - EPS, count_only=True)

return digamma(n_points).mean()

開發者ID:msmbuilder,項目名稱:mdentropy,代碼行數:20,

示例2: test_unsupervised_inputs

​點讚 6

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def test_unsupervised_inputs():

# test the types of valid input into NearestNeighbors

X = rng.random_sample((10, 3))

nbrs_fid = neighbors.NearestNeighbors(n_neighbors=1)

nbrs_fid.fit(X)

dist1, ind1 = nbrs_fid.kneighbors(X)

nbrs = neighbors.NearestNeighbors(n_neighbors=1)

for input in (nbrs_fid, neighbors.BallTree(X), neighbors.KDTree(X)):

nbrs.fit(input)

dist2, ind2 = nbrs.kneighbors(X)

assert_array_almost_equal(dist1, dist2)

assert_array_almost_equal(ind1, ind2)

開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:19,

示例3: test_haversine

​點讚 6

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def test_haversine():

tree = BallTree(spatial_data[:, :2], metric="haversine")

dist_matrix, _ = tree.query(spatial_data[:, :2], k=spatial_data.shape[0])

test_matrix = np.array(

[

[

dist.haversine(spatial_data[i, :2], spatial_data[j, :2])

for j in range(spatial_data.shape[0])

]

for i in range(spatial_data.shape[0])

]

)

test_matrix.sort(axis=1)

assert_array_almost_equal(

test_matrix,

dist_matrix,

err_msg="Distances don't match " "for metric haversine",

)

開發者ID:lmcinnes,項目名稱:pynndescent,代碼行數:20,

示例4: test_haversine

​點讚 6

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def test_haversine(spatial_data):

tree = BallTree(spatial_data[:, :2], metric="haversine")

dist_matrix, _ = tree.query(spatial_data[:, :2], k=spatial_data.shape[0])

test_matrix = np.array(

[

[

dist.haversine(spatial_data[i, :2], spatial_data[j, :2])

for j in range(spatial_data.shape[0])

]

for i in range(spatial_data.shape[0])

]

)

test_matrix.sort(axis=1)

assert_array_almost_equal(

test_matrix,

dist_matrix,

err_msg="Distances don't match " "for metric haversine",

)

開發者ID:lmcinnes,項目名稱:umap,代碼行數:20,

示例5: make_propensity_lists

​點讚 6

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def make_propensity_lists(self, train_ids, benchmark):

input_data, ids, pair_data = benchmark.get_data_access().get_rows(train_ids)

assignments = map(benchmark.get_assignment, ids, input_data)

treatment_data, batch_y = zip(*assignments)

treatment_data = np.array(treatment_data)

if pair_data.shape[-1] > 200 and False:

self.pca = PCA(50, svd_solver="randomized")

pair_data = self.pca.fit_transform(pair_data)

else:

self.pca = None

# covariance_matrix = np.cov(pair_data, rowvar=False)

self.original_data = [pair_data[treatment_data == t]

for t in range(benchmark.get_num_treatments())]

# self.ball_trees = [BallTree(pair_data[treatment_data == t], metric="mahalanobis",

# V=covariance_matrix)

# for t in range(benchmark.get_num_treatments())]

self.ball_trees = [BallTree(pair_data[treatment_data == t])

for t in range(benchmark.get_num_treatments())]

self.treatment_ids = [ids[treatment_data == t]

for t in range(benchmark.get_num_treatments())]

開發者ID:d909b,項目名稱:perfect_match,代碼行數:24,

示例6: test_objectmapper

​點讚 6

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def test_objectmapper(self):

df = pdml.ModelFrame([])

self.assertIs(df.neighbors.NearestNeighbors,

neighbors.NearestNeighbors)

self.assertIs(df.neighbors.KNeighborsClassifier,

neighbors.KNeighborsClassifier)

self.assertIs(df.neighbors.RadiusNeighborsClassifier,

neighbors.RadiusNeighborsClassifier)

self.assertIs(df.neighbors.KNeighborsRegressor,

neighbors.KNeighborsRegressor)

self.assertIs(df.neighbors.RadiusNeighborsRegressor,

neighbors.RadiusNeighborsRegressor)

self.assertIs(df.neighbors.NearestCentroid, neighbors.NearestCentroid)

self.assertIs(df.neighbors.BallTree, neighbors.BallTree)

self.assertIs(df.neighbors.KDTree, neighbors.KDTree)

self.assertIs(df.neighbors.DistanceMetric, neighbors.DistanceMetric)

self.assertIs(df.neighbors.KernelDensity, neighbors.KernelDensity)

開發者ID:pandas-ml,項目名稱:pandas-ml,代碼行數:19,

示例7: calc_vert_vals

​點讚 6

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def calc_vert_vals(verts, pts, vals, method='max', k_points=100):

from sklearn.neighbors import BallTree

ball_tree = BallTree(pts)

k_points = min([k_points, len(pts)])

dists, pts_inds = ball_tree.query(verts, k=k_points, return_distance=True)

near_vals = vals[pts_inds]

# sig_dists = dists[np.where(abs(near_vals)>2)]

cover = len(np.unique(pts_inds.ravel()))/float(len(pts))

print('{}% of the points are covered'.format(cover*100))

if method == 'dist':

n_dists = 1/(dists**2)

norm = 1/np.sum(n_dists, 1)

norm = np.reshape(norm, (len(norm), 1))

n_dists = norm * n_dists

verts_vals = np.sum(near_vals * n_dists, 1)

elif method == 'max':

verts_vals = near_vals[range(near_vals.shape[0]), np.argmax(abs(near_vals), 1)]

return verts_vals

開發者ID:pelednoam,項目名稱:mmvt,代碼行數:20,

示例8: test_barnes_hut_angle

​點讚 5

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def test_barnes_hut_angle():

# When Barnes-Hut's angle=0 this corresponds to the exact method.

angle = 0.0

perplexity = 10

n_samples = 100

for n_components in [2, 3]:

n_features = 5

degrees_of_freedom = float(n_components - 1.0)

random_state = check_random_state(0)

distances = random_state.randn(n_samples, n_features)

distances = distances.astype(np.float32)

distances = abs(distances.dot(distances.T))

np.fill_diagonal(distances, 0.0)

params = random_state.randn(n_samples, n_components)

P = _joint_probabilities(distances, perplexity, verbose=0)

kl_exact, grad_exact = _kl_divergence(params, P, degrees_of_freedom,

n_samples, n_components)

k = n_samples - 1

bt = BallTree(distances)

distances_nn, neighbors_nn = bt.query(distances, k=k + 1)

neighbors_nn = neighbors_nn[:, 1:]

distances_nn = np.array([distances[i, neighbors_nn[i]]

for i in range(n_samples)])

assert np.all(distances[0, neighbors_nn[0]] == distances_nn[0]),\

abs(distances[0, neighbors_nn[0]] - distances_nn[0])

P_bh = _joint_probabilities_nn(distances_nn, neighbors_nn,

perplexity, verbose=0)

kl_bh, grad_bh = _kl_divergence_bh(params, P_bh, degrees_of_freedom,

n_samples, n_components,

angle=angle, skip_num_points=0,

verbose=0)

P = squareform(P)

P_bh = P_bh.toarray()

assert_array_almost_equal(P_bh, P, decimal=5)

assert_almost_equal(kl_exact, kl_bh, decimal=3)

開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:40,

示例9: fit

​點讚 5

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def fit(self, X):

X = self._validate_input(X, return_compact=False)

self._tree = BallTree(X, metric='hamming', leaf_size=self.leaf_size)

return self

開發者ID:jakevdp,項目名稱:klsh,代碼行數:6,

示例10: build_tree

​點讚 5

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def build_tree(points):

if points.shape[1] >= 20:

return BallTree(points, metric='chebyshev')

return KDTree(points, metric='chebyshev')

# TESTS

開發者ID:gregversteeg,項目名稱:NPEET,代碼行數:8,

示例11: update_tree

​點讚 5

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def update_tree(self, time):

print 'rebuild tree'

self.tree = BallTree(self.state[:self.items, :], leaf_size=self.size)

self.last_tree_built_time = time

print 'rebuild done'

開發者ID:ShibiHe,項目名稱:Model-Free-Episodic-Control,代碼行數:7,

示例12: transform

​點讚 5

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def transform(self, documents):

return [

BallTree(documents)

]

開發者ID:foxbook,項目名稱:atap,代碼行數:6,

示例13: fit_transform

​點讚 5

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def fit_transform(self, documents):

# Transformer will be False if pipeline hasn't been fit yet,

# Trigger fit_transform and save the transformer and lexicon.

if self.transformer == False:

self.transformer = Pipeline([

('norm', TextNormalizer(minimum=50, maximum=200)),

('transform', Pipeline([

('tfidf', TfidfVectorizer()),

('svd', TruncatedSVD(n_components=200))

])

)

])

self.lexicon = self.transformer.fit_transform(documents)

self.tree = BallTree(self.lexicon)

self.save()

開發者ID:foxbook,項目名稱:atap,代碼行數:17,

示例14: knn_interpolation

​點讚 5

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def knn_interpolation(cumulated_pc: np.ndarray, full_sized_data: np.ndarray, k=5):

"""

Using k-nn interpolation to find labels of points of the full sized pointcloud

:param cumulated_pc: cumulated pointcloud results after running the network

:param full_sized_data: full sized point cloud

:param k: k for k nearest neighbor interpolation

:return: pointcloud with predicted labels in last column and ground truth labels in last but one column

"""

labeled = cumulated_pc[cumulated_pc[:, -1] != -1]

to_be_predicted = full_sized_data.copy()

ball_tree = BallTree(labeled[:, :3], metric='euclidean')

knn_classes = labeled[ball_tree.query(to_be_predicted[:, :3], k=k)[1]][:, :, -1].astype(int)

interpolated = np.zeros(knn_classes.shape[0])

for i in range(knn_classes.shape[0]):

interpolated[i] = np.bincount(knn_classes[i]).argmax()

output = np.zeros((to_be_predicted.shape[0], to_be_predicted.shape[1]+1))

output[:, :-1] = to_be_predicted

output[:, -1] = interpolated

return output

開發者ID:VisualComputingInstitute,項目名稱:3d-semantic-segmentation,代碼行數:29,

示例15: _calc_ball_trees

​點讚 5

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def _calc_ball_trees(self, metric='euclidean'):

ball_trees = []

for pointcloud_data in tqdm(self.dataset.data, desc='Ball trees have to be calculated from scratch'):

ball_trees.append(BallTree(pointcloud_data[:, :2], metric=metric))

return ball_trees

開發者ID:VisualComputingInstitute,項目名稱:3d-semantic-segmentation,代碼行數:7,

示例16: __init__

​點讚 5

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def __init__(self, num_corrections=10, num_basic_results=10,

home_dir=".",

embedding_json=None,

vocab_int_json=None, *args, **kwargs):

super().__init__(num_res_return=num_basic_results, *args, **kwargs)

self.use_embedding = False

if embedding_json and vocab_int_json:

self.use_embedding = True

embedding_json = path.join(home_dir, embedding_json)

vocab_int_json = path.join(home_dir, vocab_int_json)

# load json files

print("Loading JSON files, may take a while.")

with open(embedding_json, 'r') as read_file:

self.embeddings = np.array(json.load(read_file))

with open(vocab_int_json, 'r') as read_file:

self.vocab_int = json.load(read_file)

self.int_vocab = {i: word for word, i in self.vocab_int.items()}

# train k nearest neighbor model

print("Training BallTree k-nearest neighbor searcher...")

self.searcher = BallTree(self.embeddings, leaf_size=10)

self.checker = Spell.Spell()

self.num_corrections = num_corrections

self.num_basic_search_results = num_basic_results

self.max_total_res = min(10, num_basic_results+num_corrections)

print("Ready to use.")

開發者ID:weihesdlegend,項目名稱:Autocomplete-System,代碼行數:32,

示例17: fit

​點讚 5

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def fit(self, X):

"""Fit detector. y is optional for unsupervised methods.

Parameters

----------

X : dataframe of shape (n_samples, n_features)

The input samples.

"""

# validate inputs X and y (optional)

X = X.to_numpy()

if self.metric_params is not None:

self.tree_ = BallTree(X, leaf_size=self.leaf_size,

metric=self.metric,

**self.metric_params)

else:

self.tree_ = BallTree(X, leaf_size=self.leaf_size,

metric=self.metric)

self.neigh_.fit(X)

dist_arr, _ = self.neigh_.kneighbors(n_neighbors=self.n_neighbors,

return_distance=True)

dist = self._get_dist_by_method(dist_arr)

self.decision_scores_ = dist.ravel()

self._process_decision_scores()

return self

開發者ID:datamllab,項目名稱:pyodds,代碼行數:31,

示例18: fit

​點讚 4

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def fit(self, X, y=None):

"""Fit detector. y is ignored in unsupervised methods.

Parameters

----------

X : numpy array of shape (n_samples, n_features)

The input samples.

y : Ignored

Not used, present for API consistency by convention.

Returns

-------

self : object

Fitted estimator.

"""

# validate inputs X and y (optional)

X = check_array(X)

self._set_n_classes(y)

self.neigh_.fit(X)

# In certain cases, _tree does not exist for NearestNeighbors

# See Issue #158 (https://github.com/yzhao062/pyod/issues/158)

# n_neighbors = 100

if self.neigh_._tree is not None:

self.tree_ = self.neigh_._tree

else:

if self.metric_params is not None:

self.tree_ = BallTree(X, leaf_size=self.leaf_size,

metric=self.metric,

**self.metric_params)

else:

self.tree_ = BallTree(X, leaf_size=self.leaf_size,

metric=self.metric)

dist_arr, _ = self.neigh_.kneighbors(n_neighbors=self.n_neighbors,

return_distance=True)

dist = self._get_dist_by_method(dist_arr)

self.decision_scores_ = dist.ravel()

self._process_decision_scores()

return self

開發者ID:yzhao062,項目名稱:pyod,代碼行數:48,

示例19: test_ball_tree

​點讚 4

# 需要導入模塊: from sklearn import neighbors [as 別名]

# 或者: from sklearn.neighbors import BallTree [as 別名]

def test_ball_tree(N=1):

np.random.seed(12345)

i = 0

while i < N:

N = np.random.randint(2, 100)

M = np.random.randint(2, 100)

k = np.random.randint(1, N)

ls = np.min([np.random.randint(1, 10), N - 1])

X = np.random.rand(N, M)

BT = BallTree(leaf_size=ls, metric=euclidean)

BT.fit(X)

x = np.random.rand(M)

mine = BT.nearest_neighbors(k, x)

assert len(mine) == k

mine_neighb = np.array([n.key for n in mine])

mine_dist = np.array([n.distance for n in mine])

sort_ix = np.argsort(mine_dist)

mine_dist = mine_dist[sort_ix]

mine_neighb = mine_neighb[sort_ix]

sk = sk_BallTree(X, leaf_size=ls)

theirs_dist, ind = sk.query(x.reshape(1, -1), k=k)

sort_ix = np.argsort(theirs_dist.flatten())

theirs_dist = theirs_dist.flatten()[sort_ix]

theirs_neighb = X[ind.flatten()[sort_ix]]

for j in range(len(theirs_dist)):

np.testing.assert_almost_equal(mine_neighb[j], theirs_neighb[j])

np.testing.assert_almost_equal(mine_dist[j], theirs_dist[j])

print("PASSED")

i += 1

#######################################################################

# Graphs #

#######################################################################

開發者ID:ddbourgin,項目名稱:numpy-ml,代碼行數:44,

注:本文中的sklearn.neighbors.BallTree方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

python中tree 100 6_Python neighbors.BallTree方法代碼示例相关推荐

  1. python中tree 100 6_Python spatial.KDTree方法代码示例

    本文整理汇总了Python中scipy.spatial.KDTree方法的典型用法代码示例.如果您正苦于以下问题:Python spatial.KDTree方法的具体用法?Python spatial ...

  2. python的from_bytes属性_Python parse.quote_from_bytes方法代碼示例

    本文整理匯總了Python中urllib.parse.quote_from_bytes方法的典型用法代碼示例.如果您正苦於以下問題:Python parse.quote_from_bytes方法的具體 ...

  3. JAVA中自己写的util中的chop,Java StringUtils.chop方法代碼示例

    import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類 /** * Tutti i file dentro a /res ve ...

  4. java中move用法_Java IFile.move方法代碼示例

    import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類 /** * * 01. Class0 uses Class1 in requi ...

  5. python中startout是什么意思_Python socket.timeout方法代碼示例

    本文整理匯總了Python中gevent.socket.timeout方法的典型用法代碼示例.如果您正苦於以下問題:Python socket.timeout方法的具體用法?Python socket ...

  6. python terminator_Python turtle.Terminator方法代碼示例

    本文整理匯總了Python中turtle.Terminator方法的典型用法代碼示例.如果您正苦於以下問題:Python turtle.Terminator方法的具體用法?Python turtle. ...

  7. python里turtle.circle什么意思_Python turtle.circle方法代碼示例

    本文整理匯總了Python中turtle.circle方法的典型用法代碼示例.如果您正苦於以下問題:Python turtle.circle方法的具體用法?Python turtle.circle怎麽 ...

  8. python的concatetate_Python tensorflow.truncated_normal_initializer方法代碼示例

    本文整理匯總了Python中tensorflow.truncated_normal_initializer方法的典型用法代碼示例.如果您正苦於以下問題:Python tensorflow.trunca ...

  9. python创建方法draw_Python draw.polygon方法代碼示例

    本文整理匯總了Python中skimage.draw.polygon方法的典型用法代碼示例.如果您正苦於以下問題:Python draw.polygon方法的具體用法?Python draw.poly ...

  10. python turtle color_Python turtle.color方法代碼示例

    本文整理匯總了Python中turtle.color方法的典型用法代碼示例.如果您正苦於以下問題:Python turtle.color方法的具體用法?Python turtle.color怎麽用?P ...

最新文章

  1. Netty面试题 汇总
  2. MATLAB实现图像平移的源代码
  3. linux shell之字符串的更具字符分割和删除字符和文本内容的删除以及内容是否匹配成功
  4. 《Wireshark协议分析从入门到精通》
  5. [UE4]UMG、HUI、Slate之间的区别
  6. android开发我的新浪微博客户端-载入页面UI篇(1.1)
  7. Ubuntu 12.04重启后丢失resolv.conf问题
  8. linux服务器网卡查看,Linux操作系统下如何查看网卡当前版本
  9. 2017年数模国赛B题第一小题的思路过程(个人思路)
  10. “浙大学霸作息表”疯传,网友:越优秀就越努力!
  11. NESSUS 安装 6.12 及使用
  12. Linux DRM(一)Display Server
  13. PS操作01 - PS切手机图标 + Android.9.png图片制作
  14. 【贝壳】(算法工程师)采木【Python】
  15. SQL中日期与时间类型及函数
  16. 安装fabric-2.2.0
  17. 关于PCB行业三巨头的一点个人评价
  18. 古力娜扎秒删合影 修改年龄成亮点,疑似打脸黑粉
  19. Idea上传项目到gitee
  20. 【Web技术】959- JavaScript 如何在线解压 ZIP 文件?

热门文章

  1. win10安装PHP环境
  2. 《商业分析实践指南》(一)
  3. 【经验】AngularJS
  4. Java - Log
  5. 网络字节序与主机字节序的转换 - HEN_MAN的专栏 - 博客频道 - CSDN.NET
  6. 联想个人云 X1 五盘位NAS全网首发评测 值得买吗?
  7. easypoi导入图片_EasyPOI—导出Excel图片问题
  8. 什么是集合竞价和连续竞价
  9. 结构光激光器选择时应该注意的问题二:功率
  10. w ndows无法连接到无线网络,windows无法连接到无线网络,详细教您windows无法连接到无线网络怎么办...