我正在研究一个聚类程序,并且有一个 double 据集,我需要对其进行归一化,以确保每个 double (变量)具有相同的影响。
我想使用最小-最大归一化,其中每个变量的最小值和最大值都是确定的,但我不确定如何在我的数据集上用 Java 实现它。有人有什么建议吗?
最佳答案
Encog Project wiki给出 utility class进行范围归一化。
构造函数采用输入和规范化数据的高值和低值。
/**
* Construct the normalization utility, allow the normalization range to be specified.
* @param dataHigh The high value for the input data.
* @param dataLow The low value for the input data.
* @param dataHigh The high value for the normalized data.
* @param dataLow The low value for the normalized data.
*/
public NormUtil(double dataHigh, double dataLow, double normalizedHigh, double normalizedLow) {
this.dataHigh = dataHigh;
this.dataLow = dataLow;
this.normalizedHigh = normalizedHigh;
this.normalizedLow = normalizedLow;
然后您可以对样本使用normalize
方法。
/**
* Normalize x.
* @param x The value to be normalized.
* @return The result of the normalization.
*/
public double normalize(double x) {
return ((x - dataLow)
/ (dataHigh - dataLow))
* (normalizedHigh - normalizedLow) + normalizedLow;
}
要找到数据集的最小值和最大值,请使用此问题的一个答案:Finding the max/min value in an array of primitives using Java .
关于java - Java 中数据集的规范化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30680389/