1.准备
win7 64位旗舰版
JDK1.7
weka3.8
mysql-connector-java-5.1.41-bin.jar(这个版本不一定,但是要匹配否则会出问题,自己体会)
2.双击weka-3-8.exe安装weka
3.创建lib
C:\Program Files\Weka-3-8\lib
将mysql-connector-java-5.1.41-bin.jar放入lib文件夹中
4.进入C:\Program Files\Weka-3-8\weka.jar\weka\experiment
你会看到:
…
DatabaseUtils.props
DatabaseUtils.props.hsql
DatabaseUtils.props.mssqlserver2005
DatabaseUtils.props.mssqlserver
DatabaseUtils.props.mysql
DatabaseUtils.props.odbc
DatabaseUtils.props.oracle
DatabaseUtils.props.postgresql
…
weka运行时会使用DatabaseUtils.props
其他的如:’DatabaseUtils.props.数据库名称’(这些是weka提供的针对不同数据库提供的模板)
我们先将DatabaseUtils.props随便改成一个其他的名字,如:DatabaseUtils.props.sample
然后将DatabaseUtils.props.mysql改成DatabaseUtils.props(假设我们需要连接mysql数据库)
打开现在的DatabaseUtils.props可以看到以下部分:
jdbcDriver=org.gjt.mm.mysql.Driver
[修改为–>jdbcDriver=com.mysql.jdbc.Driver]
jdbcURL=jdbc:mysql://server_name:3306/database_name
[这个建议不修改,方便后面进入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
gloat, getFloat() = 7; –> numeric
date, getDate() = 8; –> date
text, getString() = 9; –> string
将上面的内容改成:
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
gloat, getFloat() = 7; –> numeric
date, getDate() = 8; –> date
text, getString() = 9; –> string
TINYINT=3
SMALLINT=4
SHORT=4
SHORT=5
INTEGER=5
INT=5
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=9
DATE=8
TIME=8
DATETIME=8
TIMESTAMP=8
5.设置环境变量
WEKA_HOME:C:\Program Files\Weka-3-8
CLASSPATH:%WEKA_HOME%\lib\mysql-connector-java-5.1.41-bin.jar
6.必杀技(很关键)
C:\Program Files\Weka-3-8\RunWeka.ini文件末尾
cp=%CLASSPATH%;C:/Program Files/Weka-3-8/lib/mysql-connector-java-5.1.41-bin.jar
7.Weka 3.8 (with console).exe运行没问题,Weka 3.8.exe运行不行,将mysql-connector-java-5.1.41-bin.jar版本改成最新版本,问题就解决了。