Exemplo n.º 1
0
  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;
  }
Exemplo n.º 2
0
 public void testAddString() {
   m_Filter = getFilter();
   ((Add) m_Filter).setAttributeType(new SelectedTag(Attribute.STRING, Add.TAGS_TYPE));
   testBuffered();
   testType(Attribute.STRING);
 }
Exemplo n.º 3
0
 public void testAddNominal() {
   m_Filter = getFilter();
   ((Add) m_Filter).setNominalLabels("hello,there,bob");
   testBuffered();
   testType(Attribute.NOMINAL);
 }
Exemplo n.º 4
0
 /** Creates a specialized Add */
 public Filter getFilter(int pos) {
   Add af = new Add();
   af.setAttributeIndex("" + (pos + 1));
   return af;
 }
Exemplo n.º 5
0
 public void testAddDate() {
   m_Filter = getFilter();
   ((Add) m_Filter).setAttributeType(new SelectedTag(Attribute.DATE, Add.TAGS_TYPE));
   testBuffered();
   testType(Attribute.DATE);
 }