今天参照
http://www.netfoucs.com/article/fansy1990/76224.html
和
http://jayatiatblogs.blogspot.hk/2013/05/running-mahouts-logistic-regression.html
两篇博文,开始了hadoop上的逻辑回归实验。
在hadoop上进行机器学习实验,需要用到一个高层的框架名为mahout,意思是驭象人,所以它的功能自然就是让你更好地驾驭hadoop这头小象咯。
mahout的安装略过不说,直接说如何使用mahout。Mahout里面使用逻辑回归(logistic regression)的主要两个类是org.apache.mahout.classifier.sgd.TrainLogistic、org.apache.mahout.classifier.sgd.RunLogistic,一个是建立模型,一个是进行模型评估。在使用时,直接写trainlogistic这种形式就行,系统会自动识别。不过注意不能写成TrainLogistic,不然会无法识别。
使用时的命令如下:
./bin/mahout trainlogistic --input ~/whx/hadoop/logistic_data.csv --output ~/whx/hadoop/logistic.model --target y --categories 2 --predictors
x1.......x1000 --types numeric --features 20 --passes 100 --rate 50
注意其中加粗的部分,一共有1到1000个变量,实在太长了。。。暂时还没找到好的办法缩减,只能全部敲上去了。另外一个需要注意的是,在上面链接中第二篇博客提到的,--types n n这种写法是错误的,会导致无法生成想要的模型,改成--types numeric就行了
最后,若要对已有模型进行测试,则输入
bin/mahout runlogistic --input logistic_test.csv
--model logistic.model --auc --scores --confusion
即可进行测试