大家都知道sklearn这玩意,听说过xlearn 吗?
xLearn 是一款高性能的,易用的,并且可扩展的机器学习算法库,你可以用它来解决大规模机器学习问题,尤其是大规模稀疏数据机器学习问题。
官方文档
https://xlearn-doc-cn.readthedocs.io/en/latest/python_api/
在近年来,大规模稀疏数据机器学习算法被广泛应用在各种领域,例如广告点击率预测、推荐系统等。现在 xLearn 将会是你更好的选择,因为 xLearn 几乎囊括了这些系统的全部功能。
安装
https://xlearn-doc-cn.readthedocs.io/en/latest/install/install_windows.html
window 要安装Visual Studio 2017和cmake编译,我赶紧选用ubuntu安装
https://xlearn-doc-cn.readthedocs.io/en/latest/install/index.html
建议通过源码安装
从源码安装 xLearn 分为两个步骤:
首先,我们需要编译 xLearn 得到 xlearn_train 和 xlearn_predict 这两个可执行文件。
从 Github 上 clone 下 xLearn 源代码:
git clone https://github.com/aksnzhy/xlearn.git
cd xlearn
mkdir build
cd build
cmake ../
make
./run_example.sh
之后,你就可以通过 install-python.sh 脚本来安装 xLearn Python 包:
cd python-package
sudo ./install-python.sh
用户可以通过如下命令检测 xLearn Python 库是否安装成功:
cd ../
python run_demo_ctr.py
用户只需要从 Github 上 clone 下 xLearn 源代码:
git clone https://github.com/aksnzhy/xlearn.git
然后通过以下命令进行编译和安装:
cd xlearn
sudo ./build.sh
pip安装
在 Debian/Ubuntu Linux 上, 输入如下命令:
sudo apt-get install gcc binutils
安装 GCC (或者 Clang)
sudo apt-get install clang
在 Debian/Ubuntu Linux 上, 输入以下命令安装 cmake:
sudo apt-get install cmake
在pip安装
pip install xlearn
从iris快速入门
环境
- ubuntu jupyter notebook
import xlearn as xl
ffm_model = xl.create_fm()
# 训练集
ffm_model.setTrain("./small_train.txt")
# 设置验证集
ffm_model.setValidate("./small_test.txt")
# 设置参数
param = {'task':'binary','lr':0.2,'lambda':0.002}
# 模型保存为model.txt
ffm_model.setTXTModel("./model.txt")
# 训练模型
ffm_model.fit(param, "model.out")
# 测试集
ffm_model.setTest("small_test.txt")
# 输出样本预测概率,范围(-1,1)
ffm_model.predict("model.out","output.txt")
# 设置预测概率范围为(0,1)
ffm_model.setSigmoid()
ffm_model.predict("model.out","output2.txt")
ffm_model.setSign()
ffm_model.predict("model.out","output3.txt")