📄 statisticsminingmodel.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/**
* Title: XELOPES Data Mining Library
* Description: The XELOPES library is an open platform-independent and data-source-independent library for Embedded Data Mining.
* Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
* Company: ZSoft (www.zsoft.ru), Prudsys (www.prudsys.com)
* @author Valentine Stepanenko (valentine.stepanenko@zsoft.ru)
* @author Victor Borichev
* @version 1.0
*/
package com.prudsys.pdm.Models.Statistics;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import com.prudsys.pdm.Adapters.PmmlVersion20.DataDictionary;
import com.prudsys.pdm.Adapters.PmmlVersion20.Header;
import com.prudsys.pdm.Adapters.PmmlVersion20.ModelStats;
import com.prudsys.pdm.Adapters.PmmlVersion20.PMML;
import com.prudsys.pdm.Adapters.PmmlVersion20.TreeModel;
import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.MiningMatrixElement;
import com.prudsys.pdm.Core.MiningModel;
import com.prudsys.pdm.Core.NumericAttribute;
import com.prudsys.pdm.Input.MiningVector;
import com.prudsys.pdm.Utils.PmmlUtils;
/**
* Description of data produced by a statistical mining function. <p>
*
* From PDM CWM extension. <p>
*
* Superclasses:
* <ul>
* <li> MiningModel
* </ul>
*
* In addition, functionality from PMML was added.
* It corresponds to the PMML element ModelStats.
*
* @see MiningModel
* @see com.prudsys.pdm.Adapters.PmmlVersion20.ModelStats
*/
public class StatisticsMiningModel extends MiningModel
{
private Group rootGroup;
/**
* Constructor sets function and algorithm parameters.
*/
public StatisticsMiningModel()
{
function = MiningModel.STATISTICAL_ANALYSIS_FUNCTION;
algorithm = MiningModel.DESCRIPTIVE_ANALYSIS_ALGORITHM;
}
/**
* Applies function of statistics mining model to a mining vector.
* Not supported because the statistics mining model is clearly
* descriptive.
*
* @param miningVector mining vector where the model should be applied
* @return function value of the mining vector
* @throws MiningException always thrown
*/
public double applyModelFunction(MiningVector miningVector)
throws MiningException {
throw new MiningException("Statistics model function cannot be applied.");
}
/**
* General function of applying the statistics mining model to some data.
* Not supported because the statistics mining model is clearly
* descriptive.
*
* @param miningData mining data where the model should be applied
* @return data resulting from the model application
* @throws MiningException always thrown
*/
public MiningMatrixElement applyModel(MiningMatrixElement miningData)
throws MiningException {
throw new MiningException("Statistics model cannot be applied.");
}
/**
* Returns string representation (just few words).
*
* @return string representation
*/
public String toString()
{
return "Statistics mining model";
}
/**
* Returns association rule model as HTML string.
*
* @return model as HTML string
*/
public String toHtmlString()
{
return toString();
}
/**
* Creates PMML document of association rule model.
* PMMLs TreeModel (for grouping) with ModelStats is used.
*
* @param writer writer for PMML model
* @exception MiningException can't create PMML document
* @see com.prudsys.pdm.Adapters.PmmlVersion20.TreeModel
* @see com.prudsys.pdm.Adapters.PmmlVersion20.ModelStats
*/
public void writePmml( Writer writer ) throws MiningException
{
PMML pmml = new PMML();
pmml.setVersion("2.0");
pmml.setHeader((Header)PmmlUtils.getHeader());
MiningDataSpecification metaData = miningSettings.getDataSpecification();
if ( metaData.isTransformed() )
{
pmml.setDataDictionary( (DataDictionary)metaData.getPretransformedMetaData().createPmmlObject() );
pmml.setTransformationDictionary( (com.prudsys.pdm.Adapters.PmmlVersion20.TransformationDictionary)metaData.getMiningTransformationActivity().createPmmlObject() );
}
else
{
pmml.setDataDictionary( (DataDictionary)metaData.createPmmlObject() );
};
TreeModel treeModel = new TreeModel();
treeModel.setModelStats((ModelStats)createPmmlObject());
pmml.addTreeModel(treeModel);
// Add encoding and write to document:
PmmlUtils.setEncoding();
PmmlUtils.marshalPmml(writer, pmml);
}
/**
* Creates PMML element ModelStats.
*
* @return PMML object ModelStats
* @exception MiningException can't create PMML object
* @see com.prudsys.pdm.Adapters.PmmlVersion20.ModelStats
*/
public Object createPmmlObject() throws MiningException
{
if(rootGroup == null) throw new MiningException("rootGroup can't be null run build at first");
if(miningSettings == null || !(miningSettings instanceof StatisticsSettings))
throw new MiningException("Model settings can'e be null");
StatisticsSettings statset = (StatisticsSettings)miningSettings;
MiningAttribute target = statset.getUnivariateTarget();
if(target == null) throw new MiningException("Statistics calculation target attribute can't be null");
ModelStats stats = rootGroup.createPmmlObject(target,(target instanceof CategoricalAttribute)?0:1);
return stats;
}
/**
* Reads PMML document of statistics model.
* PMMLs TreeModel (for grouping) with ModelStats is used.
* Not supported.
*
* @param reader reader for PMML model
* @exception MiningException always thrown
* @see com.prudsys.pdm.Adapters.PmmlVersion20.TreeModel
* @see com.prudsys.pdm.Adapters.PmmlVersion20.ModelStats
*/
public void readPmml( Reader reader ) throws MiningException
{
throw new MiningException("not implemented");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -