Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
EvaluationUtils.java
Package: Weka-3-2.rar [view]
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 5k
Category:
Windows Develop
Development Platform:
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.
- */
- /*
- * EvaluationUtils.java
- * Copyright (C) 2000 Intelligenesis Corp.
- *
- */
- package weka.classifiers.evaluation;
- import weka.core.FastVector;
- import weka.core.Instance;
- import weka.core.Instances;
- import weka.classifiers.DistributionClassifier;
- import java.util.Random;
- /**
- * Contains utility functions for generating lists of predictions in
- * various manners.
- *
- * @author Len Trigg (len@intelligenesis.net)
- * @version $Revision: 1.6 $
- */
- public class EvaluationUtils {
- /** Seed used to randomize data in cross-validation */
- private int m_Seed = 1;
- /** Sets the seed for randomization during cross-validation */
- public void setSeed(int seed) { m_Seed = seed; }
- /** Gets the seed for randomization during cross-validation */
- public int getSeed() { return m_Seed; }
- /**
- * Generate a bunch of predictions ready for processing, by performing a
- * cross-validation on the supplied dataset.
- *
- * @param classifier the DistributionClassifier to evaluate
- * @param data the dataset
- * @param numFolds the number of folds in the cross-validation.
- * @exception Exception if an error occurs
- */
- public FastVector getCVPredictions(DistributionClassifier classifier,
- Instances data,
- int numFolds)
- throws Exception {
- FastVector predictions = new FastVector();
- Instances runInstances = new Instances(data);
- Random random = new Random(m_Seed);
- runInstances.randomize(random);
- if (runInstances.classAttribute().isNominal() && (numFolds > 1)) {
- runInstances.stratify(numFolds);
- }
- int inst = 0;
- for (int fold = 0; fold < numFolds; fold++) {
- Instances train = runInstances.trainCV(numFolds, fold);
- Instances test = runInstances.testCV(numFolds, fold);
- FastVector foldPred = getTrainTestPredictions(classifier, train, test);
- predictions.appendElements(foldPred);
- }
- return predictions;
- }
- /**
- * Generate a bunch of predictions ready for processing, by performing a
- * evaluation on a test set after training on the given training set.
- *
- * @param classifier the DistributionClassifier to evaluate
- * @param train the training dataset
- * @param test the test dataset
- * @exception Exception if an error occurs
- */
- public FastVector getTrainTestPredictions(DistributionClassifier classifier,
- Instances train, Instances test)
- throws Exception {
- classifier.buildClassifier(train);
- return getTestPredictions(classifier, test);
- }
- /**
- * Generate a bunch of predictions ready for processing, by performing a
- * evaluation on a test set assuming the classifier is already trained.
- *
- * @param classifier the pre-trained DistributionClassifier to evaluate
- * @param test the test dataset
- * @exception Exception if an error occurs
- */
- public FastVector getTestPredictions(DistributionClassifier classifier,
- Instances test)
- throws Exception {
- FastVector predictions = new FastVector();
- for (int i = 0; i < test.numInstances(); i++) {
- if (!test.instance(i).classIsMissing()) {
- predictions.addElement(getPrediction(classifier, test.instance(i)));
- }
- }
- return predictions;
- }
- /**
- * Generate a single prediction for a test instance given the pre-trained
- * classifier.
- *
- * @param classifier the pre-trained DistributionClassifier to evaluate
- * @param test the test instance
- * @exception Exception if an error occurs
- */
- public Prediction getPrediction(DistributionClassifier classifier,
- Instance test)
- throws Exception {
- double actual = test.classValue();
- double [] dist = classifier.distributionForInstance(test);
- if (test.classAttribute().isNominal()) {
- return new NominalPrediction(actual, dist, test.weight());
- } else {
- return new NumericPrediction(actual, dist[0], test.weight());
- }
- }
- }