Module sktmls.models
Sub-modules
sktmls.models.automl
sktmls.models.contrib
sktmls.models.ml_model
sktmls.models.mls_model
sktmls.models.mls_trainable
Classes
class AutoMLModel (**kwargs)
-
AutoML모델 클래스 입니다.
Args
- kwargs
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- dataset_id: (int) ML 데이터셋 고유 ID
- dataset_name: (str) ML 데이터셋 이름
- automl_model_info: (dict) AutoML모델 정보
Returns
Ancestors
Methods
def get_error(self)
-
모델 학습 시 에러 발생 원인을 조회한다. (모델 학습 실패 시에만 값 존재)
Returns
str
- kwargs
class MLModel (**kwargs)
-
ML모델 클래스 입니다.
Args
- kwargs
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- version: (str) ML모델 버전
- creator: (str) ML모델 생성 계정명
- description: (str) ML모델 설명
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - table: (str) ML모델 테이블
- model_data: (str) ML모델 데이터
- status: (
MLModelStatus
) ML모델 상태 - created_at: (datetime) 생성일시
- updated_at: (datetime) 수정일시
Returns
Subclasses
Methods
def get(self) ‑> dict
def reset(self, **kwargs)
- kwargs
class MLModelClient (env: MLSENV = None, runtime_env: MLSRuntimeENV = None, username: str = None, password: str = None)
-
Args
- env: (
MLSENV
) 접근할 MLS 환경 (MLSENV.DEV
|MLSENV.STG
|MLSENV.PRD
) (기본값:MLSENV.STG
) - runtime_env: (
MLSRuntimeENV
) 클라이언트가 실행되는 환경 (MLSRuntimeENV.YE
|MLSRuntimeENV.EDD
|MLSRuntimeENV.LOCAL
) (기본값:MLSRuntimeENV.LOCAL
) - username: (str) MLS 계정명 (기본값: $MLS_USERNAME)
- password: (str) MLS 계정 비밀번호 (기본값: $MLS_PASSWORD)
아래의 환경 변수가 정의된 경우 해당 파라미터를 생략 가능합니다.
- $MLS_ENV: env
- $MLS_RUNTIME_ENV: runtime_env
- $MLS_USERNAME: username
- $MLS_PASSWORD: password
Returns
Example
ml_model_client = MLModelClient(env=MLSENV.STG, runtime_env=MLSRuntimeENV.YE, username="mls_account", password="mls_password")
Ancestors
Methods
def create_automl_model(self, dataset: Dataset, name: str, version: str, description: str) ‑> AutoMLModel
-
AutoML 모델을 생성합니다.
Args
- dataset: (sktmls.datasets.Dataset) ML 데이터셋
- name: (str) 생성할 AutoML 모델 이름
- version: (str) 생성할 AutoML 모델 버전
- description: (str) 생성할 AutoML 설명
Returns
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- creator: (str) ML모델 생성 계정명
- description: (str) ML모델 설명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- dataset_id: (int) ML 데이터셋 고유 ID
- dataset_name: (str) ML 데이터셋 이름
- automl_model_info: (dict) AutoML모델 정보
Example
automl_model = ml_model_client.create_automl_model( dataset=dataset, name="automl_test_model", version="v1", description="test_model" )
def create_manual_model(self, name: str, version: str, description: str = None, creator: str = None, model_lib: str = None, model_data: str = None, model_meta: dict = None, features: str = None, table: str = None, components: List[Component] = None) ‑> ManualModel
-
일반 모델을 생성합니다. 모델을 버킷에 연결 가능하도록 deploy하는 작업입니다.
일반 모델은 deploy 후 버킷에 연결되어 정상 동작하기 까지 약 한 시간이 소요됩니다.
Args
- name: (str) 생성할 일반 모델 이름
- version: (str) 생성할 일반 모델 버전
- description: (optional) (str) 생성할 일반 모델 설명
- creator: (optional) (str) 일반 모델 생성 계정명
- model_lib: (optional) (str) 일반 모델 라이브러리
- model_data: (optional) (str) 일반 모델 데이터
- model_meta: (optional) (dict) 모델 레지스트리에 등록된 메타정보(model.json)
- features: (optional) (str) 일반 모델에 사용된 피쳐
- table: (optional) (str) 일반 모델 테이블
- components: (optional) list(
Component
) 일반 모델 컴포넌트 리스트
Returns
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- components: list(
Component
) ML모델 컴포넌트 - table: (str) ML모델 테이블
- model_lib: (str) ML모델 라이브러리
- model_data: (str) ML모델 데이터
- features: (str) ML모델에 사용된 피쳐
- is_enabled: (bool) 활성상태 여부
Example
component_1 = component_client.get_component(name="test_component_1") component_2 = component_client.get_component(name="test_component_2") manual_model = ml_model_client.create_manual_model( name="manual_test_model", version="v1", description="test_model", creator="mls_user", model_lib="lightgbm", model_data="/models/manual_test_model/v1/model.joblib", model_meta={ "name": "manual_test_model", "version": "v1", "model_lib": "lightgbm", "model_lib_version": "2.3.1", "model_data": "/models/manual_test_model/v1/model.joblib", "features": ["age", "app_use_traffic_youtube", "svc_scrb_period"], }, features="age,app_use_traffic_youtube,svc_scrb_period", table="test_model_table", components=[component_1, component_2] )
def create_model_deployment(self, name: str, version: str, description: str = None, creator: str = None, model_lib: str = None, model_data: str = None, model_meta: dict = None, features: str = None, table: str = None, components: List[Component] = None) ‑> ManualModel
-
일반 모델을 배포(배포 객체를 생성)합니다.
위 메소드는 create_manual_model과 같은 기능을 수행합니다.
모델을 버킷에 연결 가능하도록 deploy하는 작업입니다. 일반 모델은 deploy 후 버킷에 연결되어 정상 동작하기 까지 약 한 시간이 소요됩니다.
Args
- name: (str) 생성할 일반 모델 이름
- version: (str) 생성할 일반 모델 버전
- description: (optional) (str) 생성할 일반 모델 설명
- creator: (optional) (str) 일반 모델 생성 계정명
- model_lib: (optional) (str) 일반 모델 라이브러리
- model_data: (optional) (str) 일반 모델 데이터
- model_meta: (optional) (dict) 모델 레지스트리에 등록된 메타정보(model.json)
- features: (optional) (str) 일반 모델에 사용된 피쳐
- table: (optional) (str) 일반 모델 테이블
- components: (optional) list(
Component
) 일반 모델 컴포넌트 리스트
Returns
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- components: list(
Component
) ML모델 컴포넌트 - table: (str) ML모델 테이블
- model_lib: (str) ML모델 라이브러리
- model_data: (str) ML모델 데이터
- features: (str) ML모델에 사용된 피쳐
- is_enabled: (bool) 활성상태 여부
Example
component_1 = component_client.get_component(name="test_component_1") component_2 = component_client.get_component(name="test_component_2") model_deployment = ml_model_client.create_model_deployment( name="manual_test_model", version="v1", description="test_model", creator="mls_user", model_lib="lightgbm", model_data="/models/manual_test_model/v1/model.joblib", model_meta={ "name": "manual_test_model", "version": "v1", "model_lib": "lightgbm", "model_lib_version": "2.3.1", "model_data": "/models/manual_test_model/v1/model.joblib", "features": ["age", "app_use_traffic_youtube", "svc_scrb_period"], }, features="age,app_use_traffic_youtube,svc_scrb_period", table="test_model_table", components=[component_1, component_2] )
def delete_model(self, model: Union[AutoMLModel, ManualModel], delete_table: bool = False) ‑> MLSResponse
-
모델 삭제합니다.
Args
- model: (
AutoMLModel
orManualModel
) AutoML 혹은 일반 모델 객체 - delete_table: (optional) (bool) manual_model의 경우 모델의 연결된 dynamodb table을 함께 지우는 옵션. (기본값:
False
)
Returns
Example
ml_model_client.delete_model(model=model, delete_table=True)
- model: (
def delete_model_deployment(self, model_deployment: ManualModel, delete_table: bool = False) ‑> MLSResponse
-
모델 배포를 삭제합니다. 위 메소드는 delete_model과 같은 기능을 수행합니다.
Args
- model_deployment: (
ManualModel
) 일반 모델 객체 - delete_table: (optional) (bool) manual_model의 경우 모델의 연결된 dynamodb table을 함께 지우는 옵션. (기본값:
False
)
Returns
Example
ml_model_client.delete_model_deployment(model_deployment=model_deployment, delete_table=True)
- model_deployment: (
def get_automl_model(self, id: int = None, name: str = None, version: str = None) ‑> AutoMLModel
-
AutoML모델 정보를 가져옵니다.
Args:
id
또는 (name
andversion
) 중 한 개 이상의 값이 반드시 전달되어야 합니다.- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- version: (str) ML모델 이름
Returns
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- dataset_id: (int) ML 데이터셋 고유 ID
- dataset_name: (str) ML 데이터셋 이름
- automl_model_info: (dict) AutoML모델 정보
Example
automl_model_by_id = ml_model_client.get_automl_model(id=3) automl_model_by_name_and_version = ml_model_client.get_automl_model(name="my_automl_model", version="my_automl_version")
def get_automl_model_server_handler(self, model: AutoMLModel) ‑> str
-
AutoML모델 서버의 예측 결과 로직을 조회합니다.
Args
- model: (
AutoMLModel
) AutoML 객체
Returns
str
Example
```python ml_model_client.get_automl_model_server_handler(model=model)
- model: (
def get_automl_model_server_status(self, model: AutoMLModel) ‑> str
-
AutoML모델 서버 상태를 확인합니다.
Args
- model: (
AutoMLModel
) AutoML 객체
Returns
str (
RUNNING
|STOPPED
|FAILED
|UNKNOWN
)Example
ml_model_client.get_automl_model_server_status(model=model)
- model: (
def get_manual_model(self, id: int = None, name: str = None, version: str = None) ‑> ManualModel
-
일반 모델 정보를 가져옵니다.
Args:
id
또는 (name
andversion
) 중 한 개 이상의 값이 반드시 전달되어야 합니다.- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- version: (str) ML모델 이름
Returns
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- components: list(
Component
) ML모델 컴포넌트 - table: (str) ML모델 테이블
- model_lib: (str) ML모델 라이브러리
- model_data: (str) ML모델 데이터
- features: (str) ML모델에 사용된 피쳐
- is_enabled: (bool) 활성상태 여부
Example
manual_model_by_id = ml_model_client.get_manual_model(id=3) manual_model_by_name_and_version = ml_model_client.get_manual_model(name="my_manual_model", version="my_manual_version")
def get_model_deployment(self, id: int = None, name: str = None, version: str = None) ‑> ManualModel
-
일반 모델 배포를 가져옵니다. 위 메소드는 get_manual_model과 같은 기능을 수행합니다.
Args:
id
또는 (name
andversion
) 중 한 개 이상의 값이 반드시 전달되어야 합니다.- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- version: (str) ML모델 이름
Returns
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- components: list(
Component
) ML모델 컴포넌트 - table: (str) ML모델 테이블
- model_lib: (str) ML모델 라이브러리
- model_data: (str) ML모델 데이터
- features: (str) ML모델에 사용된 피쳐
- is_enabled: (bool) 활성상태 여부
Example
model_deployment_by_id = ml_model_client.get_model_deployment(id=3) model_deployment_by_name_and_version = ml_model_client.get_model_deployment(name="my_manual_model", version="my_manual_version")
def is_batch_prediction_ready(self, manual_model: ManualModel) ‑> bool
-
일반 모델에 등록된 배치추론 테이블이 존재하는지와 업로드가 끝났는지 체크합니다.
Args
- model: (
ManualModel
) 일반 모델 객체
Returns
bool
Example
my_model = ml_model_client.get_manual_model(name="manual_test_model", version="v1") ml_model_client.is_batch_prediction_ready(manual_model=my_model)
- model: (
def is_online_prediction_ready(self, manual_model: ManualModel) ‑> bool
-
일반 모델에 등록된 아티팩트(model.jobilb)이 존재하는지 확인합니다.
Args
- model: (
ManualModel
) 일반 모델 객체
Returns
bool
Example
my_model = ml_model_client.get_manual_model(name="manual_test_model", version="v1") ml_model_client.is_online_prediction_ready(manual_model=my_model)
- model: (
def list_automl_models(self, **kwargs) ‑> List[AutoMLModel]
-
AutoML모델 리스트를 가져옵니다.
Args
- kwargs: (optional) (dict) 쿼리 조건
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- version: (str) ML모델 이름
- query: (str) 검색 문자
- page: (int) 페이지 번호
Returns
list(
AutoMLModel
)- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- creator: (str) ML모델 생성 계정명
- description: (str) ML모델 설명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- dataset_id: (int) ML 데이터셋 고유 ID
- dataset_name: (str) ML 데이터셋 이름
- automl_model_info: (dict) AutoML모델 정보
Example
automl_models = ml_model_client.list_automl_models()
- kwargs: (optional) (dict) 쿼리 조건
def list_manual_models(self, **kwargs) ‑> List[ManualModel]
-
일반 모델 리스트를 가져옵니다.
Args
- kwargs: (optional) (dict) 쿼리 조건
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- version: (str) ML모델 이름
- query: (str) 검색 문자
- page: (int) 페이지 번호
Returns
list(
ManualModel
)- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- components: list(
Component
) ML모델 컴포넌트 - table: (str) ML모델 테이블
- model_lib: (str) ML모델 라이브러리
- model_data: (str) ML모델 데이터
- features: (str) ML모델에 사용된 피쳐
- is_enabled: (bool) 활성상태 여부
Example
manual_models = ml_model_client.list_manual_models()
- kwargs: (optional) (dict) 쿼리 조건
def list_model_deployments(self, **kwargs) ‑> List[ManualModel]
-
일반 모델 배포들을 가져옵니다. 위 메소드는 list_manual_models와 같은 기능을 수행합니다.
Args
- kwargs: (optional) (dict) 쿼리 조건
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- version: (str) ML모델 이름
- query: (str) 검색 문자
- page: (int) 페이지 번호
Returns
list(
ManualModel
)- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- components: list(
Component
) ML모델 컴포넌트 - table: (str) ML모델 테이블
- model_lib: (str) ML모델 라이브러리
- model_data: (str) ML모델 데이터
- features: (str) ML모델에 사용된 피쳐
- is_enabled: (bool) 활성상태 여부
Example
manual_models = ml_model_client.list_model_deployments()
- kwargs: (optional) (dict) 쿼리 조건
def start_automl_model_server(self, model: AutoMLModel) ‑> MLSResponse
-
AutoML모델 서버를 시작합니다.
Args
- model: (
AutoMLModel
) AutoML 객체
Returns
Example
ml_model_client.start_automl_model_server(model=model)
- model: (
def stop_automl_model_server(self, model: AutoMLModel) ‑> MLSResponse
-
AutoML모델 서버를 중단합니다.
Args
- model: (
AutoMLModel
) AutoML 객체
Returns
Example
ml_model_client.stop_automl_model_server(model=model)
- model: (
def update_automl_model_server_handler(self, model: AutoMLModel, handler: str) ‑> MLSResponse
-
AutoML모델 서버의 예측 결과 로직(Handler)을 수정합니다.
Args
- model: (
AutoMLModel
) AutoML 객체 - handler: (str) 예측 결과 로직 코드
Returns
Example
handler_path = "handler.py" with open(handler_path) as f: handler = f.read() ml_model_client.update_automl_model_server_handler(model=model, handler=handler)
- model: (
def update_manual_model(self, manual_model: ManualModel, name: str = None, version: str = None, description: str = None, creator: str = None, model_lib: str = None, model_data: str = None, model_meta: dict = None, features: str = None, table: str = None, components: List[Component] = None) ‑> ManualModel
-
일반 모델 정보를 수정합니다.
Args
- model: (
ManualModel
) 일반 모델 객체 - name: (str) (optional) 수정할 일반 모델 이름
- version: (str) (optional) 수정할 일반 모델 버전
- description: (optional) (str) 수정할 일반 모델 설명
- creator: (optional) (str) 수정할 일반 모델 계정명
- model_lib: (optional) (str) 수정할 일반 모델 라이브러리
- model_data: (optional) (str) 수정할 일반 모델 데이터
- model_meta: (optional) (dict) 수정할 모델 레지스트리에 등록된 메타정보(model.json)
- features: (optional) (str) 수정할 일반 모델에 사용된 피쳐
- table: (optional) (str) 수정할 일반 모델 테이블
- components: (optional) list(
Component
) 수정할 일반 모델 컴포넌트 리스트
Returns
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- components: list(
Component
) ML모델 컴포넌트 - table: (str) ML모델 테이블
- model_lib: (str) ML모델 라이브러리
- model_data: (str) ML모델 데이터
- features: (str) ML모델에 사용된 피쳐
- is_enabled: (bool) 활성상태 여부
Example
manual_model = ml_model_client.get_manual_model(name="my_manual_model", version="v1") manual_model = ml_model_client.update_manual_model( manual_model=manual_model, name="my_new_manual_model", description="updated manual model", model_data="/models/my_new_manual_model/v1/model.joblib", )
- model: (
def update_manual_model_components(self, manual_model: ManualModel, components: List[Component]) ‑> ManualModel
-
일반 모델의 컴포넌트 정보를 수정합니다.
Args
- model: (
ManualModel
) 일반 모델 객체 - components: list(
Component
) 수정할 컴포넌트 리스트
Returns
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- components: list(
Component
) ML모델 컴포넌트 - table: (str) ML모델 테이블
- model_lib: (str) ML모델 라이브러리
- model_data: (str) ML모델 데이터
- features: (str) ML모델에 사용된 피쳐
- is_enabled: (bool) 활성상태 여부
Example
component = component_client.get_component(name="test_component") manual_model = ml_model_client.get_manual_model(name="manual_test_model", version="v1") updated_manual_model = ml_model_client.update_manual_model_components( manual_model=manual_model, components=[component], ) no_component_manual_model = ml_model_client.update_manual_model_components( manual_model=manual_model, components=[], )
- model: (
def update_manual_model_meta(self, manual_model: ManualModel, model_meta: dict, partial_update: bool = False) ‑> ManualModel
-
일반 모델의 모델 메타 정보를 수정합니다.
Args
- model: (
ManualModel
) 일반 모델 객체 - model_meta: (dict) 수정할 모델 메타 정보
- partial_update: (optional) (dict) 기존 모델 메타에 덮어씌울지(True) 기존 모델 메타를 교체할지(False) 여부 (기본값:
False
)
Returns
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- components: list(
Component
) ML모델 컴포넌트 - table: (str) ML모델 테이블
- model_lib: (str) ML모델 라이브러리
- model_data: (str) ML모델 데이터
- features: (str) ML모델에 사용된 피쳐
- is_enabled: (bool) 활성상태 여부
Example
manual_model = ml_model_client.get_manual_model(name="my_manual_model", version="v1") manual_model = ml_model_client.update_manual_model_meta( manual_model=manual_model, model_meta={ "model_lib": "xgboost", "model_lib_version": "1.2.0", }, partial_update = True ) manual_model_without_meta = ml_model_client.update_manual_model_meta( manual_model=manual_model, model_meta={} )
- model: (
def update_model_deployment(self, model_deployment: ManualModel, name: str = None, version: str = None, description: str = None, creator: str = None, model_lib: str = None, model_data: str = None, model_meta: dict = None, features: str = None, table: str = None, components: List[Component] = None) ‑> ManualModel
-
일반 모델 배포를 수정합니다. 위 메소드는 update_manual_model과 같은 기능을 수행합니다.
Args
- model_deployment: (
ManualModel
) 일반 모델 객체 - name: (str) (optional) 수정할 일반 모델 이름
- version: (str) (optional) 수정할 일반 모델 버전
- description: (optional) (str) 수정할 일반 모델 설명
- creator: (optional) (str) 수정할 일반 모델 계정명
- model_lib: (optional) (str) 수정할 일반 모델 라이브러리
- model_data: (optional) (str) 수정할 일반 모델 데이터
- model_meta: (optional) (dict) 수정할 모델 레지스트리에 등록된 메타정보(model.json)
- features: (optional) (str) 수정할 일반 모델에 사용된 피쳐
- table: (optional) (str) 수정할 일반 모델 테이블
- components: (optional) list(
Component
) 수정할 일반 모델 컴포넌트 리스트
Returns
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- components: list(
Component
) ML모델 컴포넌트 - table: (str) ML모델 테이블
- model_lib: (str) ML모델 라이브러리
- model_data: (str) ML모델 데이터
- features: (str) ML모델에 사용된 피쳐
- is_enabled: (bool) 활성상태 여부
Example
model_deployment = ml_model_client.get_model_deployment(name="my_manual_model", version="v1") model_deployment = ml_model_client.update_model_deployment( model_deployment=model_deployment, name="my_new_manual_model_deployment", description="updated manual model deployment", model_data="/models/my_new_manual_model/v1/model.joblib", )
- model_deployment: (
def update_model_deployment_components(self, model_deployment: ManualModel, components: List[Component]) ‑> ManualModel
-
일반 모델 배포의 컴포넌트 정보를 수정합니다. 위 메소드는 update_manual_model_components와 같은 기능을 수행합니다.
Args
- model_deployment: (
ManualModel
) 일반 모델 객체 - components: list(
Component
) 수정할 컴포넌트 리스트
Returns
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- components: list(
Component
) ML모델 컴포넌트 - table: (str) ML모델 테이블
- model_lib: (str) ML모델 라이브러리
- model_data: (str) ML모델 데이터
- features: (str) ML모델에 사용된 피쳐
- is_enabled: (bool) 활성상태 여부
Example
component = component_client.get_component(name="test_component") model_deployment = ml_model_client.get_model_deployment(name="manual_test_model", version="v1") updated_manual_model = ml_model_client.update_model_deployment_components( model_deployment=model_deployment, components=[component], ) no_component_manual_model = ml_model_client.update_model_deployment_components( model_deployment=model_deployment, components=[], )
- model_deployment: (
def update_model_deployment_meta(self, model_deployment: ManualModel, model_meta: dict, partial_update: bool = False) ‑> ManualModel
-
일반 모델 배포의 모델 메타 정보를 수정합니다. 위 메소드는 update_manual_model_meta와 같은 기능을 수행합니다.
Args
- model_deployment: (
ManualModel
) 일반 모델 객체 - model_meta: (dict) 수정할 모델 메타 정보
- partial_update: (optional) (dict) 기존 모델 메타에 덮어씌울지(True) 기존 모델 메타를 교체할지(False) 여부 (기본값:
False
)
Returns
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- components: list(
Component
) ML모델 컴포넌트 - table: (str) ML모델 테이블
- model_lib: (str) ML모델 라이브러리
- model_data: (str) ML모델 데이터
- features: (str) ML모델에 사용된 피쳐
- is_enabled: (bool) 활성상태 여부
Example
model_deployment = ml_model_client.get_model_deployment(name="my_manual_model", version="v1") model_deployment = ml_model_client.update_model_deployment_meta( model_deployment=model_deployment, model_meta={ "model_lib": "xgboost", "model_lib_version": "1.2.0", }, partial_update = True ) manual_model_deployment_without_meta = ml_model_client.update_manual_model_meta( model_deployment=model_deployment, model_meta={} )
- model_deployment: (
- env: (
class MLModelStatus (value, names=None, *, module=None, qualname=None, type=None, start=1)
-
An enumeration.
Ancestors
- enum.Enum
Class variables
var AUTOML_DONE
var AUTOML_FAILED
var AUTOML_TRAINING
var IN_USE
var NOT_IN_USE
var UNKNOWN
class MLSCatBoostModel (model, model_name: str, model_version: str, features: List[str])
-
MLS 모델 레지스트리에 등록되는 단일 CatBoost 기반 상위 클래스입니다.
Ancestors
Subclasses
Inherited members
class MLSGenericModel (models, model_name: str, model_version: str, features: List[str], custom_predict_async: Union[str, Callable] = None)
-
MLS 모델 레지스트리에 등록되는 제네릭 모델 기반 상위 클래스입니다.
Ancestors
Subclasses
- ConditionalGenericLogicModel
- DefaultGenericModel
- GenericContextModel
- GenericLogicModel
- SampleGenericModel
Methods
def load_custom_predict_async(self, file_path: str = None) ‑> Callable
def predict(self, x: List[Any], **kwargs) ‑> Dict[str, Any]
async def predict_async(self, x: List[Any], **kwargs) ‑> Dict[str, Any]
def set_model_lib(self, model_lib: str)
-
모델이 사용한 라이브러리 정보를 세팅하기 위한 함수입니다.
Inherited members
class MLSLightGBMModel (model, model_name: str, model_version: str, features: List[str] = None)
-
MLS 모델 레지스트리에 등록되는 단일 LightGBM 기반 상위 클래스입니다.
Ancestors
Subclasses
Inherited members
class MLSModel (model_name: str, model_version: str)
-
MLS 모델 레지스트리에 등록되는 최상위 클래스입니다.
Subclasses
Methods
def predict(self, x: List[Any], **kwargs) ‑> Dict[str, Any]
async def predict_async(self, x: List[Any], **kwargs) ‑> Dict[str, Any]
def save(self, env: MLSENV = None, runtime_env: MLSRuntimeENV = None, force: bool = False) ‑> NoneType
-
모델 바이너리(model.joblib)와 정보(model.json)를 MLS 모델 레지스트리에 등록합니다.
ModelRegistry.save()
와 동일하게 동작합니다.Args
- env: (
MLSENV
) 접근할 MLS 환경 (MLSENV.DEV
|MLSENV.STG
|MLSENV.PRD
) (기본값:MLSENV.STG
) - runtime_env: (
MLSRuntimeENV
) 클라이언트가 실행되는 환경 (MLSRuntimeENV.YE
|MLSRuntimeENV.EDD
|MLSRuntimeENV.LOCAL
) (기본값:MLSRuntimeENV.LOCAL
) - force: (bool) 이미 모델 레지스트리에 등록된 경우 덮어 쓸 것인지 여부 (기본값:
False
)
- env: (
class MLSModelError (msg)
-
Common base class for all non-exit exceptions.
Ancestors
- builtins.Exception
- builtins.BaseException
class MLSPyTorchModel (model, model_name: str, model_version: str, features: List[str])
-
MLS 모델 레지스트리에 등록되는 단일 PyTorch 기반 상위 클래스입니다.
Ancestors
Subclasses
Inherited members
class MLSRuleModel (model_name: str, model_version: str, features: List[str])
-
MLS 모델 레지스트리에 등록되는 Rule 기반 상위 클래스입니다.
Ancestors
Subclasses
- InfoDefectRuleModel
- InfoUnpaidRuleModel
- SampleRuleModel
- TwRandomGreetingRuleModel
- VasXcloudRuleModel
Inherited members
class MLSTrainable
-
AutoGluon을 통한 학습을 지원하는 클래스입니다.
이 클래스는 단독으로 상속될 수 없으며 MLSModel과 함께 상속되어야 정상 동작합니다.
GenericLogicModel
에서 실사용 가능합니다.Subclasses
Methods
def evaluate(self, test_data: pandas.core.frame.DataFrame) ‑> Dict[str, float]
-
AutoGluon을 통해 학습한 모델의 성능을 계산합니다.
참고 사항
fit
함수를 통해 학습이 된 경우에만 정상적으로 동작합니다.fit
함수에서는 모델 학습 후 한 차례 본 함수를 실행하여self.performance
에 저장합니다.
Args
- test_data: (optional) (
pandas.DataFrame
) 모델 성능 측정을 위한 테스트 데이터 프레임 (기본값: None)
Example
학습 및 테스트 데이터 준비
train_data, test_data = train_test_split(df, test_size=0.2, random_state=0)
학습
my_model_v1.fit( train_data=train_data, test_data=test_data, label="some_label" )
성능 계산
print(my_model_v1.evaluate(test_data))
def fit(self, train_data: pandas.core.frame.DataFrame, test_data: pandas.core.frame.DataFrame, label: str, non_training_features: List[str] = [], eval_metric: str = 'roc_auc', hyperparameters: Dict[str, Any] = {'CAT': {}}, k: int = 20, time_limit: int = None, ensemble: bool = False) ‑> NoneType
-
AutoGluon을 통해 모델을 학습합니다.
모델 학습이 완료되면
self.models[0]
에 자동으로 할당되며, 이후predict
함수에서 참조될 수 있습니다.참고 사항
- AutoGluon이 자동으로 분류 문제인지 회귀 문제인지 판단합니다.
- 성능 지표를 설정할 수 있으나, 분류 문제의 경우 기본값인
roc_auc
사용을 권장합니다. - 회귀 문제에 분류 성능 지표를 세팅하거나 분류 문제에 회귀 성능 지표를 세팅하면 에러가 발생합니다.
Args
- train_data: (
pandas.DataFrame
) 학습에 사용할 데이터 프레임 - test_data: (
pandas.DataFrame
) 모델 성능 측정을 위한 테스트 데이터 프레임 - label: (str) train_data 내 라벨 컬럼 이름
- non_training_features: (optional) (str) 학습에서 제외할 피쳐 이름 리스트. 후처리 전용 피쳐 등을 명세할 때 사용 가능 (기본값: [])
- eval_metric: (optional) (str) 성능 지표 (기본값:
roc_auc
)- 분류 모델의 경우 가능한 값:
accuracy
|balanced_accuracy
|f1
|f1_macro
|f1_micro
|f1_weighted
|roc_auc
|average_precision
|precision
|precision_macro
|precision_micro
|precision_weighted
|recall
|recall_macro
|recall_micro
|recall_weighted
|log_loss
|pac_score
- 회귀 모델의 경우 가능한 값:
root_mean_squared_error
|mean_squared_error
|mean_absolute_error
|median_absolute_error
|r2
- 분류 모델의 경우 가능한 값:
- hyperparameters: (optional) (dict) AutoGluon hyperparameters. 공식 문서 참조 (기본값: {"CAT": {}})
- k: (optional) (int) Feature importance를 바탕으로 선택할 상위 피쳐의 개수 (기본값: 20)
- time_limit: (optional) (int) 학습 시간 제한 시간 (단위: 초). n개의 모델을 학습하는 경우 1/n초씩 사용. None인 경우 무제한 (기본값: None)
- ensemble: (optional) (bool) 앙상블 모델 학습 여부. 추론 시간이 길어지므로 학습 후 벤치마크 필수 (기본값: False)
Example
features = […] preprocess_logic = {…} postprocess_logic = {…}
학습을 직접 할 것이므로
model
을None
으로 할당합니다.my_model_v1 = GenericLogicModel( model=None, model_name="my_model", model_version="v1", features=features, preprocess_logic=preprocess_logic, postprocess_logic=postprocess_logic, predict_fn="predict_proba" )
학습 및 테스트 데이터 준비
train_data, test_data = train_test_split(df, test_size=0.2, random_state=0)
학습
my_model_v1.fit( train_data=train_data, test_data=test_data, label="some_label" )
성능 확인
print(my_model_v1.performance) print(my_model_v1.feature_importance)
predict 테스트
print(my_model_v1.predict(test_feature_values, pf_client=pf_client, graph_client=graph_client))
배포
model_registry = ModelRegistry(env=MLSENV.STG, runtime_env=MLSRuntimeENV.YE) model_registry.save(my_model_v1)
def get_feature_importance(self, test_data: pandas.core.frame.DataFrame) ‑> pandas.core.series.Series
-
AutoGluon을 통해 학습한 모델의 피쳐 중요도를 계산하여
pandas.Series
형식으로 리턴합니다.참고 사항
fit
함수를 통해 학습이 된 경우에만 정상적으로 동작합니다.fit
함수에서는 모델 학습 후 한 차례 본 함수를 실행하여self.feature_importance
에 저장합니다.
Args
- test_data: (optional) (
pandas.DataFrame
) 모델 성능 측정을 위한 테스트 데이터 프레임 (기본값: None)
Example
학습 및 테스트 데이터 준비
train_data, test_data = train_test_split(df, test_size=0.2, random_state=0)
학습
my_model_v1.fit( train_data=train_data, test_data=test_data, label="some_label" )
성능 계산
print(my_model_v1.get_feature_importance(test_data))
def get_model_names_persisted(self) ‑> List[str]
-
캐시된 모델 이름 조회를 위한 함수로 내부 호출 용도입니다.
def persist_models(self) ‑> NoneType
-
모델 캐시를 위한 함수로 내부 호출 용도입니다.
def set_local_path(self) ‑> NoneType
-
로컬 환경에서의 정상적인 inference를 위한 path 업데이트 함수로 내부 호출 용도입니다.
def set_mms_path(self) ‑> NoneType
-
MMS에서의 정상적인 inference를 위한 path 업데이트 함수로 내부 호출 용도입니다.
def unpersist_models(self) ‑> NoneType
-
모델 캐시 만료를 위한 함수로 내부 호출 용도입니다.
class MLSXGBoostModel (model, model_name: str, model_version: str, features: List[str])
-
MLS 모델 레지스트리에 등록되는 단일 XGBoost 기반 상위 클래스입니다.
Ancestors
Subclasses
Inherited members
class ManualModel (**kwargs)
-
일반 모델 클래스이자, 모델 배포 객체입니다. 위 객체를 생성해 배치 추론 테이블 또는 모델 레지스트리에 등록된 모델 아티팩트를 서비스 가능하도록 배포합니다. 배포된 모델만 버킷에 연결하여 서비스 가능합니다.
Args
- kwargs
- id: (int) ML모델 고유 ID
- name: (str) ML모델 이름
- model_type: (str) ML모델 타입 (
sktmls.models.automl
|manual
) - version: (str) ML모델 버전
- description: (str) ML모델 설명
- creator: (str) ML모델 생성 계정명
- status: (
MLModelStatus
) ML모델 상태 - model_meta: (dict) ML모델 메타정보
- components: list(
Component
) ML모델 컴포넌트 리스트 - table: (str) ML모델 테이블
- model_lib: (str) ML모델 라이브러리
- model_data: (str) ML모델 데이터
- features: (str) ML모델에 사용된 피쳐
- is_enabled: (bool) 활성상태 여부
Returns
Ancestors
- kwargs