-
Notifications
You must be signed in to change notification settings - Fork 0
/
PmmlTest.java
27 lines (24 loc) · 5.54 KB
/
PmmlTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
import org.dmg.pmml.FieldName;
import org.jpmml.evaluator.Evaluator;
import org.jpmml.evaluator.EvaluatorUtil;
import org.jpmml.evaluator.LoadingModelEvaluatorBuilder;
import org.xml.sax.SAXException;
import javax.xml.bind.JAXBException;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public static void main(String[] args) throws JAXBException, IOException, SAXException {
JSON.DEFAULT_PARSER_FEATURE &= ~Feature.UseBigDecimal.getMask();
String featureStr = "{\"benefitSent_featureValueList_3\":1748,\"cate3_cart_cnt_his15d\":0,\"benefitSent_featureValueList_2\":1369,\"benefitSent_featureValueList_5\":4095,\"benefitSent_featureValueList_4\":1369,\"coupon_kind\":1,\"jingbean_in\":3207,\"benefitSent_featureValueList_1\":1369,\"benefitSent_featureValueList_0\":1369,\"sku_pv_his3d\":0,\"discount\":10.0,\"cate3_log_cnt_his15d\":2,\"brand_log_cnt_his30d\":3,\"sku_pv_his30d\":8,\"cate1_cart_cnt_his7d\":0,\"cate3_log_cnt_his30d\":3,\"first_ord_to_now\":1795,\"benefitSent_channelIdList_0\":8,\"benefitSent_channelIdList_2\":8,\"quota\":100.0,\"dc_life_cycle_value\":5477,\"search_cate_times\":0,\"benefitSent_channelIdList_1\":8,\"since_last_browse_days\":10,\"dc_rfm_score\":17,\"user_log_acct\":\"18819268972_p\",\"sku_pv_his15d\":6,\"cate3_pref_cnt\":11,\"page_hour_7\":20,\"sku_log_cnt_his1d\":0,\"page_hour_3\":16,\"page_hour_4\":16,\"page_hour_5\":20,\"page_hour_6\":20,\"brand_log_cnt_his3d\":0,\"gmv_his1d\":0,\"page_hour_0\":16,\"page_pageCountList_0\":3,\"page_hour_1\":16,\"page_hour_2\":16,\"dc_life_cycle_value_level\":5,\"benefitSent_datetimeList_9\":1647404237,\"credit_score\":96,\"benefitSent_datetimeList_8\":1647243333,\"benefitSent_datetimeList_7\":1647232138,\"benefitSent_datetimeList_6\":1647168894,\"cate2_pref_cnt\":11,\"jingbean_out\":2240,\"dc_life_cycle_value_30d\":395,\"cate2_cart_cnt_his7d\":0,\"sku_ord_cnt_his90d\":1,\"dc_rfm_type\":-1,\"sku_cart_cnt_his30d\":0,\"sku_cart_cnt_his7d\":0,\"since_first_add_days\":9999,\"cate2_cart_cnt_his15d\":0,\"cate1_cart_cnt_his30d\":0,\"brand_cart_cnt_his7d\":0,\"pref_promotion_level\":2,\"focus_cate_times\":0,\"cate1_log_cnt_his15d\":2,\"hx_age\":2,\"last_cart_to_now_his30d\":9999,\"sku_log_cnt_his3d\":0,\"cate1_log_cnt_his30d\":3,\"gmv_his90d\":53,\"benefitSent_datetimeList_1\":1647052395,\"benefitSent_datetimeList_0\":1646998165,\"benefitSent_datetimeList_5\":1647164788,\"benefitSent_featureValueList_7\":1369,\"sku_cart_cnt_his15d\":0,\"benefitSent_datetimeList_4\":1647152506,\"benefitSent_featureValueList_6\":1748,\"brand_log_cnt_his1d\":0,\"benefitSent_datetimeList_3\":164714191,\"benefitSent_featureValueList_9\":1369,\"since_first_search_days\":9999,\"benefitSent_datetimeList_2\":1647082277,\"benefitSent_featureValueList_8\":723,\"hx_gender\":0,\"last_log_to_now_his30d\":10,\"since_last_search_days\":9999,\"since_last_add_days\":9999,\"cate3_log_cnt_his7d\":0,\"sku_pv_his7d\":0,\"since_first_ord_days\":53,\"page_pageIdList_7\":1,\"page_pageIdList_4\":2,\"page_pageIdList_3\":2,\"page_pageIdList_6\":1,\"page_pageIdList_5\":1,\"page_pageIdList_0\":7,\"page_pageIdList_2\":7,\"page_pageIdList_1\":2,\"brand_cart_cnt_his30d\":0,\"since_first_browse_days\":10,\"since_first_consult_days\":9999,\"valid_sale_amt\":31970,\"jdmem_score\":5514,\"cate2_cart_cnt_his30d\":0,\"dc_life_cycle_value_90d\":1141,\"cate1_cart_cnt_his15d\":0,\"brand_log_cnt_his7d\":0,\"gmv_his60d\":53,\"consult_cate_times\":0,\"sku_log_cnt_his30d\":3,\"last_ord_to_now\":53,\"coupon_type\":3,\"pref_gmv_his90d\":7,\"browse_cate_times\":6,\"page_pageCountList_7\":1,\"page_pageCountList_5\":4,\"page_pageCountList_6\":1,\"page_pageCountList_3\":1,\"page_pageCountList_4\":1,\"page_pageCountList_1\":1,\"brand_ord_cnt_his90d\":1,\"page_pageCountList_2\":6,\"sku_cart_cnt_his3d\":0,\"sku_pv_his1d\":0,\"coupon_style\":6,\"sku_log_cnt_his15d\":2,\"page_minute_7\":28,\"page_minute_6\":30,\"page_minute_5\":33,\"page_minute_4\":38,\"page_minute_3\":39,\"page_minute_2\":39,\"page_minute_1\":40,\"page_minute_0\":40,\"cate2_log_cnt_his30d\":3,\"since_last_ord_days\":1795,\"risk_score\":-10,\"brand_log_cnt_his15d\":2,\"brand_cart_cnt_his15d\":0,\"cate3_cart_cnt_his30d\":0,\"benefitSent_channelIdList_4\":8,\"add_cate_times\":0,\"benefitSent_channelIdList_3\":8,\"benefitSent_channelIdList_6\":8,\"parent_ord_cnt_his90d\":1,\"benefitSent_channelIdList_5\":1,\"sku_log_cnt_his7d\":0,\"benefitSent_channelIdList_8\":7,\"valid_par_ord_num\":47,\"benefitSent_channelIdList_7\":8,\"pref_comment_level\":5,\"cate1_pref_cnt\":10,\"benefitSent_featureTypeList_0\":1,\"benefitSent_channelIdList_9\":8,\"benefitSent_featureTypeList_1\":1,\"benefitSent_featureTypeList_2\":1,\"benefitSent_featureTypeList_3\":6,\"benefitSent_featureTypeList_4\":1,\"benefitSent_featureTypeList_5\":1,\"benefitSent_featureTypeList_6\":6,\"benefitSent_featureTypeList_7\":1,\"since_last_consult_days\":9999,\"benefitSent_featureTypeList_8\":1,\"benefitSent_featureTypeList_9\":1,\"last_ord_to_now_his90d\":53,\"cate2_log_cnt_his15d\":2,\"pref_gmv_his60d\":7,\"cate3_cart_cnt_his7d\":0}";
HashMap<String, Object> featureMap = JSON.parseObject(featureStr, new TypeReference<HashMap<String, Object>>() {});
String pmmlPath = "model_jy.pmml";
Evaluator evaluator = new LoadingModelEvaluatorBuilder().load(new File(pmmlPath)).build();
evaluator.verify();
Map<FieldName, ?> fieldNameMap = EvaluatorUtil.encodeKeys(featureMap);
Map<FieldName, ?> evaluateResult = evaluator.evaluate(fieldNameMap);
System.out.println(evaluateResult)
}