本文整理汇总了Java中weka.experiment.InstanceQuery类的典型用法代码示例。如果您正苦于以下问题:Java InstanceQuery类的具体用法?Java InstanceQuery怎么用?Java InstanceQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InstanceQuery类属于weka.experiment包,在下文中一共展示了InstanceQuery类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: buildAssociate
import weka.experiment.InstanceQuery; //导入依赖的package包/类
public static String buildAssociate() throws Exception {
InstanceQuery query = new InstanceQuery();
query.setUsername("root");
query.setPassword("cs6310");
query.setDatabaseURL("jdbc:mysql://localhost/system?#characterEncoding=UTF-8");
query.setQuery("select * from courses_sessions;");
// You can declare that your data set is sparse
// query.setSparseData(true);
Instances data = query.retrieveInstances();
data.setClassIndex(data.numAttributes() - 1);
final NumericToNominal filter = new NumericToNominal();
filter.setInputFormat(data);
data = Filter.useFilter(data, filter);
if (data.size() > 0) {
// build associator
Apriori apriori = new Apriori();
apriori.setClassIndex(data.classIndex());
apriori.buildAssociations(data);
return String.valueOf(apriori);
} else {
return "Not enough data provided";
}
}
开发者ID:ejesposito,项目名称:CS6310O01,代码行数:26,代码来源:WekaDataMiner.java
示例2: setInstancesFromDBQ
import weka.experiment.InstanceQuery; //导入依赖的package包/类
/**
* Loads instances from an SQL query the user provided with the
* SqlViewerDialog, then loads the instances in a background process. This is
* done in the IO thread, and an error message is popped up if the IO thread
* is busy.
*
* @param url the database URL
* @param user the user to connect as
* @param pw the password of the user
* @param query the query for retrieving instances from
* @param sparse whether to create sparse or non-sparse instances
*/
public void setInstancesFromDBQ(String url, String user,
String pw, String query,
boolean sparse) {
if (m_IOThread == null) {
try {
InstanceQuery InstQ = new InstanceQuery();
InstQ.setDatabaseURL(url);
InstQ.setUsername(user);
InstQ.setPassword(pw);
InstQ.setQuery(query);
InstQ.setSparseData(sparse);
// we have to disconnect, otherwise we can't change the DB!
if (InstQ.isConnected())
InstQ.disconnectFromDatabase();
InstQ.connectToDatabase();
try {
addUndoPoint();
} catch (Exception ignored) {}
setInstancesFromDB(InstQ);
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,
"Problem connecting to database:\n"
+ ex.getMessage(),
"Load Instances",
JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(this,
"Can't load at this time,\n"
+ "currently busy with other IO",
"Load Instances",
JOptionPane.WARNING_MESSAGE);
}
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:50,代码来源:PreprocessPanel.java
示例3: setInstancesFromDB
import weka.experiment.InstanceQuery; //导入依赖的package包/类
/**
* Loads instances from a database
*
* @param iq the InstanceQuery object to load from (this is assumed
* to have been already connected to a valid database).
*/
public void setInstancesFromDB(final InstanceQuery iq) {
if (m_IOThread == null) {
m_IOThread = new Thread() {
@Override
public void run() {
try {
m_Log.statusMessage("Reading from database...");
final Instances i = iq.retrieveInstances();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
setInstances(new Instances(i));
}
});
iq.disconnectFromDatabase();
} catch (Exception ex) {
m_Log.statusMessage("Problem executing DB query "+m_SQLQ);
JOptionPane.showMessageDialog(PreprocessPanel.this,
"Couldn't read from database:\n"
+ ex.getMessage(),
"Load Instances",
JOptionPane.ERROR_MESSAGE);
}
m_IOThread = null;
}
};
m_IOThread.setPriority(Thread.MIN_PRIORITY); // UI has most priority
m_IOThread.start();
} else {
JOptionPane.showMessageDialog(this,
"Can't load at this time,\n"
+ "currently busy with other IO",
"Load Instances",
JOptionPane.WARNING_MESSAGE);
}
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:45,代码来源:PreprocessPanel.java
示例4: setInstancesFromDB
import weka.experiment.InstanceQuery; //导入依赖的package包/类
/**
* Loads instances from a database
*
* @param iq the InstanceQuery object to load from (this is assumed
* to have been already connected to a valid database).
*/
public void setInstancesFromDB(final InstanceQuery iq) {
if (m_IOThread == null) {
m_IOThread = new Thread() {
public void run() {
try {
m_Log.statusMessage("Reading from database...");
final Instances i = iq.retrieveInstances();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
setInstances(new Instances(i));
}
});
iq.disconnectFromDatabase();
} catch (Exception ex) {
m_Log.statusMessage("Problem executing DB query "+m_SQLQ);
JOptionPane.showMessageDialog(PreprocessPanel.this,
"Couldn't read from database:\n"
+ ex.getMessage(),
"Load Instances",
JOptionPane.ERROR_MESSAGE);
}
m_IOThread = null;
}
};
m_IOThread.setPriority(Thread.MIN_PRIORITY); // UI has most priority
m_IOThread.start();
} else {
JOptionPane.showMessageDialog(this,
"Can't load at this time,\n"
+ "currently busy with other IO",
"Load Instances",
JOptionPane.WARNING_MESSAGE);
}
}
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:44,代码来源:PreprocessPanel.java
示例5: setInstancesFromDBQ
import weka.experiment.InstanceQuery; //导入依赖的package包/类
/**
* Loads instances from an SQL query the user provided with the
* SqlViewerDialog, then loads the instances in a background process. This is
* done in the IO thread, and an error message is popped up if the IO thread
* is busy.
* @param url the database URL
* @param user the user to connect as
* @param pw the password of the user
* @param query the query for retrieving instances from
*/
public void setInstancesFromDBQ(String url, String user,
String pw, String query) {
if (m_IOThread == null) {
try {
InstanceQuery InstQ = new InstanceQuery();
InstQ.setDatabaseURL(url);
InstQ.setUsername(user);
InstQ.setPassword(pw);
InstQ.setQuery(query);
// we have to disconnect, otherwise we can't change the DB!
if (InstQ.isConnected())
InstQ.disconnectFromDatabase();
InstQ.connectToDatabase();
try {
addUndoPoint();
} catch (Exception ignored) {}
setInstancesFromDB(InstQ);
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,
Messages.getInstance().getString("PreprocessPanel_SetInstancesFromDBQ_JOptionPaneShowMessageDialog_Text_First")
+ ex.getMessage(),
Messages.getInstance().getString("PreprocessPanel_SetInstancesFromDBQ_JOptionPaneShowMessageDialog_Text_Second"),
JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(this,
Messages.getInstance().getString("PreprocessPanel_SetInstancesFromDBQ_JOptionPaneShowMessageDialog_Text_Third"),
Messages.getInstance().getString("PreprocessPanel_SetInstancesFromDBQ_JOptionPaneShowMessageDialog_Text_Fourth"),
JOptionPane.WARNING_MESSAGE);
}
}
开发者ID:williamClanton,项目名称:jbossBA,代码行数:45,代码来源:PreprocessPanel.java
示例6: setInstancesFromDB
import weka.experiment.InstanceQuery; //导入依赖的package包/类
/**
* Loads instances from a database
*
* @param iq the InstanceQuery object to load from (this is assumed
* to have been already connected to a valid database).
*/
public void setInstancesFromDB(final InstanceQuery iq) {
if (m_IOThread == null) {
m_IOThread = new Thread() {
public void run() {
try {
m_Log.statusMessage(Messages.getInstance().getString("PreprocessPanel_SetInstancesFromDB_Run_Log_StatusMessage_Text_First"));
final Instances i = iq.retrieveInstances();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
setInstances(new Instances(i));
}
});
iq.disconnectFromDatabase();
} catch (Exception ex) {
m_Log.statusMessage(Messages.getInstance().getString("PreprocessPanel_SetInstancesFromDB_Run_Log_StatusMessage_Text_Second") + m_SQLQ);
JOptionPane.showMessageDialog(PreprocessPanel.this,
Messages.getInstance().getString("PreprocessPanel_SetInstancesFromDB_Run_JOptionPaneShowMessageDialog_Text_First")
+ ex.getMessage(),
Messages.getInstance().getString("PreprocessPanel_SetInstancesFromDB_Run_JOptionPaneShowMessageDialog_Text_Second"),
JOptionPane.ERROR_MESSAGE);
}
m_IOThread = null;
}
};
m_IOThread.setPriority(Thread.MIN_PRIORITY); // UI has most priority
m_IOThread.start();
} else {
JOptionPane.showMessageDialog(this,
Messages.getInstance().getString("PreprocessPanel_SetInstancesFromDB_Run_JOptionPaneShowMessageDialog_Text_Third"),
Messages.getInstance().getString("PreprocessPanel_SetInstancesFromDB_Run_JOptionPaneShowMessageDialog_Text_Fourth"),
JOptionPane.WARNING_MESSAGE);
}
}
开发者ID:williamClanton,项目名称:jbossBA,代码行数:43,代码来源:PreprocessPanel.java
示例7: getDataSet
import weka.experiment.InstanceQuery; //导入依赖的package包/类
/**
* Return the full data set in batch mode (header and all intances at once).
*
* @return the structure of the data set as an empty set of Instances
* @throws IOException if there is no source or parsing fails
*/
public Instances getDataSet() throws IOException {
if (m_DataBaseConnection == null && dataSource == null) {
throw new IOException("No source database has been specified");
}
if (getRetrieval() == INCREMENTAL) {
throw new IOException("Cannot mix getting Instances in both incremental and batch modes");
}
setRetrieval(BATCH);
Instances result = null;
// TODO perhaps add option for sparse data
try {
InstanceQuery iq = new InstanceQuery();
iq.setDataSource(dataSource);
iq.setDatabaseURL(m_URL);
iq.setUsername(m_User);
iq.setPassword(m_Password);
iq.setQuery(m_query);
result = iq.retrieveInstances();
if (m_DataBaseConnection.getUpperCase()) {
m_idColumn = m_idColumn.toUpperCase();
}
if (result.attribute(0).name().equals(m_idColumn)) {
result.deleteAttributeAt(0);
}
m_structure = new Instances(result, 0);
iq.disconnectFromDatabase();
} catch (Exception ex) {
printException(ex);
StringBuffer text = new StringBuffer();
if (m_query.equals("Select * from Results0")) {
text.append("\n\nDatabaseLoader options:\n");
Enumeration enumi = listOptions();
while (enumi.hasMoreElements()) {
Option option = (Option) enumi.nextElement();
text.append(option.synopsis() + '\n');
text.append(option.description() + '\n');
}
System.out.println(Thread.currentThread().getStackTrace()[1].getClassName() + text);
}
}
return result;
}
开发者ID:williamClanton,项目名称:jbossBA,代码行数:60,代码来源:DatabaseLoader.java
示例8: trainRC
import weka.experiment.InstanceQuery; //导入依赖的package包/类
public void trainRC() throws Exception
{
// ---
// Retrieve the instances in the database
// ---
InstanceQuery query = new InstanceQuery();
query.setDatabaseURL(dbase);
query.setUsername("");
query.setPassword("");
String sql = "SELECT ";
sql += "Data.H2, Data.D2, Data.DX, ";
sql += "Data.CLASS, Data.PARENT_CHAR AS PCLASS, ";
sql += "Data.RELID ";
sql += "FROM Data ";
sql += "WHERE (((Data.SEGERR)=0) AND (Data.PARENT_CHAR<>'0') );";
query.setQuery(sql);
Instances data = query.retrieveInstances();
// ---
// Setting options
// ---
// String[] options = Utils.splitOptions("-L 0.2 -M 0.2 -N 50 -V 0 -S 0 -E 20 -H 5 ");
String[] options = Utils.splitOptions("-cost-matrix \"[0.0 1.0 1.0 0.1 0.1; 1.0 0.0 1.0 0.1 0.1; 1.0 1.0 0.0 0.1 0.1; 10.0 10.0 10.0 0.0 1.0; 10.0 10.0 10.0 1.0 0.0]\" -S 1 -W weka.classifiers.functions.MultilayerPerceptron -- -L 0.2 -M 0.2 -N 500 -V 0 -S 0 -E 20 -H a");
RC.setOptions(options);
data.setClassIndex(data.numAttributes()-1);
// ---
// Train
// ---
System.out.println("Building RC...");
RC.buildClassifier(data);
System.out.println("Done.");
// ---
// Evaluation
// ---
System.out.println("Cross-validation for RC...");
Evaluation eval = new Evaluation(data);
eval.crossValidateModel(RC, data, 10, new Random(1));
System.out.println("Done.");
System.out.println(eval.toSummaryString("\n Results for RC: \n\n", false));
}
开发者ID:tbluche,项目名称:MERStructure,代码行数:46,代码来源:Classifiers.java
示例9: trainYNC
import weka.experiment.InstanceQuery; //导入依赖的package包/类
public void trainYNC() throws Exception
{
// ---
// Retrieve the instances in the database
// ---
InstanceQuery query = new InstanceQuery();
query.setDatabaseURL(dbase);
query.setUsername("");
query.setPassword("");
String sql = "SELECT ";
sql += "YNCdata.PCLASS, YNCdata.CCLASS, YNCdata.RAREA, YNCdata.H, YNCdata.D, YNCdata.V, ";
sql += "YNCdata.YN ";
sql += "FROM YNCdata ";
query.setQuery(sql);
Instances data = query.retrieveInstances();
// ---
// Setting options
// ---
String[] options = Utils.splitOptions("-R -N 3 -Q 1 -M 30");
YNC.setOptions(options);
data.setClassIndex(data.numAttributes()-1);
// ---
// Train
// ---
System.out.println("Building YC...");
YNC.buildClassifier(data);
System.out.println("Done.");
// ---
// Evaluation
// ---
System.out.println("Cross-validation for YNC...");
Evaluation eval = new Evaluation(data);
eval.crossValidateModel(YNC, data, 10, new Random(1));
System.out.println("Done.");
System.out.println(eval.toSummaryString("\n Results for YNC: \n\n", false));
}
开发者ID:tbluche,项目名称:MERStructure,代码行数:43,代码来源:Classifiers.java
注:本文中的weka.experiment.InstanceQuery类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论