?? demoapriori.java
字號:
import java.io.*;import Apriori;public class DemoApriori{ public static void main( String [] args ) throws IOException { if( args.length < 3 ) { System.err.println("<datafilename> <int support> <float confidence>"); System.exit(1); } Apriori apriori = new Apriori(); String inputFileName = args[0]; int minSup = Integer.parseInt(args[1]); float minConf = Float.parseFloat(args[2]); System.err.println(inputFileName+" "+minSup+" "+minConf); printRules( apriori.go( getInput(inputFileName), minSup, minConf ) ); } // // Print out the rules // private static void printRules( RuleSet ruleSet ) { Object o[] = ruleSet.toArray(); for(int i=0; i<o.length; i++) { Rule rule = (Rule)o[i]; System.out.print( "Rule:"); System.out.print( translate(rule.getLhs()) ); System.out.print( "==>" ); System.out.print( translate(rule.getRhs()) ); System.out.print( " (confidence="+rule.getConfidence() ); System.out.println( " support="+rule.getSupport()+")"); } } // // Translate the integers into their column headings // private static String translate( ItemSet s ) { String outStr = new String(); Object o[] = s.toArray(); for(int i=0; i<o.length; i++) { Integer x = (Integer)o[i]; outStr = new String(outStr + translateElement(x)); if( i != (o.length-1) ) outStr = new String(outStr + " and "); } return outStr; } // // Determine column heading by int value // public static String translateElement(Integer i) { String outStr; if( i.compareTo(new Integer(20000)) < 0 ) // i < 20000 outStr=new String("origin="+(i.intValue()-10000)); else if( i.compareTo(new Integer(30000)) < 0 ) // i < 30000 outStr=new String("cylinders="+(i.intValue()-20000)); else if( i.compareTo(new Integer(40000)) < 0 ) // i < 40000 outStr=new String("mpg="+(i.intValue()-30000)); else if( i.compareTo(new Integer(50000)) < 0 ) // i < 50000 outStr=new String("acceleration="+(i.intValue()-40000)); else if( i.compareTo(new Integer(60000)) < 0 ) // i < 60000 outStr=new String("modelyear="+(i.intValue()-50000)); else if( i.compareTo(new Integer(70000)) < 0 ) // i < 70000 outStr=new String("displacement="+(i.intValue()-60000)); else if( i.compareTo(new Integer(80000)) < 0 ) // i < 80000 outStr=new String("horsepower="+(i.intValue()-70000)); else if( i.compareTo(new Integer(90000)) < 0 ) // i < 90000 outStr=new String("weight="+(i.intValue()-80000)); else outStr=new String("catchall="+i); return outStr; } // // Read text file into ItemSets // private static ItemSet getInput(String name) throws IOException { ItemSet set = new ItemSet(); try { File file = new File(name); FileReader is = new FileReader(file); Reader r = new BufferedReader(is); StreamTokenizer st = new StreamTokenizer(r); st.eolIsSignificant(true); st.nextToken(); while( st.ttype != st.TT_EOF ) { ItemSet s = new ItemSet(); int k=1; while( st.ttype != st.TT_EOL ) { s.add(new Integer((int)st.nval+k*10000)); st.nextToken(); k++; } set.add(s); st.nextToken(); } } catch ( IOException e ) { System.err.println(e.toString()); System.exit(1); } return set; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -