พัฒนา machine learning pipeline

การวิเคราะห์ข้อมูล IoT ด้วย Python

Matthias Voppichler

IT Developer

Pipeline

  • Transform
    • Conversation
    • Scaling
  • Estimator
    • Model
การวิเคราะห์ข้อมูล IoT ด้วย Python

สร้าง Pipeline

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

# Initialize Objects sc = StandardScaler() logreg = LogisticRegression()
# Create pipeline pl = Pipeline([ ("scale", sc), ("logreg", logreg) ])
การวิเคราะห์ข้อมูล IoT ด้วย Python

ตรวจสอบ Pipeline

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]
การวิเคราะห์ข้อมูล IoT ด้วย Python

บันทึกโมเดล

import pickle

with Path("pipeline_model.pkl").open("bw") as f: pickle.dump(pl, f)
การวิเคราะห์ข้อมูล IoT ด้วย Python

โหลดโมเดล

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 ไฟล์ที่ไม่น่าเชื่อถือ เพราะอาจทำให้โค้ดอันตรายถูกรันขึ้นได้

การวิเคราะห์ข้อมูล IoT ด้วย Python

มาฝึกกันเถอะ!

การวิเคราะห์ข้อมูล IoT ด้วย Python

Preparing Video For Download...