File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes confusion matrix in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "confusion matrix in java" Watch "confusion matrix in java" New topic
Author

confusion matrix in java

deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
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

Joined: Nov 28, 2009
Posts: 111
Have you given a try? If so, please share your current code, so that we can add our inputs to it.


Regards,
Mahesh Kedari - Fidus Technologies Ltd.
deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
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
Bartender

Joined: May 31, 2011
Posts: 1776
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

Joined: Jan 23, 2012
Posts: 199
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

Joined: Oct 13, 2005
Posts: 38793
    
  23
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
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

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.. !!!

My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7779
    
  21

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


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: confusion matrix in java