UP 逻辑回归算法数据采用的是 libsvm 格式数据,如下所示:

数据中包含了标签(0 或 1)和特征(不限定维数),libsvm 格式是一种标准且通用的数据格 式,其他格式的数据都可以转换为这种格式。 UP 逻辑回归算法通过这些数据训练模型,经过评估后,采用模型对未含有标签的数据进行分 类,即“贴标签”,最终将该数据及标签输出。 UP 逻辑回归算法作为一个标准机器学习算法,包含通用的 3 个过程:训练、评估和预测。这 些过程由 UP 机器学习模型管理模块进行统一的管理,用户在使用的过程中,只需要注册新的算 法和模型,并设置相应的参数即可使用。详细过程可参考 UP 机器学习模型管理。示例如下:
# 准备数据 call hdfs.hdfs_put('/home/gbase/up_ml_spark2/data/logisticRegression/*','/up/sparkml/data/logisticRegression/'); # 添加算法 call upextdb.add_algorithm('logisticRegression','com.gbase.ml.core.logisticRegression.LRTrain', 'com.gbase.ml.core.logisticRegression.LREvaluate',0,'com.gbase.ml.core.logisticRegression.LRClassify' ); # 创建模型 call upextdb.create_model( 'logisticRegression_model', 'logisticRegression', '/up/sparkml/data/logisticRegression/lr_train.txt','/up/sparkml/data/logisticRegression/lr_test.txt'); # 设置训练和评估参数(没有参数则不用设置) call upextdb.add_train_setting('logisticRegression_model','numClasses','2' ); # 训练过程 call upextdb.train_model('logisticRegression_model'); # 评估过程 call upextdb.evaluate_model('logisticRegression_model'); # 预测 call upextdb.predict('logisticRegression_model', '/up/sparkml/data/logisticRegression/lr_classify.txt', '/up/sparkml/result/logisticRegression/');
最终的输出结果,示例如下:

值得注意的是,UP 逻辑回归算法当前只支持二分类,即 binary logistic regress。因此,上述 的参数:numClasses,如果设置大于 2,则 内部会更改为 2。
由于这些算法是内置在 UP 机器学习库中,因此,在实际使用的时候,并不需要执行添加算 法过程,后续示例将省略这一步骤。




