weka Loading Instances Loading from Database

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

Example

Many databases can be used in Weka. Firstly, the DatabaseUtils.props file must be edited to match your database; specifically you must provide your database's name, location, port and correct driver.

jdbcDriver=org.gjt.mm.mysql.Driver
jdbcURL=jdbc:mysql://localhost:3306/my_database

Then the database can be loaded by using some simple code.

import weka.core.Instances;
import weka.experiment.InstanceQuery;
...
InstanceQuery query = new InstanceQuery();
query.setUsername("user");
query.setPassword("pass");
query.setQuery("select * from mytable");
Instances data = query.retrieveInstances();

Some notes about loading from a database:

  • Make sure the correct JDBC driver is in your classpath.
  • If you are using Microsoft Access then the JDBC-ODBC-driver which comes with the JDK can be used.
  • The InstanceQuery method converts VARCHAR to nominal attributes and TEXT to string attributes. A filter, such as NominalToString or StringToNormal, can convert the attributes back to their correct type.


Got any weka Question?