⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 miningdata.java

📁 【源码共享系列-JSmartMiner.Eclipse】一个JAVA版本的数据挖掘基本框架体系
💻 JAVA
字号:
package org.scut.DataMining.Core;

public class MiningData 
{
    /** double array value of the data */
	private double[] values;
	/** weight of the data */
	private double weight;
	/** Meta data of the data */
	private MiningMetaData metaData = null;
	public MiningData(int size) 
	{
		// TODO Auto-generated constructor stub
		this.values = new double[size];
		this.weight = 1.0;
	}
	/**
	 * Constructs a MiningData with a double array
	 * @param values
	 */
	public MiningData(double[] values)
	{
		this.values = values;
	}
	/**
	 * Copy constructs a MiningData object
	 * @param data MiningData object to be copied
	 */
	public MiningData(MiningData data)
	{
		this.values = new double[data.values.length];
		for(int i=0;i<this.values.length;i++) this.values[i] = data.values[i];
		this.weight = data.weight;
		this.metaData = data.metaData;
	}
	/**
	 * Gets all the values of the mining data
	 * @return
	 */
	public double[] getAll()
	{
		double[] res = new double[this.values.length];
		for(int i=0;i<res.length;i++)
			res[i]= this.values[i];
		return res;
	}
	/**
	 * Gets the target array
	 * @return
	 */
	public double[] getTarget()
	{
		if(this.metaData == null)
			return new double[0];
		double[] res = new double[this.metaData.getTargetCount()];
		for(int i=0;i<res.length;i++)
			res[i] = this.values[this.metaData.getTargetIndex(i)];
		return res;
	}
	/**
	 * Gets non target array 
	 * @return
	 */
	public double[] getInput()
	{
		if(this.metaData == null)
		{
			double[] res = new double[this.values.length];
			for(int i=0;i<res.length;i++) res[i] = this.values[i];
			return res;
		}
		double[] res = new double[this.metaData.getInputCount()];
		for(int i=0;i<res.length;i++)
			res[i] = this.values[this.metaData.getInputIndex(i)];
		return res;
	}
	/**
	 * Gets the meta data object of the data
	 * @return
	 */
	public MiningMetaData MiningMetaData()
	{
		return this.metaData;
	}
	/**
	 * Sets the mining meta data
	 * @param metaData
	 */
	public void setMiningMetaData(MiningMetaData metaData)
	{
		this.metaData = metaData;
	}
	/**
	 * Gets the size of the mining data
	 * @return
	 */
	public int size()
	{
		return this.values.length;
	}
	/**
	 * Gets the double value at a specified position
	 * @param idx position of the value to be got
	 * @return value of the specified position
	 */
	public double get(int idx)
	{
		return this.values[idx];
	}
	/**
	 * Sets the double value at a specified position
	 * @param idx position of the value to be set
	 * @param value value to be set 
	 */
	public void set(int idx,double value)
	{
		this.values[idx] = value;
	}
	/**
	 * Getst the weight of the data
	 * @return weight value
	 */
	public double getWeight()
	{
		return this.weight;
	}
	/**
	 * Sets the weight of the data
	 * @param value weight value to be set
	 */
	public void setWeight(double value)
	{
		this.weight = value;
	}
	public void normalize()
	{
		for(int i=0;i<this.values.length;i++)
		{
			MiningAttribute ma = this.metaData.getAttribute(i);
			if(ma instanceof NominalAttribute)
			{
				NominalAttribute nom = (NominalAttribute)ma;
				this.values[i] /= nom.getNominalCount();
			}
			if(ma instanceof NumericAttribute)
			{
				NumericAttribute num = (NumericAttribute)ma;
				if(num.getLowerBound() == num.getUpperBound())
					this.values[i] = 1;
				else
					this.values[i] = (this.values[i] - num.getLowerBound())/(num.getUpperBound()-num.getLowerBound());
			}
				
		}
	}
	/**
	 * Transforms the mining data object to a string value
	 */
	public String toString()
	{
		StringBuilder sb = new StringBuilder();	
		for(int i=0;i<this.values.length;i++)
			sb.append(values[i]+ " ");
		return sb.toString();
	}
	

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -