- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要将一个简单的单变量数据集聚类为预设数量的聚类。从技术上讲,它更接近于对数据进行分箱或排序,因为它只是一维的,但我的老板称之为聚类,所以我将坚持使用这个名称。我所在的系统当前使用的方法是 K-means,但这似乎有点矫枉过正。
是否有更好的方法来执行此任务?
其他一些帖子的答案提到了 KDE(核密度估计),但这是一种密度估计方法,它是如何工作的?
我看到 KDE 如何返回密度,但我如何告诉它将数据拆分到容器中?
如何拥有独立于数据的固定数量的垃圾箱(这是我的要求之一)?
更具体地说,如何使用 scikit learn 来实现这一目标?
我的输入文件如下所示:
str ID sls
1 10
2 11
3 9
4 23
5 21
6 11
7 45
8 20
9 11
10 12
我想将 sls 编号分组到簇或箱中,这样:
Cluster 1: [10 11 9 11 11 12]
Cluster 2: [23 21 20]
Cluster 3: [45]
我的输出文件将如下所示:
str ID sls Cluster ID Cluster centroid
1 10 1 10.66
2 11 1 10.66
3 9 1 10.66
4 23 2 21.33
5 21 2 21.33
6 11 1 10.66
7 45 3 45
8 20 2 21.33
9 11 1 10.66
10 12 1 10.66
最佳答案
自己编写代码。那么它最适合您的问题!
样板文件:永远不要假设从网上下载的代码是正确的或最佳的...确保在使用它之前完全理解它。
%matplotlib inline
from numpy import array, linspace
from sklearn.neighbors import KernelDensity
from matplotlib.pyplot import plot
a = array([10,11,9,23,21,11,45,20,11,12]).reshape(-1, 1)
kde = KernelDensity(kernel='gaussian', bandwidth=3).fit(a)
s = linspace(0,50)
e = kde.score_samples(s.reshape(-1,1))
plot(s, e)
from scipy.signal import argrelextrema
mi, ma = argrelextrema(e, np.less)[0], argrelextrema(e, np.greater)[0]
print "Minima:", s[mi]
print "Maxima:", s[ma]
> Minima: [ 17.34693878 33.67346939]
> Maxima: [ 10.20408163 21.42857143 44.89795918]
因此,您的集群是
print a[a < mi[0]], a[(a >= mi[0]) * (a <= mi[1])], a[a >= mi[1]]
> [10 11 9 11 11 12] [23 21 20] [45]
从视觉上看,我们做了这样的分割:
plot(s[:mi[0]+1], e[:mi[0]+1], 'r',
s[mi[0]:mi[1]+1], e[mi[0]:mi[1]+1], 'g',
s[mi[1]:], e[mi[1]:], 'b',
s[ma], e[ma], 'go',
s[mi], e[mi], 'ro')
我们剪切红色标记。绿色标记是我们对聚类中心的最佳估计。
关于machine-learning - 如何在 scikit learn 中使用核密度估计作为一维聚类方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35094454/
我想计算或至少估计放置在相机/kinect 前面的物体的体积。知道我应该从哪里开始吗?你推荐 OpenCV 吗?您是否推荐任何其他技术,例如声纳/激光? 最佳答案 一直在用 OpenCV 2.3 编写
我想知道 MySQL 对表中总行数的 TABLE_ROWS 估计值是否有限制或保证误差范围? 最佳答案 如果它与 SHOW TABLE STATUS 发出的数字类似,则至少会偏差 +/- 40%,有时
我们都曾 mock 过“还剩 X 分钟”的对话框,它似乎过于简单,但我们如何改进它呢? 实际上,输入是截至当前时间的一组下载速度,我们需要使用它来估计完成时间,也许带有确定性指示,例如使用一些 Y%
我们都曾 mock 过“还剩 X 分钟”的对话框,它似乎过于简单,但我们如何改进它呢? 实际上,输入是截至当前时间的一组下载速度,我们需要使用它来估计完成时间,也许带有确定性指示,例如使用一些 Y%
我的理解是 glmnet 采用矩阵,其中每一列都是一个解释变量。 我有一个包含约 10 个解释变量的数据框(其中一些是因子) 我怎样才能使用诸如 y~(x1*x2*x3)+(x4*x5)+x6 之类的
有没有办法估计运行 R 的时间?命令而不实际运行它或仅部分运行命令? 我知道 system.time()存在但需要运行整个命令然后它给出了花费的时间。 最佳答案 还有http://www.ats.uc
在尝试使用 libGD 在 PHP 中调整图像大小之前,我想检查是否有足够的内存来执行操作,因为“内存不足”会完全杀死 PHP 进程并且无法被捕获。 我的想法是,原始图像和新图像中的每个像素 (RGB
我有一些 VHDL 文件,我可以在 Debian 上用 ghdl 编译它们。一些人已将相同的文件改编为 ASIC 实现。算法有一个“大面积”实现和一个“紧凑”实现。我想编写更多实现,但要评估它们,我需
我在 Amazon EC2 上使用 RStudio 0.97.320 (R 2.15.3)。我的数据框有 20 万行和 12 列。 我正在尝试使用大约 1500 个参数来拟合逻辑回归。 R 使用 7%
我目前正在估算一个新项目。假设只有一名开发人员在处理它,我的高水平估计是 25 周。 实际上会有两个开发人员并行工作。减少估计的什么因素是合理的? (我意识到不会是0.5) 最佳答案 根据原始开发人员
我试图更好地理解创建 Postgres 索引所涉及的权衡。作为其中的一部分,我很想了解通常使用多少空间索引。我已通读 the docs ,但找不到这方面的任何信息。我一直在做自己的小实验来创建表和索引
我对 Azure 平台相当陌生,需要一些有关 Azure 搜索服务成本估算的帮助。每个月我们都会有大约 500GB 的文件被放入 Azure Blob 存储中。我们希望仅根据文件名使用 Azure 搜
我正在尝试最大化横截面面板数据中的数据点数量。我的矩阵结构如下,y 轴为年份,x 轴为国家/地区: A B C D 2000 NA 50 NA
如果我有两个时间序列,例如: t f1 #[1] 0.25 #> f2 #[1] 0.25 f phase_difference #[1] 0.5 这意味着时间序列相移 pi/2,因为它们应该根据
我对 Azure 平台相当陌生,需要一些有关 Azure 搜索服务成本估算的帮助。每个月我们都会有大约 500GB 的文件被放入 Azure Blob 存储中。我们希望仅根据文件名使用 Azure 搜
我使用了以下 R 包:mice、mitools 和 pROC。 基本设计:3 个预测变量度量,在 n~1,000 的数据缺失率在 5% 到 70% 之间。 1 个二进制目标结果变量。 分析目标:确定
如何使用 lsmeans 来估计两个成对对比的差异?例如——想象一个连续的 dv 和两个因子预测变量 library(lsmeans) library(tidyverse) dat % fac
我制作了一个使用 BigDecimal 的科学计算器。它有一个特别消耗资源的功能:阶乘。现在,输入任何数字都会启动计算。根据运行此代码的设备,答案会在不同的时间显示。输入像 50000 这样的巨大值!
我已经发出了 sympy 命令来求解某个方程或另一个方程。现在已经好几天了,我不知道什么时候能完成。 我可以使用 sympy 来记录调用 .solvers.solve 的进度吗?如果不是,我如何估计
最近我得到了一些 error C6020: Constant register limit exceeded at variable; more than 1024 registers needed
我是一名优秀的程序员,十分优秀!