Skip to content

Commit

Permalink
Change topk confidence stats
Browse files Browse the repository at this point in the history
  • Loading branch information
gadelrab committed Apr 26, 2016
1 parent f23a04b commit ee0533d
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,112 @@ public void showStatistics(AssocRulesExtended rules,boolean export, String fileN



}


public void showStatisticsRevisedRules(AssocRulesExtended rules,boolean export, String fileName) throws Exception {

long revisedRulesCount=rules.getRevisedRuleCount();

StringBuilder st=new StringBuilder();
st.append(toString());
st.append('\n');




st.append("topK\ttype\tAvgConf\tdiff\tAvgConfRO\tdiff\tAvgLIFT\tdiff\tAvgLIFTRO\tdiff");
st.append('\n');

StringBuilder stAll=new StringBuilder();
stAll.append("TopK\tMeasurement\tAll Rules\tRevised Rules Only\n");



for(int i=1;i<=10;i++) {
int k=(int)Math.ceil((i*0.1)*revisedRulesCount);


double orgAvgConf= rules.getRevisedRulesConfidenceStats(k, false,false).getAverage();
double orgAvgConfRO= rules.getRevisedRulesConfidenceStats(k, false,true).getAverage();

double orgAvgLift = rules.getRevisedRulesLiftStats(k, false,false).getAverage();
double orgAvgLiftRO = rules.getRevisedRulesLiftStats(k, false,true).getAverage();
// double orgAvgJaccardCoefficient = rules.getJaccardCoefficientStats(k, false,false).getAverage();;


st.append(k+":\tBefore\t");
st.append(String.format("%.5f",orgAvgConf)+"\t__\t");
st.append(String.format("%.5f",orgAvgConfRO)+"\t__\t");
st.append(String.format("%.6f", orgAvgLift)+"\t__\t");
st.append(String.format("%.6f", orgAvgLiftRO)+"\t__\t");
// st.append(String.format("%.5f", orgAvgJaccardCoefficient)+"\t__\t");
st.append('\n');

double newAvgConfidence = rules.getRevisedRulesConfidenceStats(k, true, false).getAverage();
double newAvgConfidenceRO = rules.getRevisedRulesConfidenceStats(k, true, true).getAverage();
double newAvgLift = rules.getRevisedRulesLiftStats(k, true,false).getAverage();
double newAvgLiftRO = rules.getRevisedRulesLiftStats(k, true,true).getAverage();


// double newAvgJaccardCoefficient = rules.getJaccardCoefficientStats(k, true,false).getAverage();;

st.append(k+":\tAfter\t");
st.append(String.format("%.5f", newAvgConfidence)+"\t");
st.append(String.format("%.5f", newAvgConfidence-orgAvgConf)+"\t");
st.append(String.format("%.5f", newAvgConfidenceRO)+"\t");
st.append(String.format("%.5f", newAvgConfidenceRO-orgAvgConfRO)+"\t");

st.append(String.format("%.6f", newAvgLift)+"\t");
st.append(String.format("%.6f", newAvgLift-orgAvgLift)+"\t");
st.append(String.format("%.6f", newAvgLiftRO)+"\t");
st.append(String.format("%.6f", newAvgLiftRO-orgAvgLiftRO)+"\t");
// st.append(String.format("%.5f", newAvgJaccardCoefficient)+"\t");
// st.append(String.format("%.5f", newAvgJaccardCoefficient-orgAvgConf)+"\t");
st.append('\n');

st.append("--------------------------------------------------------------------\n");


st.append('\n');


//-------------------

stAll.append(k+"\t");
stAll.append("Confidence\t");
stAll.append(rules.getConfidenceDiffStats(k,false).toString().replaceAll("DoubleSummaryStatistics","")+"\t");
stAll.append(rules.getConfidenceDiffStats(k,true).toString().replaceAll("DoubleSummaryStatistics","")+"\n");
stAll.append("\tLift\t");
stAll.append(rules.getLiftDiffStats(k,false).toString().replaceAll("DoubleSummaryStatistics","")+"\t");
stAll.append(rules.getLiftDiffStats(k,true).toString().replaceAll("DoubleSummaryStatistics","")+"\n");
// stAll.append("\tJaccard\t");
// stAll.append(rules.getJaccardDiffStats(k,false).toString().replaceAll("DoubleSummaryStatistics","")+"\t");
// stAll.append(rules.getJaccardDiffStats(k,true).toString().replaceAll("DoubleSummaryStatistics","")+"\n");
stAll.append("--------------------------------------------------------------------\n");



}

st.append("RO: revised only\n");



System.out.println(st.toString());
System.out.println(stAll.toString());
if(export){
BufferedWriter bw=FileUtils.getBufferedUTF8Writer(fileName);
bw.write(st.toString());
bw.close();

BufferedWriter bw2=FileUtils.getBufferedUTF8Writer(fileName+".all");
bw2.write(stAll.toString());
bw2.close();
}



}


Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/mpii/frequentrulesminning/MainCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public void run(CommandLine cmd) throws Exception{

String fileName=outputFilePath+".stat";
miner.showStatistics( rulesStrings,export, fileName);
miner.showStatisticsRevisedRules( rulesStrings,export, fileName+".ro");


if(cmd.hasOption(exportDLVConflictOp.getOpt())){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,22 +307,27 @@ public String toStringdlvConflict() {
}


public DoubleSummaryStatistics getConfidenceStats(int k, boolean exception, boolean revisedOnly){
public DoubleSummaryStatistics getRevisedRulesConfidenceStats(int k, boolean exception, boolean revisedOnly){
if(exception)
return rules.stream().filter((r)-> (!revisedOnly)||r.hasExceptions()).limit(k).mapToDouble(AssocRuleWithExceptions::getRevisedConfidence).summaryStatistics();
else
return rules.stream().filter((r)-> (!revisedOnly)||r.hasExceptions()).limit(k).mapToDouble(AssocRuleWithExceptions::getConfidence).summaryStatistics();

}

public DoubleSummaryStatistics getConfidenceStats2(int k, boolean exception, boolean revisedOnly){
public DoubleSummaryStatistics getConfidenceStats(int k, boolean exception, boolean revisedOnly){
if(exception)
return rules.stream().limit(k).filter((r)-> (!revisedOnly)||r.hasExceptions()).mapToDouble(AssocRuleWithExceptions::getRevisedConfidence).summaryStatistics();
else
return rules.stream().limit(k).filter((r)-> (!revisedOnly)||r.hasExceptions()).mapToDouble(AssocRuleWithExceptions::getConfidence).summaryStatistics();

}

public DoubleSummaryStatistics getRevisedRulesConfidenceDiffStats(int k, boolean revisedOnly){

return rules.stream().filter((r)-> (!revisedOnly)||r.hasExceptions()).limit(k).mapToDouble((r)->r.getRevisedConfidence()-r.getConfidence()).summaryStatistics();

}

public DoubleSummaryStatistics getConfidenceDiffStats(int k, boolean revisedOnly){

Expand All @@ -344,6 +349,14 @@ public DoubleSummaryStatistics getJaccardDiffStats(int k, boolean revisedOnly){

}


public DoubleSummaryStatistics getRevisedRulesLiftStats(int k, boolean withException, boolean revisedOnly){
if(withException)
return rules.stream().filter((r)-> (!revisedOnly)||r.hasExceptions()).limit(k).mapToDouble(AssocRuleWithExceptions::getRevisedLift).summaryStatistics();
else
return rules.stream().filter((r)-> (!revisedOnly)||r.hasExceptions()).limit(k).mapToDouble(AssocRuleWithExceptions::getLift).summaryStatistics();
}

public DoubleSummaryStatistics getLiftStats(int k, boolean withException, boolean revisedOnly){
if(withException)
return rules.stream().limit(k).filter((r)-> (!revisedOnly)||r.hasExceptions()).mapToDouble(AssocRuleWithExceptions::getRevisedLift).summaryStatistics();
Expand All @@ -357,7 +370,11 @@ public DoubleSummaryStatistics getLiftDiffStats(int k,boolean revisedOnly){

}

public DoubleSummaryStatistics getRevisedRulesLiftDiffStats(int k,boolean revisedOnly){

return rules.stream().filter((r)-> (!revisedOnly)||r.hasExceptions()).limit(k).mapToDouble((r)->r.getRevisedLift()-r.getLift()).summaryStatistics();

}


// private void sortByLift(List<AssocRuleWithExceptions> rulesToSort) {
Expand Down

0 comments on commit ee0533d

Please sign in to comment.