머신 러닝 파이프라인 개발

Python으로 IoT 데이터 분석하기

Matthias Voppichler

IT Developer

파이프라인

  • 변환
    • 전처리
    • 스케일링
  • 추정기
    • 모델
Python으로 IoT 데이터 분석하기

파이프라인 생성

from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline

# 객체 초기화 sc = StandardScaler() logreg = LogisticRegression()
# 파이프라인 생성 pl = Pipeline([ ("scale", sc), ("logreg", logreg) ])
Python으로 IoT 데이터 분석하기

파이프라인 확인

pl
Pipeline(memory=None,
         steps=[('scale', StandardScaler(copy=True, with_mean=True, with_std=True)), 
                ('logreg', <class 'sklearn.linear_model.logistic.LogisticRegression'>)])
pl.fit(X_train, y_train)

print(pl.predict(X_test))
[0 0 1 1 0 1 1 0 0]
Python으로 IoT 데이터 분석하기

모델 저장

import pickle

with Path("pipeline_model.pkl").open("bw") as f: pickle.dump(pl, f)
Python으로 IoT 데이터 분석하기

모델 로드

import pickle
with Path("pipeline_model.pkl").open('br') as f:
    pl = pickle.load(f)

pl
Pipeline(memory=None,
     steps=[('scale', StandardScaler(copy=True, with_mean=True, with_std=True)), 
             ('logreg', LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
          intercept_scaling=1, max_iter=100, multi_class='warn', n_jobs=None, penalty='l2', 
          random_state=None, solver='warn', tol=0.0001, verbose=0, warm_start=False))])

주의

신뢰할 수 없는 파일은 절대 unpickle 하지 마십시오. 악성 코드가 실행될 수 있습니다.

Python으로 IoT 데이터 분석하기

연습해 봅시다!

Python으로 IoT 데이터 분석하기

Preparing Video For Download...