📄 apriori.java
字号:
} } m_minSupport -= m_delta; m_minSupport = (m_minSupport < m_lowerBoundMinSupport) ? 0 : m_minSupport; necSupport = (int)(m_minSupport * (double)instances.numInstances()+0.5); m_cycles++; if (m_verbose) { if (m_Ls.size() > 1) { System.out.println(toString()); } } } while ((m_allTheRules[0].size() < m_numRules) && (m_minSupport >= m_lowerBoundMinSupport) /* (necSupport >= lowerBoundNumInstancesSupport)*/ /* (Utils.grOrEq(m_minSupport, m_lowerBoundMinSupport)) */ && (necSupport >= 1)); m_minSupport += m_delta; } /** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ public Enumeration listOptions() { String string1 = "\tThe required number of rules. (default = " + m_numRules + ")", string2 = "\tThe minimum confidence of a rule. (default = " + m_minMetric + ")", string3 = "\tThe delta by which the minimum support is decreased in\n", string4 = "\teach iteration. (default = " + m_delta + ")", string5 = "\tThe lower bound for the minimum support. (default = " + m_lowerBoundMinSupport + ")", string6 = "\tIf used, rules are tested for significance at\n", string7 = "\tthe given level. Slower. (default = no significance testing)", string8 = "\tIf set the itemsets found are also output. (default = no)", stringType = "\tThe metric type by which to rank rules. (default = " +"confidence)"; FastVector newVector = new FastVector(9); newVector.addElement(new Option(string1, "N", 1, "-N <required number of rules output>")); newVector.addElement(new Option(stringType, "T", 1, "-T <0=confidence | 1=lift | " +"2=leverage | 3=Conviction>")); newVector.addElement(new Option(string2, "C", 1, "-C <minimum metric score of a rule>")); newVector.addElement(new Option(string3 + string4, "D", 1, "-D <delta for minimum support>")); newVector.addElement(new Option("\tUpper bound for minimum support. " +"(default = 1.0)", "U", 1, "-U <upper bound for minimum support>")); newVector.addElement(new Option(string5, "M", 1, "-M <lower bound for minimum support>")); newVector.addElement(new Option(string6 + string7, "S", 1, "-S <significance level>")); newVector.addElement(new Option(string8, "S", 0, "-I")); newVector.addElement(new Option("\tRemove columns that contain " +"all missing values (default = no)" , "R", 0, "-R")); newVector.addElement(new Option("\tReport progress iteratively. (default " +"= no)", "V", 0, "-V")); return newVector.elements(); } /** * Parses a given list of options. Valid options are:<p> * * -N required number of rules <br> * The required number of rules (default: 10). <p> * * -T type of metric by which to sort rules <br> * 0 = confidence | 1 = lift | 2 = leverage | 3 = Conviction. <p> * * -C minimum metric score of a rule <br> * The minimum confidence of a rule (default: 0.9). <p> * * -D delta for minimum support <br> * The delta by which the minimum support is decreased in * each iteration (default: 0.05). * * -U upper bound for minimum support <br> * The upper bound for minimum support. Don't explicitly look for * rules with more than this level of support. <p> * * -M lower bound for minimum support <br> * The lower bound for the minimum support (default = 0.1). <p> * * -S significance level <br> * If used, rules are tested for significance at * the given level. Slower (default = no significance testing). <p> * * -I <br> * If set the itemsets found are also output (default = no). <p> * * -V <br> * If set then progress is reported iteratively during execution. <p> * * -R <br> * If set then columns that contain all missing values are removed from * the data. <p> * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { resetOptions(); String numRulesString = Utils.getOption('N', options), minConfidenceString = Utils.getOption('C', options), deltaString = Utils.getOption('D', options), maxSupportString = Utils.getOption('U', options), minSupportString = Utils.getOption('M', options), significanceLevelString = Utils.getOption('S', options); String metricTypeString = Utils.getOption('T', options); if (metricTypeString.length() != 0) { setMetricType(new SelectedTag(Integer.parseInt(metricTypeString), TAGS_SELECTION)); } if (numRulesString.length() != 0) { m_numRules = Integer.parseInt(numRulesString); } if (minConfidenceString.length() != 0) { m_minMetric = (new Double(minConfidenceString)).doubleValue(); } if (deltaString.length() != 0) { m_delta = (new Double(deltaString)).doubleValue(); } if (maxSupportString.length() != 0) { setUpperBoundMinSupport((new Double(maxSupportString)).doubleValue()); } if (minSupportString.length() != 0) { m_lowerBoundMinSupport = (new Double(minSupportString)).doubleValue(); } if (significanceLevelString.length() != 0) { m_significanceLevel = (new Double(significanceLevelString)).doubleValue(); } m_outputItemSets = Utils.getFlag('I', options); m_verbose = Utils.getFlag('V', options); setRemoveAllMissingCols(Utils.getFlag('R', options)); } /** * Gets the current settings of the Apriori object. * * @return an array of strings suitable for passing to setOptions */ public String [] getOptions() { String [] options = new String [16]; int current = 0; if (m_outputItemSets) { options[current++] = "-I"; } if (getRemoveAllMissingCols()) { options[current++] = "-R"; } options[current++] = "-N"; options[current++] = "" + m_numRules; options[current++] = "-T"; options[current++] = "" + m_metricType; options[current++] = "-C"; options[current++] = "" + m_minMetric; options[current++] = "-D"; options[current++] = "" + m_delta; options[current++] = "-U"; options[current++] = ""+m_upperBoundMinSupport; options[current++] = "-M"; options[current++] = ""+m_lowerBoundMinSupport; options[current++] = "-S"; options[current++] = "" + m_significanceLevel; while (current < options.length) { options[current++] = ""; } return options; } /** * Outputs the size of all the generated sets of itemsets and the rules. */ public String toString() { StringBuffer text = new StringBuffer(); if (m_Ls.size() <= 1) return "\nNo large itemsets and rules found!\n"; text.append("\nApriori\n=======\n\n"); text.append("Minimum support: " + Utils.doubleToString(m_minSupport,2) + '\n'); text.append("Minimum metric <"); switch(m_metricType) { case CONFIDENCE: text.append("confidence>: "); break; case LIFT: text.append("lift>: "); break; case LEVERAGE: text.append("leverage>: "); break; case CONVICTION: text.append("conviction>: "); break; } text.append(Utils.doubleToString(m_minMetric,2)+'\n'); if (m_significanceLevel != -1) text.append("Significance level: "+ Utils.doubleToString(m_significanceLevel,2)+'\n'); text.append("Number of cycles performed: " + m_cycles+'\n'); text.append("\nGenerated sets of large itemsets:\n"); for (int i = 0; i < m_Ls.size(); i++) { text.append("\nSize of set of large itemsets L("+(i+1)+"): "+ ((FastVector)m_Ls.elementAt(i)).size()+'\n'); if (m_outputItemSets) { text.append("\nLarge Itemsets L("+(i+1)+"):\n"); for (int j = 0; j < ((FastVector)m_Ls.elementAt(i)).size(); j++) text.append(((ItemSet)((FastVector)m_Ls.elementAt(i)).elementAt(j)). toString(m_instances)+"\n"); } } text.append("\nBest rules found:\n\n"); for (int i = 0; i < m_allTheRules[0].size(); i++) { text.append(Utils.doubleToString((double)i+1, (int)(Math.log(m_numRules)/Math.log(10)+1),0)+ ". " + ((ItemSet)m_allTheRules[0].elementAt(i)). toString(m_instances) + " ==> " + ((ItemSet)m_allTheRules[1].elementAt(i)). toString(m_instances) +" conf:("+ Utils.doubleToString(((Double)m_allTheRules[2]. elementAt(i)).doubleValue(),2)+")"); if (m_metricType != CONFIDENCE || m_significanceLevel != -1) { text.append((m_metricType == LIFT ? " <" : "")+" lift:("+ Utils.doubleToString(((Double)m_allTheRules[3]. elementAt(i)).doubleValue(),2) +")"+(m_metricType == LIFT ? ">" : "")); text.append((m_metricType == LEVERAGE ? " <" : "")+" lev:("+ Utils.doubleToString(((Double)m_allTheRules[4]. elementAt(i)).doubleValue(),2) +")"); text.append(" ["+ (int)(((Double)m_allTheRules[4].elementAt(i)) .doubleValue() * (double)m_instances.numInstances()) +"]"+(m_metricType == LEVERAGE ? ">" : "")); text.append((m_metricType == CONVICTION ? " <" : "")+" conv:("+ Utils.doubleToString(((Double)m_allTheRules[5]. elementAt(i)).doubleValue(),2) +")"+(m_metricType == CONVICTION ? ">" : "")); } text.append('\n'); } return text.toString(); } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String removeAllMissingColsTipText() { return "Remove columns with all missing values."; } /** * Remove columns containing all missing values. * @param r true if cols are to be removed. */ public void setRemoveAllMissingCols(boolean r) { m_removeMissingCols = r; } /** * Returns whether columns containing all missing values are to be removed * @return true if columns are to be removed. */ public boolean getRemoveAllMissingCols() { return m_removeMissingCols; } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String upperBoundMinSupportTipText() { return "Upper bound for minimum support. Start iteratively decreasing " +"minimum support from this value."; } /** * Get the value of upperBoundMinSupport. * * @return Value of upperBoundMinSupport. */ public double getUpperBoundMinSupport() { return m_upperBoundMinSupport; } /** * Set the value of upperBoundMinSupport. * * @param v Value to assign to upperBoundMinSupport. */ public void setUpperBoundMinSupport(double v) { m_upperBoundMinSupport = v; } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String lowerBoundMinSupportTipText() { return "Lower bound for minimum support."; } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -