扩展/Train|Run|Predict

Train/Run/Predict 都属于 Byzer-lang 里独有的并且可扩展的句式,一般用于机器学习模型的训练和预测,以及特征工程相关的数据处理操作。

想了解更多 内置算法 和 特征工程 算子的应用,可跳转置对应章节。

1. 基础语法

Train

train 顾名思义,就是进行训练,主要是对算法进行训练时使用。下面是一个比较典型的示例:


load json.`/tmp/train` as trainData;

train trainData as RandomForest.`/tmp/rf` where
keepVersion="true"
and fitParam.0.featuresCol="content"
and fitParam.0.labelCol="label"
and fitParam.0.maxDepth="4"
and fitParam.0.checkpointInterval="100"
and fitParam.0.numTrees="4"
;
  • 第一行代码,含义是加载位于 /tmp/train 目录下的,数据格式为 JSON 的数据,并且给该表取名为 trainData
  • 第二行代码,则表示提供 trainData 为数据集,使用算法 RandomForest,将模型保存在 /tmp/rf 下,训练的参数为 fitParam.0.* 参数组里指定的那些。其中 fitParam.0 表示第一组参数,用户可以递增设置 N 组,Byzer-lang 会自动运行多组,最后返回结果列表。例如:
load json.`/tmp/train` as trainData;

train trainData as RandomForest.`/tmp/rf` where
-- 每次模型不要覆盖,保持版本
keepVersion = "true"
and `fitParam.0.labelCol`= "label"  --y标签
and `fitParam.0.featuresCol`= "features"  -- x特征
and `fitParam.0.maxDepth`= "4"

--设置了两组参数同时运行可对比结果优劣
and `fitParam.1.labelCol`= "label"  --y标签
and `fitParam.1.featuresCol`= "features"  -- x特征
and `fitParam.1.maxDepth`= "10";
Run

run 的语义是对数据进行处理,而不是训练。

下面来看一个例子:

run testData as TableRepartition.`` where partitionNum="5" as newdata; 

格式和 train 是一致的,其含义为运行 testData 数据集,使用内置插件 TableRepartition 对其重分区处理, 处理的参数是 partitionNum="5",最后处理后的表叫 newdata

Predict

predict 顾名思义,应该和机器学习相关预测相关。比如上面的 train 示例中,用户将随机森林的模型放在了 /tmp/rf 目录下,用户可以通过 predict 语句加载该模型,并且对表 testData 进行预测。

示例代码如下:

predict testData as RandomForest.`/tmp/rf`;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

想做全栈的胖胖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值