ในบทความนี้ จะแนะนำวิธีการสร้างกระบวนการ Machine Learning ด้วย Python โดยใช้ iris dataset ตั้งแต่การโหลดข้อมูล, สร้าง Model, Cross Validation, วัด Accuracy และการนำ Model ไปใช้งาน เพื่อความสะดวกในการเรียนรู้ เราจะเลือกใช้ Anaconda ซึ่งเป็น Python Data Science Platform ซึ่งจะรวบรวมเครื่องมือ และ Library ที่จำเป็นต่อการพัฒนา โดยสามารถเลือก Download รุ่นที่เหมาะกับระบบปฏบัติการของท่านได้ที่ https://www.anaconda.com/download/ สามารถ Clone Repository ตัวอย่างทั้งหมดที่กล่าวถึงในบทความนี้ได้จาก https://github.com/nagarindkx/pythonml และ แนะนำให้ใช้งาน jupyter-notebook เพื่อสะดวกในการเรียนรู้ บทความนี้ใช้ Notebook: 01 – SVM with iris dataset.ipynb เริ่มจาก import dataset “iris” จาก SciKit ซึ่งเป็น dataset ตัวอย่างทีดี ในการสร้างระบบ Predict ชนิดของดอกไม้ จากการป้อนค่า ความกว้างและความยาวของกลีบดอก Iris (รายละเอียดอ่านได้จาก https://en.wikipedia.org/wiki/Iris_flower_data_set) ซึ่งเป็นการวัดความกว้าง และ ความยาวของกลีบดอก ของดอก “iris” (sepal width, sepal length, petal width, petal length) ใน 3 Spicy Image Source: https://en.wikipedia.org/wiki/Iris_flower_data_set ชุด iris dataset นี้ มักจะใช้ในการเริ่มต้นเรียนรู้ กระบวนการสร้าง Machine Learning เพื่อการ Classification โดยในตัวอย่างนี้จะใช้ Support Vector Machine (SVM) โดยเมื่อสร้างและ Train Model เสร็จแล้ว สามารถนำ Model นี้ไปใช้ในการ จำแนก Species ได้ โดยการระบุ ความกว้างและความยาวดังกล่าว แล้วระบบจะตอบมาได้ว่า เป็น Species ใด ในการเริ่มต้นนี้ เราจะใช้ iris dataset ที่มาพร้อมกับ SciKit (sklearn) ซึ่งเป็น Machine Learning Package ในภาษา Python (ซึ่งติดตั้งมาในชุดของ Anaconda เรียบร้อยแล้ว) นำเข้าข้อมูล from sklearn import datasets iris = datasets.load_iris() สำรวจข้อมูล print(iris.data) print(iris.target) print(iris.data.shape) print(iris.target.shape) ใช้งาน SVM (Support Vector Machine) สร้าง SVC (Support Vector Classification) เพื่อทำการ Training ด้วยคำสั่ง fit โดยใส่ค่า data และ target ลงไป from sklearn import svm clf = svm.SVC() clf.fit(iris.data, iris.target) ผลที่ได้คือ SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, decision_function_shape=None, degree=3, gamma=’auto’, kernel=’rbf’, max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False) ทดลองทำการ Predict ด้วยคำสั่ง predict แล้วใส่ Array ข้อมูลลงไป print(clf.predict([[ 6.3 , 2.5, 5.,