一、下载并解压数据库驱动
下载地址:http://www.mysql.com/products/connector/,本文下载 mysql-connector-java-5.0.8.zip。将解压后的mysql-connector-java-5.0.8-bin.jar复制到D:Program FilesWeka-3-6lib中(lib为自己新建文件夹)。
二、设置环境变量
WEKA_HOME:D:Program FilesWeka-3-6
CLASSPATH:%WEKA_HOME%libmysql-connector-java-5.0.8-bin.jar
三、修改weka.jar
1、解压weka.jar到一个目录(这里为package)
2、在D:Program FilesWeka-3-6packagewekaexperiment中找到DatabaseUtils.props.mysql,将其名字改成DatabaseUtils.props,替换原有的DatabaseUtils.props文件,并将其修改文件里的对应内容如下:
# JDBC driver (comma-separated list)
jdbcDriver=com.mysql.jdbc.Driver
# database URL
jdbcURL=jdbc:mysql://localhost:3306/db_predict(db_predict为数据库名)
# specific data types,去掉注释,改为weka支持的数据格式
string, getString() = 0; --> nominal
boolean, getBoolean() = 1; --> nominal
double, getDouble() = 2; --> numeric
byte, getByte() = 3; --> numeric
short, getByte()= 4; --> numeric
int, getInteger() = 5; --> numeric
long, getLong() = 6; --> numeric
float, getFloat() = 7; --> numeric
date, getDate() = 8; --> date
text, getString() = 9; --> string
time, getTime() = 10; --> date
BigDecimal,getBigDecimal()=11; -->nominal
#mysql-conversion --类型转换,做如下补充
TINYINT=3
SMALLINT=4
SHORT=5
INTEGER=5
INT=5
INT_UNSIGNED=6
BIGINT=6
LONG=6
REAL=7
NUMERIC=2
DECIMAL=2
FLOAT=2
DOUBLE=2
CHAR=0
TEXT=0
VARCHAR=0
LONGVARCHAR=9
BINARY=0
VARBINARY=0
LONGVARBINARY=9
BIT=1
BLOB=8
DATE=8
TIME=8
DATETIME=8
TIMESTAMP=8
3、重新打包。命令行进入D:Program FilesWeka-3-6package,执行命令:jar cvf weka.jar java_cup META-INF weka,替换原来的weka.jar。
四、运行weka
单击explorer>>单击open DB>>单击User>>输入用户名,密码>>单击Connect
下图代表成功
官网地址:http://weka.wikispaces.com/Databases