All Downloads are FREE. Search and download functionalities are using the official Maven repository.

weka.experiment.ResultMatrixHTML Maven / Gradle / Ivy

Go to download

The Waikato Environment for Knowledge Analysis (WEKA), a machine learning workbench. This is the stable version. Apart from bugfixes, this version does not receive any other updates.

There is a newer version: 3.8.6
Show newest version
/*
 *   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 3 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, see .
 */

/*
 * ResultMatrixHTML.java
 * Copyright (C) 2005-2012 University of Waikato, Hamilton, New Zealand
 *
 */

package weka.experiment;

import weka.core.RevisionUtils;
import weka.core.Utils;

/**
 
 * Generates the matrix output as HTML.
 * 

* * Valid options are:

* *

 -mean-prec <int>
 *  The number of decimals after the decimal point for the mean.
 *  (default: 2)
* *
 -stddev-prec <int>
 *  The number of decimals after the decimal point for the mean.
 *  (default: 2)
* *
 -col-name-width <int>
 *  The maximum width for the column names (0 = optimal).
 *  (default: 0)
* *
 -row-name-width <int>
 *  The maximum width for the row names (0 = optimal).
 *  (default: 25)
* *
 -mean-width <int>
 *  The width of the mean (0 = optimal).
 *  (default: 0)
* *
 -stddev-width <int>
 *  The width of the standard deviation (0 = optimal).
 *  (default: 0)
* *
 -sig-width <int>
 *  The width of the significance indicator (0 = optimal).
 *  (default: 0)
* *
 -count-width <int>
 *  The width of the counts (0 = optimal).
 *  (default: 0)
* *
 -show-stddev
 *  Whether to display the standard deviation column.
 *  (default: no)
* *
 -show-avg
 *  Whether to show the row with averages.
 *  (default: no)
* *
 -remove-filter
 *  Whether to remove the classname package prefixes from the
 *  filter names in datasets.
 *  (default: no)
* *
 -print-col-names
 *  Whether to output column names or just numbers representing them.
 *  (default: no)
* *
 -print-row-names
 *  Whether to output row names or just numbers representing them.
 *  (default: no)
* *
 -enum-col-names
 *  Whether to enumerate the column names (prefixing them with 
 *  '(x)', with 'x' being the index).
 *  (default: no)
* *
 -enum-row-names
 *  Whether to enumerate the row names (prefixing them with 
 *  '(x)', with 'x' being the index).
 *  (default: no)
* * * @author FracPete (fracpete at waikato dot ac dot nz) * @version $Revision: 8034 $ */ public class ResultMatrixHTML extends ResultMatrix { /** for serialization. */ private static final long serialVersionUID = 6672380422544799990L; /** * initializes the matrix as 1x1 matrix. */ public ResultMatrixHTML() { this(1, 1); } /** * initializes the matrix with the given dimensions. * * @param cols the number of columns * @param rows the number of rows */ public ResultMatrixHTML(int cols, int rows) { super(cols, rows); } /** * initializes the matrix with the values from the given matrix. * * @param matrix the matrix to get the values from */ public ResultMatrixHTML(ResultMatrix matrix) { super(matrix); } /** * Returns a string describing the matrix. * * @return a description suitable for * displaying in the experimenter gui */ public String globalInfo() { return "Generates the matrix output as HTML."; } /** * returns the name of the output format. * * @return the display name */ public String getDisplayName() { return "HTML"; } /** * returns the default width for the row names. * * @return the width */ public int getDefaultRowNameWidth() { return 25; } /** * returns the default of whether column names or numbers instead are printed. * * @return true if names instead of numbers are printed */ public boolean getDefaultPrintColNames() { return false; } /** * returns the default of whether column names are prefixed with the index. * * @return true if the names are prefixed */ public boolean getDefaultEnumerateColNames() { return true; } /** * returns the header of the matrix as a string. * * @return the header * @see #m_HeaderKeys * @see #m_HeaderValues */ public String toStringHeader() { return new ResultMatrixPlainText(this).toStringHeader(); } /** * returns the matrix in an HTML table. * * @return the matrix */ public String toStringMatrix() { StringBuffer result; String[][] cells; int i; int n; int cols; result = new StringBuffer(); cells = toArray(); result.append("\n"); // headings result.append(" "); for (n = 0; n < cells[0].length; n++) { if (isRowName(n)) { result.append(""); } else if (isMean(n)) { if (n == 1) cols = 1; else cols = 2; if (getShowStdDev()) cols++; result.append(""); } } result.append("\n"); // data for (i = 1; i < cells.length; i++) { result.append(" "); for (n = 0; n < cells[i].length; n++) { if (isRowName(n)) result.append(""); } result.append("\n"); } result.append("
" + cells[0][n] + ""); result.append("" + cells[0][n] + ""); result.append("
"); else if (isMean(n) || isStdDev(n)) result.append(""); else if (isSignificance(n)) result.append(""); else result.append(""); // content if (cells[i][n].trim().equals("")) result.append(" "); else if (isStdDev(n)) result.append("± " + cells[i][n]); else result.append(cells[i][n]); result.append("
\n"); return result.toString(); } /** * returns returns a key for all the col names, for better readability if * the names got cut off. * * @return the key */ public String toStringKey() { String result; int i; result = "\n" + " \n"; for (i = 0; i < getColCount(); i++) { if (getColHidden(i)) continue; result += " " + "" + "" + "\n"; } result += "
Key
(" + (i+1) + ")" + removeFilterName(m_ColNames[i]) + "
\n"; return result; } /** * returns the summary as string. * * @return the summary */ public String toStringSummary() { String result; String titles; int resultsetLength; int i; int j; String content; if (m_NonSigWins == null) return "-summary data not set-"; result = "\n"; titles = " "; resultsetLength = 1 + Math.max((int)(Math.log(getColCount())/Math.log(10)), (int)(Math.log(getRowCount())/Math.log(10))); for (i = 0; i < getColCount(); i++) { if (getColHidden(i)) continue; titles += ""; } result += titles + "\n"; for (i = 0; i < getColCount(); i++) { if (getColHidden(i)) continue; result += " "; for (j = 0; j < getColCount(); j++) { if (getColHidden(j)) continue; if (j == i) content = Utils.padLeft("-", resultsetLength * 2 + 3); else content = Utils.padLeft("" + m_NonSigWins[i][j] + " (" + m_Wins[i][j] + ")", resultsetLength * 2 + 3); result += ""; } result += "\n"; } result += "
" + getSummaryTitle(i) + "(No. of datasets where [col] >> [row])
" + content.replaceAll(" ", " ") + "" + getSummaryTitle(i) + " = " + removeFilterName(m_ColNames[i]) + "
\n"; return result; } /** * returns the ranking in a string representation. * * @return the ranking */ public String toStringRanking() { String result; int[] ranking; int i; int curr; if (m_RankingWins == null) return "-ranking data not set-"; result = "\n"; result += " " + "" + "" + "" + "" + "\n"; ranking = Utils.sort(m_RankingDiff); for (i = getColCount() - 1; i >= 0; i--) { curr = ranking[i]; if (getColHidden(curr)) continue; result += " " + "" + "" + "" + "" + "\n"; } result += "
>-<><Resultset
" + m_RankingDiff[curr] + "" + m_RankingWins[curr] + "" + m_RankingLosses[curr] + "" + removeFilterName(m_ColNames[curr]) + "
\n"; return result; } /** * Returns the revision string. * * @return the revision */ public String getRevision() { return RevisionUtils.extract("$Revision: 8034 $"); } /** * for testing only. * * @param args ignored */ public static void main(String[] args) { ResultMatrix matrix; int i; int n; matrix = new ResultMatrixHTML(3, 3); // set header matrix.addHeader("header1", "value1"); matrix.addHeader("header2", "value2"); matrix.addHeader("header2", "value3"); // set values for (i = 0; i < matrix.getRowCount(); i++) { for (n = 0; n < matrix.getColCount(); n++) { matrix.setMean(n, i, (i+1)*n); matrix.setStdDev(n, i, ((double) (i+1)*n) / 100); if (i == n) { if (i % 2 == 1) matrix.setSignificance(n, i, SIGNIFICANCE_WIN); else matrix.setSignificance(n, i, SIGNIFICANCE_LOSS); } } } System.out.println("\n\n--> " + matrix.getDisplayName()); System.out.println("\n1. complete\n"); System.out.println(matrix.toStringHeader() + "\n"); System.out.println(matrix.toStringMatrix() + "\n"); System.out.println(matrix.toStringKey()); System.out.println("\n2. complete with std deviations\n"); matrix.setShowStdDev(true); System.out.println(matrix.toStringMatrix()); System.out.println("\n3. cols numbered\n"); matrix.setPrintColNames(false); System.out.println(matrix.toStringMatrix()); System.out.println("\n4. second col missing\n"); matrix.setColHidden(1, true); System.out.println(matrix.toStringMatrix()); System.out.println("\n5. last row missing, rows numbered too\n"); matrix.setRowHidden(2, true); matrix.setPrintRowNames(false); System.out.println(matrix.toStringMatrix()); System.out.println("\n6. mean prec to 3\n"); matrix.setMeanPrec(3); matrix.setPrintRowNames(false); System.out.println(matrix.toStringMatrix()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy