public static Instances getDatasetDB(String tableName) throws Exception { Statement st = null; ResultSet rs = null; Connection conn = getDBConn(); String query; switch (tableName) { case "all": query = Config.selectAll; break; case "chiller1": query = Config.selectChiller1; break; case "chiller2": query = Config.selectChiller2; break; case "consumption": query = Config.selectConsumption; break; default: query = Config.selectAll; break; } st = conn.createStatement(); rs = st.executeQuery(query); ResultSetMetaData rsmd = rs.getMetaData(); ArrayList<Attribute> attributes = new ArrayList<Attribute>(); int numAtts = rsmd.getColumnCount(); for (int i = 1; i <= numAtts; i++) { String attName = (rsmd.getColumnName(i)); Attribute att = new Attribute(attName); attributes.add(att); } Instances data = new Instances(tableName, attributes, 0); weka.filters.unsupervised.attribute.Add addAtt = new weka.filters.unsupervised.attribute.Add(); addAtt.setOptions(weka.core.Utils.splitOptions("-T NOM -N class -L T,F -C last")); addAtt.setInputFormat(data); data = Filter.useFilter(data, addAtt); while (rs.next()) { double[] values = new double[numAtts + 1]; for (int i = 1; i <= numAtts; i++) { values[i - 1] = rs.getDouble(i); } data.add(new DenseInstance(1.0, values)); } return data; }
public void testAddString() { m_Filter = getFilter(); ((Add) m_Filter).setAttributeType(new SelectedTag(Attribute.STRING, Add.TAGS_TYPE)); testBuffered(); testType(Attribute.STRING); }
public void testAddNominal() { m_Filter = getFilter(); ((Add) m_Filter).setNominalLabels("hello,there,bob"); testBuffered(); testType(Attribute.NOMINAL); }
/** Creates a specialized Add */ public Filter getFilter(int pos) { Add af = new Add(); af.setAttributeIndex("" + (pos + 1)); return af; }
public void testAddDate() { m_Filter = getFilter(); ((Add) m_Filter).setAttributeType(new SelectedTag(Attribute.DATE, Add.TAGS_TYPE)); testBuffered(); testType(Attribute.DATE); }