Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confusion matrix in java

 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,

i want to create an confusion matrix in java. the link show details about the confusion matrix. can any one help me ?

http://en.wikipedia.org/wiki/Confusion_matrix
 
Mahesh Kedari
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you given a try? If so, please share your current code, so that we can add our inputs to it.
 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya. the input file is


Cat Cat
Cat Cat
Cat Dog
Dog Cat
Dog Dog
Cat Dog
Dog Cat
Cat Dog
Rabbit Dog
Cat Cat
Rabbit Dog
Cat Cat
Rabbit Rabbit
Cat Cat
Rabbit Rabbit
Rabbit Rabbit
Rabbit Rabbit
Rabbit Rabbit
Rabbit Rabbit
Rabbit Rabbit
Rabbit Rabbit
Rabbit Rabbit
Rabbit Rabbit
Rabbit Rabbit



my program code

//package deepi;

import java.io.*;

public class ReadFile {



/**

* @param args

*/

public static void main(String[] args) {

try{

int matchCount=0;

int nonMatchCount=0;

int lineCount=0;

FileInputStream fis=new FileInputStream("pos_final");

BufferedReader br=new BufferedReader(new InputStreamReader(fis));

String s=null;

while(true){

s=br.readLine();

if(s==null){

break;

}

if(s.length()!=0){

lineCount++;

String lineData[]=s.split("\t");

// String col3=lineData[1];

//System.out.println("\t"+col3);

// String col4=lineData[2];

// String col5 = col3+"\t"+col4;

//System.out.println(col5);

int x= lineData.length;
int y = lineData.length;
System.out.println("Matrix 1 : " );
for(int i = 0; i < x; i++) {
for(int j = 0; j <= y; j++) {
if(lineData[1]!=lineData[2])
{
System.out.print(" "+(lineData[i]));
}
}
System.out.println();
}
/*

if(col3.equals(col4)){

matchCount++;

}

else{

nonMatchCount++;

}

*/

}

}

// System.out.println("Total non-empty lines:"+lineCount);

// System.out.println("Total matches:"+matchCount);

// System.out.println("Total non-matches:"+nonMatchCount);

}

catch(Exception e){}

}



}

i am unable to find the logic. can any one help me?
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepika,

You have been long enough here to know to UseCodeTags while posting. Please edit your post.

While you want to split a String using whitespace as delimiter, you have to use \s as regex and not \t. Read here.

Escape and use it like \\s while you create lineData array. Also print the stacktrace e.printStackTrace(); in the catch block to see source of Exception.
 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi yaar,

i understand. i want the matrix column output

Cat Dog Rabbit
Cat 5 3 0
Dog 2 3 1
Rabbit 0 2 11


the matrix should match the number of cat and cat, cat and dog, etc.. and print the result..

but i am unable to find the logic. can any oe help me. how to use?

the input is in string and the output should be in int. but how to use that in for loop ?
help me to sort out this problem.
 
Campbell Ritchie
Sheriff
Posts: 48921
58
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to go one period up the periodic table and stop using silicon‑based information processing. Use carbon‑based algorithmic analysis, the carbon being in the form of the graphite found in the middle of a pencil.

Turn your screen off, get a sheet of paper, a pencil and an eraser, and work it out on paper. The eraser is probably the most important piece of hardware here. Once you have reduced the algorithm to really simple terms, it will be easy to convert to code
 
salvin francis
Bartender
Posts: 1274
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You need to go one period up the periodic table and stop using silicon‑based information processing. Use carbon‑based algorithmic analysis, the carbon being in the form of the graphite found in the middle of a pencil.


Truly Amazing Comment.. !!!
 
Winston Gutkowski
Bartender
Pie
Posts: 10417
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Once you have reduced the algorithm to really simple terms, it will be easy to convert to code

@deepika: And if you decide to show it to us, please do as Henry asked you and UseCodeTags (←click).

Winston
 
salvin francis
Bartender
Posts: 1274
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to add a small comment here...

Its quite simple if you use a HashMap here, You can store each count for every occurance that you encounter.
There could be other ways to solve this logic as well.

Its quite similar to what you would do on paper (not the algorithm, the actual procedure)

if you found cat-cat .. You would add one to cat-cat (read the current value and increment it)
if you found cat-dog .. You would add one to cat-dog
and so on ....

I remember vaguely we use the 5 line method where we keep adding lines on paper for every count, and once we reach 5, we strike it off (like counting days in prison cells)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic