maths.ConfusionMatrix Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jstat Show documentation
Show all versions of jstat Show documentation
Java Library for Statistical Analysis.
The newest version!
package maths;
import datasets.DenseMatrixSet;
import datastructs.RowBuilder;
import datastructs.RowType;
import utils.Pair;
import javax.swing.*;
import javax.swing.table.TableModel;
import javax.swing.event.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* ConfusionMatrix
*/
public class ConfusionMatrix extends JFrame {
public ConfusionMatrix(List> classes, List names){
super("Confusion Matrix");
if(classes == null){
throw new IllegalArgumentException("Classes should not be null");
}
this.names = names;
data = new DenseMatrixSet<>(RowType.Type.INTEGER_VECTOR, new RowBuilder(), names.size(), names.size(), -1);
Map> result = new HashMap<>();
for(int i=0; i pair = classes.get(i);
Integer classIdx = pair.first;
if(result.containsKey(classIdx)){
result.get(classIdx).add(classIdx, 1);
}
else{
List values = new ArrayList<>(names.size());
for(int j=0; j names;
private DenseMatrixSet data;
private JPanel contentPane;
private JLabel gradesLabel;
private JTable gradesTable;
private JScrollPane scroll;
private static class MatrixModel implements TableModel
{
MatrixModel(List names, DenseMatrixSet data){
this.names = names;
this.data = data;
}
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {}
public void addTableModelListener(TableModelListener l) {}
public void removeTableModelListener(TableModelListener l) {}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
public Class> getColumnClass(int col) {
return Integer.class;
}
public int getRowCount() {
return data.m();
}
public int getColumnCount() {
return names.size();
}
public String getColumnName(int col) {
return names.get(col);
}
public Object getValueAt(int row, int col) {
return data.getEntry(row, col);
}
private List names;
private DenseMatrixSet data;
}
}