Supervised learning pipelines

การออกแบบ Machine Learning Workflows ด้วย Python

Dr. Chris Anagnostopoulos

Honorary Associate Professor

ข้อมูลที่มีป้ายกำกับ

  • ตัวแปรฟีเจอร์ (ย่อว่า X)
  • ป้ายกำกับหรือคลาส (ย่อว่า y)
credit_scoring.head(4)
  checking_status  duration  ...  foreign_worker class
0            '<0'         6  ...             yes  good
1      '0<=X<200'        48  ...             yes   bad
2   'no checking'        12  ...             yes  good
3            '<0'        42  ...             yes  good
การออกแบบ Machine Learning Workflows ด้วย Python

Feature engineering

  • classifier ส่วนใหญ่ต้องการฟีเจอร์ที่เป็นตัวเลข
  • ต้องแปลงคอลัมน์ที่เป็น string ให้เป็นตัวเลข

ประมวลผลล่วงหน้าด้วย LabelEncoder จาก sklearn.preprocessing:

le = LabelEncoder()
le.fit_transform(credit_scoring['checking_status'])[:4]
array([1, 0, 3, 1])
การออกแบบ Machine Learning Workflows ด้วย Python

การ fit โมเดล

  • .fit(features, labels)
  • .predict(features)
features, labels = credit_scoring.drop('class', 1), credit_scoring['class']

model_nb = GaussianNB() model_nb.fit(features, labels) model_nb.predict(features.head(5))
['good' 'bad' 'good' 'bad' 'good']

ความแม่นยำ 60% บน 5 ตัวอย่างแรก

การออกแบบ Machine Learning Workflows ด้วย Python

การเลือกโมเดล

  • .fit() ปรับพารามิเตอร์ของโมเดลให้เหมาะสม
  • แล้วโมเดลอื่นล่ะ?

AdaBoostClassifier ทำได้ดีกว่า GaussianNB บน 5 จุดข้อมูลแรก:

model_ab = AdaBoostClassifier()
model_ab.fit(features, labels)
model_ab.predict(features.head(5))
numpy.array(labels[0:5])
['good' 'bad' 'good' 'good' 'bad']
['good' 'bad' 'good' 'good' 'bad']
การออกแบบ Machine Learning Workflows ด้วย Python

การประเมินประสิทธิภาพ

ขนาดตัวอย่างที่มากขึ้น $\Rightarrow$ การประมาณค่าความแม่นยำที่ดีขึ้น:

from sklearn.metrics import accuracy_score
accuracy_score(labels, model_nb.predict(features)) # naive bayes
0.706
accuracy_score(labels, model_ab.predict(features)) # adaboost
0.802

การคำนวณนี้มีปัญหาอะไร?

การออกแบบ Machine Learning Workflows ด้วย Python

Overfitting และการแบ่งข้อมูล

Overfitting: โมเดลมักทำงานได้ดีกว่าบนข้อมูลที่ใช้ฝึก เมื่อเทียบกับข้อมูลที่ยังไม่เคยเห็น

ฝึกบน X_train, y_train และประเมินความแม่นยำบน X_test, y_test:

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

GaussianNB().fit(X_train, y_train).predict(X_test)
การออกแบบ Machine Learning Workflows ด้วย Python

ขั้นตอนการทำงาน supervised learning แบบมาตรฐาน เริ่มด้วย feature engineering การแบ่งข้อมูลเป็น train และ test ตามด้วยการประเมินและเลือกโมเดล อย่างไรก็ตาม pipeline มาตรฐานนี้อาจไม่เพียงพอสำหรับปัญหาในโลกจริง

การออกแบบ Machine Learning Workflows ด้วย Python

คอร์สนี้เกี่ยวกับอะไร?

  1. วิธีปรับแต่ง pipeline ของคุณให้รองรับการขยายขนาด
  2. ทำให้การพยากรณ์มีความเกี่ยวข้อง โดยให้ผู้เชี่ยวชาญด้านสาขามีส่วนร่วม
  3. ดูแลให้โมเดลยังคงทำงานได้ดีในระยะยาว
  4. การ fit โมเดลเมื่อมีป้ายกำกับไม่เพียงพอ
การออกแบบ Machine Learning Workflows ด้วย Python

คุณจะป้องกันวิกฤตสินเชื่อที่อยู่อาศัยได้ไหม?

การออกแบบ Machine Learning Workflows ด้วย Python

Preparing Video For Download...