Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //################# PGM START ##############################################
- import java.util.Scanner;
- /*
- * function to calculate sensitivity or specificity
- * sensitivity = true positive rate = the actual positive which are identified correctly
- * specificity = true negative rate = the actual negative which are identified correctly
- */
- public class Solution {
- public double solution(int A[],int B[],boolean q){
- double result=0;
- double TP=0; //true positive (1 & 1)
- double FP=0; // true negative (0 & 1)
- double FN=0; // false positive (1 & 0)
- double TN=0; //false negative (0 & 0)
- //finding the values of TP,FP,FN,TN
- for(int i=0;i<A.length;i++){
- if(A[i]==1 && B[i]==1){
- TP++;
- }else if(A[i]==1 && B[i]==0){
- FN++;
- }else if(A[i]==0 && B[i]==1){
- FP++;
- }else{
- TN++;
- }
- }
- //if q is false calculate sensitivity
- //else calculate specificity
- if(q==false)
- result=TP/(TP+FN);
- else
- result=TN/(FP+TN);
- return result*100;
- }
- public static void main(String[] args) {
- Scanner s=new Scanner(System.in);
- Solution obj=new Solution();
- boolean q=false;
- int selection;
- //requesting user to enter number of patients
- System.out.print("Enter the number of patients on test is conducted:");
- int N=s.nextInt();
- int A[]=new int[N]; //stores actual data
- int B[]=new int[N]; //stores predicted value
- //requesting user for actual data
- System.out.print("\nEnter the actual values, 0 -> negative & 1 -> possitive:");
- for(int i=0;i<N;i++){
- A[i]=s.nextInt();
- }
- //requesting user for predicted data
- System.out.print("\nEnter the predicted values, 0 -> negative & 1-> possitive:");
- for(int i=0;i<N;i++){
- B[i]=s.nextInt();
- }
- //providing options for user
- System.out.print("Choice\n\n1.Sensitivity\n2.Specificity\n\nEnter your choice:");
- selection=s.nextInt();
- if(selection==1)
- q=false;
- else if(selection==2)
- q=true;
- else
- System.out.println("Wrong entry");
- if(selection==1)
- System.out.println("Sensitivity = "+obj.solution(A,B,q));
- else
- System.out.println("Specificity = "+obj.solution(A,B,q));
- }
- }
- //############################## PGM END ####################################
- OUTPUT
- #######
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement