Module sktmls.models.contrib.lightgbm_device_model

Classes

class LightGBMDeviceModel (model, model_name: str, model_version: str, model_features: List[str], default_model_feature_values: List[Any], label_indices: Dict[str, int], product_classes: Dict[str, Any], products: Dict[str, Any], device_meta: MetaTable, conversion_formulas: Dict[str, Dict[str, Any]] = {}, emb_features: List[str] = [], default_emb_feature_values: List[List[Any]] = [], emb_feature_indices: Dict[str, List[int]] = [], default_context_value: str = 'context_default', num_pick: int = 3, high_rank_word: List[str] = ['Plus', '플러스', '울트라', 'Ultra', 'Max', '맥스', 'Pro', '프로'])

MLS 모델 레지스트리에 등록되는 LightGBM 기반 클래스입니다.

주어진 features리스트를 이용해 prediction 후 스코어 상위 3개 단말그룹으로 필터링 합니다. 이후 id, name, score, props, type을 반환하는 모델입니다.

Args

  • model: LightGBM으로 학습한 모델 객체
  • model_name: (str) 모델 이름
  • model_version: (str) 모델 버전
  • model_features: (list(str)) non-embedding 피쳐 리스트(필수피쳐: "eqp_mdl_cd", "age")
  • default_model_feature_values: (list) 피쳐 기본값 리스트
  • label_indices: (dict) 라벨 인덱스 값
  • product_classes: (dict) 상품 클래스 값
  • products: (dict) 컨텍스트 값
  • device_meta: (MetaTable) 단말코드그룹 값
  • conversion_formulas: (optional) (dict(dict)) Feature conversion에 사용할 조건 dict. 형식은 아래 Example 참조 (기본값: {})
  • emb_features: (optional) (list(str)) 임베딩 피쳐 이름 리스트 (기본값: [])
  • default_emb_feature_values: (optional) (list(list)) 임베딩 피쳐들의 기본값 리스트 (리스트의 리스트 형식) (기본값: [])
  • emb_feature_indices: (optional) (list(list)) 각 임베딩 피쳐의 세부 사용 피쳐 인덱스 리스트 (기본값: [])
  • default_context_value: (optional) (str) 기본 컨텍스트 값 (기본값: "context_default")
  • num_pick: (optional) (int) 스코어 상위 N개 추출
  • high_rank_word: (optional) (list(str)) 플래그쉽 모델 명칭 (기본값 : ["Plus", "플러스", "울트라", "Ultra", "Max", "맥스", "Pro", "프로"])

Example

model_features = ["feature1", "feature2", "feature3"]
default_model_feature_values = [
    dimension_client.get_dimension(dimension_type="user", name=feature).default for feature in model_features
]

label_indices = {
    "삼성전자_120만원": 0,
    "삼성전자_160만원": 1,
    "삼성전자_60만원": 2,
    "Apple_120만원": 3,
    "Apple_160만원": 4,
    "Apple_60만원": 5,
    "LG전자_120만원": 6,
    "LG전자_160만원": 7,
    "LG전자_60만원": 8,
    "기타_120만원": 9,
    "기타_160만원": 10,
    "기타_60만원": 11,
}

product_classes = {
    "Apple_120만원": [
        {
            "product_grp_id": "000004352",
            "product_grp_nm": "iPhone SE (2020)",
            "mfact_nm": "Apple",
            "eqp_mdl_cd": "A23F",
            "rep_eqp_mdl_cd": "A23F",
            "rep_eqp_yn": "Y",
            "color_hex": "1F2120",
            "color_nm": "블랙",
            "network_type": "4G",
            "device_weight": 0.02356698,
        },
        {
            "product_grp_id": "000003972",
            "product_grp_nm": "iPhone 11",
            "mfact_nm": "Apple",
            "eqp_mdl_cd": "A1G6",
            "rep_eqp_mdl_cd": "A1G6",
            "rep_eqp_yn": "Y",
            "color_hex": "1F2120",
            "color_nm": "블랙",
            "network_type": "4G",
            "device_weight": 0.01638297,
        },
    ],
    "Apple_160만원": [
        {
            "product_grp_id": "000003973",
            "product_grp_nm": "iPhone 11 Pro",
            "mfact_nm": "Apple",
            "eqp_mdl_cd": "A1GR",
            "rep_eqp_mdl_cd": "A1GR",
            "rep_eqp_yn": "Y",
            "color_hex": "52514F",
            "color_nm": "스페이스 그레이",
            "network_type": "4G",
            "device_weight": 0.00767129,
        }
    ],
}

products = {
    "000000332": {
        "name": "iPhone 6",
        "type": "device",
        "context_features": ["context_default"],
        "random_context": False,
    },
    "000000952": {
        "name": "iPhone 6s",
        "type": "device",
        "context_features": ["context_default"],
        "random_context": False,
    },
    "000001153": {
        "name": "갤럭시 S7 엣지",
        "type": "device",
        "context_features": ["context_popular_apple_device"],
        "random_context": False,
    },
    "000001572": {
        "name": "BlackBerry PRIV",
        "type": "device",
        "context_features": ["context_default"],
        "random_context": False,
    },
    "000001613": {"name": "준3", "type": "device", "context_features": ["context_default"], "random_context": False},
    "000001672": {
        "name": "iPhone 7",
        "type": "device",
        "context_features": ["context_popular_apple_device"],
        "random_context": False,
    },
}

device_meta = metatable_client.get_meta_table(name="eqp_mdl_cd_meta")

conversion_formulas = {
    "additional_svc_allcare_scrb_type": {"map": {"free": 1, "paid": 2, "N/A": 0}, "default": 0},
    "additional_svc_ansim_option_scrb_type": {"map": {"free": 1, "paid": 2, "N/A": 0}, "default": 0},
    "additional_svc_flo_scrb_type": {"map": {"free": 1, "paid": 2, "N/A": 0}, "default": 0},
    "additional_svc_melon_scrb_type": {"map": {"free": 1, "paid": 2, "N/A": 0}, "default": 0},
    "additional_svc_oksusu_scrb_type": {"map": {"free": 1, "paid": 2, "N/A": 0}, "default": 0},
    "additional_svc_pooq_scrb_type": {"map": {"free": 1, "paid": 2, "N/A": 0}, "default": 0},
    "age_band": {"map": {"kids": 1, "ting": 2, "young": 3, "tplan": 4, "senior": 5}, "default": 4},
    "channel": {"map": {"T월드": 1, "고객센터": 2, "오프라인": 3}, "default": 0},
    "family_comb_type": {"map": {"wire": 1, "wless": 2}, "default": 0},
    "main_channel_eqp_buy": {"map": {"D": 1, "S": 2}, "default": 0},
    "mbr_card_gr_cd": {"map": {"S": 1, "G": 2, "V": 3}, "default": 0},
    "mng_nice_cb_grd": {
        "map": {"01": 1, "02": 2, "03": 3, "04": 4, "05": 5, "06": 6, "07": 7, "08": 8, "09": 9, "10": 10},
        "default": -1,
    },
    "prefer_device_price": {"map": {"M": 1, "H": 2}, "default": 0},
    "prefer_latest_device": {"map": {"M": 1, "H": 2, "R": 3}, "default": 0},
    "prefer_device_manufacturer": {"map": {"lg": 1, "apple": 2, "samsung": 3}, "default": 0},
    "tmap_freq_dest_residence": {"map": {"apart": 1, "complex_redisence": 2, "villa": 3, "officetel": 4}, "default": 0},
}

my_model_v1 = LightGBMDeviceModel(
    model=lightgbm_model,
    model_name="my_model",
    model_version="v1",
    model_features=["eqp_mdl_cd", "age"] + model_features,
    default_model_feature_values=default_model_feature_values,
    label_indices=label_indices,
    product_classes=product_classes,
    products=products,
    device_meta=device_meta,
    conversion_formulas=conversion_formulas,
    emb_features=["embedding_vector"],
    default_emb_feature_values=[[0.0] * 64],
    emb_feature_indices=[[0, 1]],
)

result = my_model_v1.predict(["eqp_mdl_cd", "value_1", "value_2", "value_3", [[0.1, 0.2]]])

Ancestors

Methods

def predict(self, x: List[Any], **kwargs) ‑> Dict[str, Any]

Inherited members