python - 如何将球树应用于熊猫 df 列
问题描述
我将球树聚类算法应用于我的 pandas df 列sp500news3['phrase_vector']
(示例如下)
我已经试过了
from sklearn.neighbors import BallTree
import numpy as np
tree = BallTree(sp500news3['phrase_vector'])
print(tree.query_radius(sp500news3['phrase_vector'][:1], r=0.3, count_only=True))
ind = tree.query_radius(sp500news3['phrase_vector'][:1], r=0.3)
print(ind) # indices of neighbors within distance 0.
返回ValueError: setting an array element with a sequence.
指向此行tree = BallTree(sp500news3['phrase_vector'])
sp500news3['phrase_vector']
0 [-1.464906, 1.6889418, -1.750461, 0.54739094, ...
1 [-1.2658471, 1.250561, 0.59811795, -4.5680103,...
2 [-2.5886421, 3.0229673, -1.7595533, -3.804605,...
3 [-1.9567089, 3.6295261, 0.44644845, -2.5851138...
4 [-0.8531435, 1.686829, -2.1624348, -2.82526, 0...
解决方案
推荐阅读
- javascript - 错误 TS2339:“用户 | 类型”上不存在属性“管理员” 不明确的'
- azure - Terraform 应用服务不会连接到存储帐户
- python - 将 Pytest 作为子进程调用
- vb.net - 根据另一个datagridview检查值填充datagridview vb.net
- angular - Angular Service Worker 每次(软)重新加载(Chrome)时都会获取所有文件
- python - 如何从列表中删除一个元素
- node.js - 如何在 mern 应用上显示错误消息
- javascript - 如何在 JS 中在对象数组中找到两个具有相同键/值但输出的对象具有更高的键/值
- r - 使用 lmLst 和区间函数获得每位患者的截距和斜率(作为重复测量研究中的诊断)
- java - 一个类的多个 bean 实例填充了 application.properties 中的值