Skip to content
Home » [NEW] Machine Learning บทที่ 4: Logistic Regression | การใช้ perhaps – NATAVIGUIDES

[NEW] Machine Learning บทที่ 4: Logistic Regression | การใช้ perhaps – NATAVIGUIDES

การใช้ perhaps: นี่คือโพสต์ที่เกี่ยวข้องกับหัวข้อนี้

Logistic Regression

โดย ชิตพงษ์ กิตตินราดร | ธันวาคม 2562

คราวที่แล้วเราได้เรียนรู้ Linear Regression เพื่อสร้างโมเดลพยากรณ์ผลลัพธ์ที่เป็นตัวเลขต่อเนื่อง (Continuous number) คราวนี้เราจะมาสร้างโมเดลสำหรับพยากรณ์หมวดหมู่ หรือที่เรียกว่า Classification กันบ้าง

โจทย์ของเราคือการจำแนกสายพันธุ์ของพืชตระกูล Iris ออกเป็น 3 กลุ่ม คือ Sentosa, Versicolor, และ Virginica โดยมีข้อมูลอยู่ 4 Feature คือ ความยาวกลีบเลี้ยง (Sepal length), ความกว้างกลีบเลี้ยง (Sepal width), ความยาวกลีบดอก (Petal length), และความกว้างกลีบดอก (Petal width) โดยทั้งหมดมีหน่วยวัดเป็นเซนติเมตร

ภาพจาก Radomil, CC BY-SA 3.0 | Dlanglois, CC BY-SA 3.0 | Frank Mayfield – originally posted to Flickr as Iris virginica shrevei BLUE FLAG, CC BY-SA 2.0

Load

เราจะใช้ชุดข้อมูล Iris plants dataset ซึ่งเป็นชุดข้อมูลยอดนิยมในการทดสอบโมเดลการจำแนกแบบหลายหมวดหมู่ โดยชุดข้อมูลนี้ถูกฝังอยู่ใน scikit-learn เรียบร้อยแล้ว สามารถเรียกใช้ได้เลยโดยการเรียก load_iris() ฟังก์ชัน ในคลาส datasets:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression

# Load the iris data
iris = datasets.load_iris()

Explore

เมื่อโหลดแล้วลองดูโครงสร้างและคำอธิบายข้อมูล:

print(iris.keys())
print(iris["DESCR"])
print("Feature names are: ", iris["feature_names"])
print("Target names are: ", iris["target_names"])

Method .keys ของ iris object จะเรียกดู Dictionary key ของชุดข้อมูล ซึ่งประกอบด้วย:

dict_keys(['data', 'target', 'target_names', 'DESCR', 'feature_names', 'filename'])

หมายความว่าถ้าเราเรียกดู Keys เหล่านี้ ก็จะเจอข้อมูลใน Key นั้นๆ เช่น ถ้าเราอยากรู้ว่าหมวดหมู่ที่จะพยากรณ์ มีอะไรบ้าง ก็เรียก iris["target_names"] ก็จะได้:

['setosa' 'versicolor' 'virginica']

แนะนำให้เรียก iris["DESCR"] เพื่อดูคำอธิบายชุดข้อมูลด้วย จะได้เข้าใจที่มาที่ไป ลักษณะ และจำนวนตัวอย่างข้อมูล:

Iris plants dataset
--------------------

**Data Set Characteristics:**

    :Number of Instances: 150 (50 in each of three classes)
    :Number of Attributes: 4 numeric, predictive attributes and the class
    :Attribute Information:
        - sepal length in cm
        - sepal width in cm
        - petal length in cm
        - petal width in cm
        - class:
                - Iris-Setosa
                - Iris-Versicolour
                - Iris-Virginica

    :Summary Statistics:

    ============== ==== ==== ======= ===== ====================
                    Min  Max   Mean    SD   Class Correlation
    ============== ==== ==== ======= ===== ====================
    sepal length:   4.3  7.9   5.84   0.83    0.7826
    sepal width:    2.0  4.4   3.05   0.43   -0.4194
    petal length:   1.0  6.9   3.76   1.76    0.9490  (high!)
    petal width:    0.1  2.5   1.20   0.76    0.9565  (high!)
    ============== ==== ==== ======= ===== ====================

    :Missing Attribute Values: None
    :Class Distribution: 33.3% for each of 3 classes.
    :Creator: R.A. Fisher
    :Donor: Michael Marshall (MARSHALL%[email protected])
    :Date: July, 1988

The famous Iris database, first used by Sir R.A. Fisher. The dataset is taken
from Fisher's paper. Note that it's the same as in R, but not as in the UCI
Machine Learning Repository, which has two wrong data points.

This is perhaps the best known database to be found in the
pattern recognition literature.  Fisher's paper is a classic in the field and
is referenced frequently to this day.  (See Duda & Hart, for example.)  The
data set contains 3 classes of 50 instances each, where each class refers to a
type of iris plant.  One class is linearly separable from the other 2; the
latter are NOT linearly separable from each other.

Prepare

พอเข้าใจข้อมูลแล้ว ก็ต้องเตรียมข้อมูลให้อยู่ในรูปแบบที่จะนำไปให้โมเดลฝึกได้ ซึ่งโดยหลักการคือการกำหนด Matrix ข้อมูลให้อยู่ในตัวแปร X ส่วน Vector เป้าหมายให้อยู่ในตัวแปร y โดยสำหรับชุดข้อมูลที่ฝังอยู่ใน scikit_learn เราสามารถเรียก Method .data และ .target ได้เลย

X = iris.data
y = iris.target
print("X_shape shape is:", X.shape)
print("y_shape shape is:", y.shape)

สองบรรทัดสุดท้าย เป็นการตรวจสอบมิติของข้อมูลทั้ง X และ y ซึ่งจะได้:

X_shape shape is: (150, 4)
y_shape shape is: (150,)

แปลว่า X เป็น Matrix ขนาด (150, 4) คือมี 150 แถวเท่ากับจำนวนตัวอย่าง และ 4 คอลัมน์เท่ากับจำนวน Feature ส่วน y เป็น Column vector ขนาด 150 ซึ่งจะต้องเท่ากับจำนวนแถวของ X matrix

อนึ่ง เราใช้ตัวพิมพ์ใหญ่ เช่น X เวลาแทน Matrix ส่วน Vector ใช้ตัวพิมพ์เล็กเช่น y เพื่อทำให้ชัดเจนว่าข้อมูลอยู่ในประเภทอะไรทางคณิตศาสตร์

จากนั้นเราจะแบ่งข้อมูลออกเป็น Train set กับ Test set โดยการสุ่มด้วยฟังก์ชัน train_test_split ในโมดูล model_selection โดยฟังก์ชันนี้จะ Return ตัวแปร 4 ตัว ได้แก่ Matrix X เพื่อเทรน, Matrix X เพื่อทดสอบ, Vector Y เพื่อเทรน, และ Vector Y เพื่อทดสอบ ตามลำดับ ดังนั้นให้เรากำหนดตัวแปรทั้ง 4 เมื่อเรียกฟังก์ชันนี้

# Split the data into train and test set
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
print("X_train shape is:", X_train.shape)
print("y_train shape is:", y_train.shape)
print("X_test shape is:", X_test.shape)
print("y_test shape is:", y_test.shape)

สังเกตว่า train_test_split มี Argument X, y ซึ่งก็คือชุดข้อมูลที่เราเพิ่งเตรียม และมี random_state ซึ่งทำให้เราสามารถกำหนดได้การสุ่มแต่ละครั้งได้ผลออกมาเหมือนกัน ซึ่งเป็นประโยชน์ในการทดสอบโมเดล เพราะถ้าเราเรียกฟังก์ชันแต่ละครั้งแล้วผลออกมาไม่เหมือนกัน คือแต่ละครั้งก็สุ่มใหม่ เราจะไม่สามารถควบคุมตัวแปรในการทดสอบโมเดลได้

วิธีการกำหนด random_state คือการใส่ตัวเลขจำนวนเต็มอะไรก็ได้ลงไป ถ้าดูหนังสือหรือโค้ดคนอื่นจะเห็นว่าบางทีจะใส่เลข 42 อันนี้เป็น Meme ซึ่งมาจากนิยายวิทยาศาสตร์เรื่อง A Hitchhiker’s Guide to the Galaxy ของ Douglas Adams

Visualise

ก่อนจะสร้างโมเดลก็น่าจะลอง Visualise ข้อมูลให้เห็นภาพสักหน่อย ในที่นี่เราจะสร้าง Scatterplot matrix ซึ่งแสดงความสัมพันธ์ระหว่างข้อมูลแต่ละ Feature และจำแนกจุดที่เป็นตัวแทนของข้อมูลที่อยู่ในหมวดหมู่แต่ละหมวดจาก 3 หมวด โดยการใช้สีที่ไม่เหมือนกัน

# Plot the data
iris_df = pd.DataFrame(X_train, columns=iris.feature_names)
pd.plotting.scatter_matrix(iris_df, c=y_train, figsize=(12,12), marker="o")

ได้ผลแบบนี้:

วิธีอ่าน Scatterplot matrix มีดังนี้:

  • Scatterplot matrix แสดงความสัมพันธ์ระหว่างตัวแปรสองตัว ซึ่งอาจจะเป็น Feature ทั้งสองตัว หรืออาจจะเป็น Feature กับ Label ก็ได้ โดยแสดงทุกคู่ความสัมพันธ์ที่เป็นไปได้อยู่ในภาพเดียวกัน เลยมีหน้าตาเป็น Matrix
  • จะเห็นว่า Matrix ช่องบนซ้ายแทยงลงมาช่องล่างขวา ไม่ได้แสดงเป็น Scatter plot แต่เป็น Distribution plot เพราะมันคือความสัมพันธ์ของตัวมันเอง โดย Distribution plot ก็มีประโยชน์ ทำเราจะได้เห็นว่ารายการข้อมูลทั้งหมดมีการกระจายตัวใน Feature นั้นอย่างไร เช่น ช่อง Sepal width พบว่ามีการกระจายตัวแบบ Normal distribution คือข้อมูลส่วนมากมีค่าอยู่กลางๆ แถวๆ Mean แล้วกระจายตัวออกทั้งด้านลบและด้านบวก
  • ส่วนช่องอื่นๆ เราสามารถกำหนดให้แยกสีตาม Label ได้ ทำให้เห็นว่าในแต่ละคู่ความสัมพันธ์ ข้อมูล Label ไหนอยู่ตรงไหน ตัวอย่างเช่น คู่ Petal length VS. Sepal length (แถว 3 คอลัมน์ 1) จะเห็นว่า Label แรกจะมี Petal และ Sepal length น้อย, Label ที่สองอยู่ตรงกลางๆ, และ Label ที่สามมีค่ามาก แต่เมื่อดู Sepal width VS. Sepal length (แถว 2 คอลัมน์ 1) พบว่า Label 2 และ 3 มีค่าผสมผสานกัน แยกกจากกันไม่เด็ดขาด เป็นต้น

สำหรับเรา ประโยชน์หนึ่งจากการอ่าน Scatterplot matrix คือการสร้างความเข้าใจในภาพรวมว่าชุดข้อมูลนี้น่าจะ “ยาก” หรือ “ง่าย” ในการสร้างโมเดล โดยถ้าข้อมูลแต่ละ Label แยกจากกันค่อนข้างชัด การสร้างโมเดลก็จะค่อนข้างง่ายและแม่นยำ

Logistic regression algorithm

และแล้วก็เกือบถึงเวลาที่จะฝึกโมเดลให้เข้ากับชุดข้อมูล แต่ก่อนหน้านั้นเรามาทำความเข้าใจว่า Algorithm ที่เราจะใช้นั้นทำงานอย่างไร โดย Algorithm ที่เราเลือกใช้คือ Logistic Regression ชื่ออาจจะฟังดูเหมือน Regression ที่มีเป้าหมายพยากรณ์ค่าต่อเนื่อง แต่ในความเป็นจริงไม่ได้เป็นอย่างนั้น เราลองมาดูกันว่าโมเดลนี้ทำงานอย่างไร

Hypothesis function

ใน Classification model เราต้องการให้ y มีคำตอบ คือ 0 หรือ 1 เท่านั้น ซึ่งหมายความว่า “ไม่ใช่” หรือ “ใช่” (ตอนนี้กำหนดให้มีสองคำตอบไปก่อน การใช้หลักการเดียวกันมาใช้กับการจัดหมวดหมู่ที่มีหลายคำตอบ ทำได้โดยการใช้ Softmax function ซึ่งจะกล่าวถึงภายหลัง)

แต่ในความเป็นจริง เราไม่สามารถมั่นใจอะไรได้ร้อยเปอร์เซ็น ว่าคำตอบคือ “ไม่ใช่” หรือ “ใช่” ดังนั้น สิ่งที่เราต้องการ คือเราจะสร้าง Hypothesis function ที่ให้ค่าความเป็นไปได้ ที่คำตอบจะคือ “ไม่ใช่” หรือ “ใช่” โดยกำหนดขอบเขตการตัดสินใจ (Decision boundary) ไว้ที่ 0.5 ซึ่งจะทำให้เราได้ขอบเขตการตัดสินใจดังนี้:

โดย คือ Hypothesis function ที่มี x เป็น Input ซึ่งอยู่ในรูปของ:

อ่านว่า Sigma และ อ่านว่า Sigmoid z ซึ่ง นี้เป็นฟังก์ชันที่เรียกว่า Sigmoid function หรือ Logistic function ซึ่งเป็นที่มาของชื่อ Logistic regression นั่นเอง

Sigmoid function มีหน้าตาอย่างนี้:

  • แกนนอนคือ Input ซึ่งในที่นี้คือ ส่วนแกนตั้งคือ Output ซึ่งในที่นี้คือ
  • สังเกตว่าเมื่อ มีค่ามาก จะมีค่าเข้าใกล้ 1 ส่วนเมื่อ มีค่าน้อย จะมีค่าเข้าใกล้ 0
  • สังเกตว่าเมื่อ , ซึ่งอยู่กึ่งกลางระหว่าง Limit ด้านบน คือ 1 และ Limit ด้านล่าง คือ 0 ดังนั้นเราจึงเลือก 0.5 เป็นขอบเขตการตัดสินใจนั่นเอง
  • คือค่าคงที่ของ Euler มีค่าเท่ากับ 2.7182 (และทศนิยมลำดับต่อไปเรื่อยๆ)
  • คือ Linear function ซึ่งเราเคยใช้ใน Linear regression โดยไม่มีตัวแปร Intercept

นั่นหมายความว่า:

อนึ่ง สำหรับใครที่สนใจจะเขียน Algorithm เอง จะควรจะแปลง ให้เป็น Vectorised form เพื่อเร่งความเร็วในการคำนวน ซึ่งมีวิธีคือหาการ Dot product ของ W transpose และ X (ทั้งคู่เป็น Matrix) ดังนั้นเราจะได้ Sigmoid function ดังนี้:

เมื่อได้ Hypotheses function แล้ว หน้าที่ของเรา คือการหาค่า w ที่จะทำให้ค่าความคลาดเคลื่อนระหว่าง กับ นั้นน้อยที่สุด การที่จะทำให้ค่าความคลาดเคลื่อนน้อยที่สุดดังกล่าว ก็ต้องอาศัย Cost function และการหา Gradient descent ของ Cost function เหมือนที่เราเคยทำ

Cost function

สำหรับ Logistic regression เราจะใช้ Cost function ดังนี้:

ลองทำความเข้าใจเงื่อนไขของ Cost function ด้านบน พิจารณาว่าหน้าที่ของ Cost function คือการหาค่าตัวแปรที่จะส่งผลให้ Cost นั้นต่ำที่สุด ซึ่งแบ่งได้เป็น 2 กรณี คือเมื่อ y เท่ากับ 1 และ y เท่ากับ 0

โดยในกรณีของ y เท่ากับ 1 หากเราได้ Hypothesis function จะทำให้ Cost function ซึ่งก็คือ ซึ่งมีค่าน้อยที่สุดที่จะเป็นไปได้ ดังนั้นเราจึงใช้ เป็นตัวแทนของ Cost function ในกรณี

ส่วนในกรณีของ y เท่ากับ 0 หากเราได้ Hypothesis function จะทำให้ Cost function ซึ่งก็คือ ซึ่งมีค่าน้อยที่สุดที่จะเป็นไปได้ ดังนั้นเราจึงใช้ เป็นตัวแทนของ Cost function ในกรณี

เงื่อนไขทั้งสองแบบ สามารถนำมารวมกันเป็นสมการเดียวได้ว่า:

นำ Cost function นี้มาใส่ในรูปแบบ Cost function ของ Linear regression:

จะได้ Cost function เต็มรูปแบบ คือ:

หรือใน Vectorised form ดังนี้:

Gradient descent

เชื่อหรือไม่ว่าอนุพันธ์ของ ของ Logistic regression cost function นั้นเหมือนกับอนุพันธ์ ของ Linear regression cost function:

ส่วน Vectorized version ก็คือ:

ดังนั้น วิธีการอับเดตตัวแปรจึงทำเหมือน Linear regression ทุกประการ

Softmax function

Algorithm ของเราสามารถให้คำตอบสำหรับปัญหาที่มีคำตอบแค่ 2 ค่า คือ 1 กับ 0 เรียกว่า Binary classification แล้วถ้าคำตอบมีหลายค่า เช่นในโจทย์ของเรา ที่ต้องการจำแนกดอก Iris ออกเป็น 3 สายพันธุ์ล่ะ เราเรียกปัญหาแบบนี้ว่า Multiclass classification

Logistic Regression สามารถให้คำตอบปัญหา Multiclass classification โดยการแก้ไขรายละเอียดของกลไกเล็กน้อย ซึ่งจบลงที่การใช้ Softmax function ตอน Output โดยมีหลักการและขั้นตอนดังนี้:

1) คำนวนหาผลลัพธ์ Linear function z ของแต่ละ Class k:

เช่นกรณีของเรา มี k = 3 เราจะได้ , , และ ของข้อมูลแต่ละรายการ

2) นำ ไปประกอบกันใน Softmax function แทน Logistic function เดิม ดังนี้:

  • คือความเป็นไปได้ที่รายการนี้จะอยู่ใน Class k
  • เป็นค่าความเป็นไปได้ที่รายการนี้จะอยู่ใน Class k โดยเทียบกับคะแนน Linear function ของแต่ละ Class ของรายการนั้น

โดย Softmax จะเลือกพยากรณ์ Class ที่ได้คะแนนความเป็นไปได้สูงที่สุด

ถ้าอ่านแล้วงง ลองโค้ด Softmax function ใน Python ดู:

z = [1, 2, 3]
p = np.exp(z)/np.sum(np.exp(z))

เมื่อเรียก p จะได้ผลว่า array([0.09003057, 0.24472847, 0.66524096]) แปลว่าถ้า Linear function z ของ Class แรก ให้ผลเท่ากับ 1 ความเป็นไปได้ของ Class นี้จะเท่ากับ 9% เมื่อเทียบกับ Class ที่สอง (2 –> 24.47%) และ Class ที่สาม (3 –> 66.52%) ดังนั้น Softmax function จะเลือก Class 3 เป็นคำตอบ

3) Algorithm จะนำ ไปคำนวนใน Cost function ที่ดัดแปลงจากเดิมเล็กน้อย เรียกว่า Cross entropy cost function เพื่อหา Global minimum ที่จะทำให้ความต่างของค่าที่พยากรณ์กับค่าจริงมีน้อยที่สุด:

  • คือค่าจริงที่รายการที่ i จะอยู่ใน Class k ซึ่งจะมีค่า 1 หรือ 0

4) หาอนุพันธ์ในกระบวนการ Gradient descent โดยใช้สูตรเดิม:

อนึ่ง ฟังก์ชัน LogisticRegression ใน scikit-learn จะเลือกใช้ Softmax function โดยอัตโนมัติอยู่แล้ว โดยดูจากข้อมูล Label y ของเรา ซึ่งสะดวกมาก ไม่ต้องทำอะไรเพิ่มแล้ว แค่เรียกฟังก์ชัน

Modelling

ตอนนี้เราก็พร้อมแล้วในการสร้างโมเดล โดยเรียก Class LogisticRegression และพ่วง Method .fit เพื่อสร้างเทรนโมเดลไปเลย

# Train the model
logreg = LogisticRegression(max_iter=200, random_state=42).fit(X_train, y_train)

จะเห็นว่า Class LogisticRegression มี Argument max-iter อยู่ด้วย Argument นี้ทำหน้าที่ควบคุม Hyperparameter ของโมเดล โดยเราสามารถกำหนดว่าจะให้ Algorithm (เรียกใน scikit-learn ว่า “Solver”) ทำงานกี่รอบ ในลักษณะเดียวกับที่ Gradient descent อับเดต Parameter ซ้ำไปเรื่อยๆ เพื่อให้ Cost function ลดลงทุกๆ รอบ

อันที่จริง แต่ละโมเดลจะมี Argument แบบนี้มากมาย เช่น LogisticRegression มี Argument ดังนี้ (ดูจากเอกสารอ้างอิงของ scikit-learn):

class sklearn.linear_model.LogisticRegression(penalty=’l2′, dual=False, tol=0.0001, C=1.0, fit_intercept=True, intercept_scaling=1, class_weight=None, random_state=None, solver=’lbfgs’, max_iter=100, multi_class=’auto’, verbose=0, warm_start=False, n_jobs=None, l1_ratio=None)

เราจะพูดถึง Hyperparameter เหล่านี้ในหัวข้อถัดไป ในขั้นนี้เพียงแค่ให้รู้ก่อนว่าเราสามารถกำหนดค่าต่างๆ เพื่อปรับแต่งโมเดลของเราได้ในที่นี้

Evaluate

เมื่อเทรนโมเดลแล้ว เราก็มีประเมินความแม่นยำกัน:

# Evaluate the model's accuracy
print("Train set accuracy = " + str(logreg.score(X_train, y_train)))
print("Test set accuracy = " + str(logreg.score(X_test, y_test)))

ได้ผลว่า:

Train set accuracy = 0.9642857142857143
Test set accuracy = 1.0

นั่นคือเมื่อเทรนกับ Train set ได้ความแม่นยำ 96.42% ส่วนเมื่อนำมาทดสอบกับ Test set ได้ความแม่นยำถึง 100% ทีเดียว

สำหรับวิธีการคำนวนความแม่นยำของ Logistic regression สูตรนั้นง่ายมาก คือคำนวนว่าสัดส่วนระหว่าง ที่ให้ค่าตรงกับ ที่แท้จริงนั้น เป็นเท่าไหร่

Predict

มาลองดูกันว่าเวลาเราต้องการพยากรณ์จริงๆ นั้นทำอย่างไร สมมุติว่าเราไปเจอดอก Iris ที่อยากรู้ว่าเป็นสายพันธุ์ไหน เราจึงไปวัด Feature ทั้ง 4 มา ได้ว่า:

  • sepal length 6 cm
  • sepal width 2.5 cm
  • petal length 4 cm
  • petal width 1.5 cm

เราจะต้องใส่ข้อมูลนี้ลงไปในให้โมเดลพยากรณ์ โดยทำข้อมูลให้อยู่ในรูปแบบและมิติเดียวกันกับ X ที่เอาไว้เทรน ซึ่งถ้าจำได้ เราเคยหามิติของ X ไว้ ได้ดังนี้:

X_shape shape is: (150, 4)

คือเป็น Array ขนาด 150 แถว 4 คอลัมน์ โดยแต่ละแถวคือ 1 รายการ ดังนั้น X ใหม่ของเรา ตั้งชื่อว่า X_new จีงจะต้องเป็น Array มิติ (1, 4) ซึ่งเขียนใน Python ได้ว่า np.array([[6, 2.5, 4, 1.5]]):

# Make a prediction
X_new = np.array([[6, 2.5, 4, 1.5]])
y_pred = logreg.predict(X_new)
y_pred_prob = logreg.predict_proba(X_new)
print("Prediction:", y_pred, "with the probability array:", y_pred_prob)
print("Predicted target name:", iris["target_names"][y_pred])

ได้คำตอบคือ:

Prediction: [1] with the probability array: [[0.01372466 0.91809317 0.06818217]]
Predicted target name: ['versicolor']

นั่นคือโมเดลได้พยากรณ์ว่าดอก Iris ดอกนี้ เป็นสายพันธุ์ Versicolor โดยมีความมั่นใจ 91.8% อย่างไรก็ตามก็มีความเป็นไปได้ที่จะเป็นสายพันธุ์ Setosa 1.37% และ Virginica 6.81%

ถ้าดูโค้ดแล้วงง ลองพิจารณารายละเอียดดังนี้:

  • Method .predict_proba หมายว่าว่า ให้พยากรณ์โดย Output ออกเป็น Array ของความเป็นไปได้
  • ทำไม iris["target_names"][y_pred] จึงให้ผลออกมาเป็นชื่อสายพันธุ์ได้ ถ้าจำได้ตอนต้น เรารู้ว่าชุดข้อมูลนี้ได้เตรียม Dictionary key ที่ชื่อ target_names ไว้ให้ โดยมีค่าว่า ['setosa' 'versicolor' 'virginica'] คำสั่งนี้คือการเรียกค่าของ Key target_names ลำดับที่ [y_pred] ซึ่งในที่นี้คือ [1] นั่นเอง

สรุป

เป็นอันว่าเราสร้างโมเดล Logistic regression เพื่อพยากรณ์ปัญหา Multiclass classification สำเร็จ

ในบทต่อไปจะเจาะลึกรายละเอียดเกี่ยวกับการเตรียมข้อมูล โดยเฉพาะข้อมูลที่เป็นข้อความหรือหมวดหมู่ ซึ่งเราต้องแปลงให้เป็นตัวเลขเสียก่อน

หน้าแรก | บทที่ 3 Linear Regression Programming | บทที่ 5 Categorial Encoding

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.

[NEW] perhaps แปลว่าอะไร ดูความหมาย ตัวอย่างประโยค หมายความว่า พจนานุกรม Longdo Dictionary แปลภาษา คำศัพท์ | การใช้ perhaps – NATAVIGUIDES

From The Collaborative International Dictionary of English v.0.48 [gcide]:

  Perhaps \Per*haps"\ (p[~e]r*h[a^]ps"), adv. [Per + hap chance.]
     Posibly; by chance; peradventure; perchance; it may be.
     [1913 Webster]
  
           And pray God, if perhaps the thought of thine heart may
           be forgiven thee.                        --Acts viii.
                                                    22.
     [1913 Webster]

From The Collaborative International Dictionary of English v.0.48 [gcide]:

  May \May\ (m[=a]), v. [imp. {Might} (m[imac]t)] [AS. pres. maeg
     I am able, pret. meahte, mihte; akin to D. mogen, G.
     m["o]gen, OHG. mugan, magan, Icel. mega, Goth. magan, Russ.
     moche. [root]103. Cf. {Dismay}, {Main} strength, {Might}. The
     old imp. mought is obsolete, except as a provincial word.]
     An auxiliary verb qualifying the meaning of another verb, by
     expressing:
     (a) Ability, competency, or possibility; -- now oftener
         expressed by {can}.
         [1913 Webster]
  
               How may a man, said he, with idle speech,
               Be won to spoil the castle of his health!
                                                    --Spenser.
         [1913 Webster]
  
               For what he [the king] may do is of two kinds; what
               he may do as just, and what he may do as possible.
                                                    --Bacon.
         [1913 Webster]
  
               For of all sad words of tongue or pen
               The saddest are these: "It might have been."
                                                    --Whittier.
         [1913 Webster]
     (b) Liberty; permission; allowance.
         [1913 Webster]
  
               Thou mayst be no longer steward.     --Luke xvi. 2.
         [1913 Webster]
     (c) Contingency or liability; possibility or probability.
         [1913 Webster]
  
               Though what he learns he speaks, and may advance
               Some general maxims, or be right by chance. --Pope.
         [1913 Webster]
     (d) Modesty, courtesy, or concession, or a desire to soften a
         question or remark.
         [1913 Webster]
  
               How old may Phillis be, you ask.     --Prior.
         [1913 Webster]
     (e) Desire or wish, as in prayer, imprecation, benediction,
         and the like. "May you live happily." --Dryden.
         [1913 Webster]
  
     {May be}, & {It may be}, are used as equivalent to
        {possibly}, {perhaps}, {maybe}, {by chance},
        {peradventure}. See 1st {Maybe}.
        [1913 Webster]

From WordNet (r) 3.0 (2006) [wn]:

  perhaps
      adv 1: by chance; "perhaps she will call tomorrow"; "we may
             possibly run into them at the concert"; "it may
             peradventure be thought that there never was such a time"
             [syn: {possibly}, {perchance}, {perhaps}, {maybe},
             {mayhap}, {peradventure}]


Perfume Etiquette: How to Store, Apply and Choose Yours \u0026 Why I Keep My Scent a Secret


jamilamusayeva etiquette perfume

Hi,
I am Jamila Musayeva, an international social etiquette consultant and author of etiquette books: “Etiquette: the least you need to know” and “Afternoon Tea Etiquette.” If you wish to order my books, email me at [email protected]
In this video, I explain all the rules regarding perfume: how to choose your scent, how to best store and properly apply the fragrance. I will also disclose the reasons as to why I prefer to keep my perfume choice a secret. At the very end of this video, I will share my personal tips on how to keep your bag and notebook smelling nice.
Yours,
Jamila Musayeva
Follow me on Instagram: https://www.instagram.com/jamila_musayeva
Website: http://jamilamusayeva.com/
Email: [email protected]

นอกจากการดูบทความนี้แล้ว คุณยังสามารถดูข้อมูลที่เป็นประโยชน์อื่นๆ อีกมากมายที่เราให้ไว้ที่นี่: ดูเพิ่มเติม

Perfume Etiquette: How to Store, Apply and Choose Yours \u0026 Why I Keep My Scent a Secret

🟡 Perhaps It’s Time To Join Them! (Improve Your Photography WITHOUT Photoshop)


Can’t make photos like your idols? There is a solution (Not editing) Photography motivation video
▶️ WATCH NEXT: All Film Camera Reviews https://bit.ly/3eBvxq7
Trying to understand how to improve your photography? Photography inspiration video explaining how to take better photos and how to enjoy photography more. It’s the same as asking how to improve my photography without photoshop. If the subjects look nice already you don’t need to edit too much.
🚀 LEICA PHOTOGRAPHY WORKSHOPS https://mrleica.com/leicaworkshopsuk/
📝 BLOG: https://mrleica.com/freenewsletter/
☕️ COFFEE: Thank Matt with a coffee https://www.paypal.com/paypalme/MrLeica
⭐️ PATREON: Join us today for more! From £1/mth https://www.patreon.com/mrleicacom
✅ CHECK prices on eBay: (US) https://ebay.to/2F0HoxY (UK) https://ebay.to/3ijzle2 (DE) https://ebay.to/3iqDNYs (FR) https://ebay.to/2ZJ3E75 (HK) https://ebay.to/32A8xBu
▶️ VIDEO PLAYLISTS
▪️Leica M Lenses (Series 1) https://bit.ly/38AOFjW
▪️Leica LTM Lenses (Series 2) https://bit.ly/3rLKtWr
▪️All Lens Reviews (All Mounts) https://bit.ly/3rN8fkR
▪️All Leica Reviews https://bit.ly/2ZAOpg7
▪️All Film Camera Reviews https://bit.ly/3eBvxq7
▪️Medium Format Cameras https://bit.ly/3vjvLrP
▪️Misc Videos (Film Reviews+More) https://bit.ly/3cwIVsP
🛎 SUBSCRIBED? Turn on notifications and see you in the next video! https://bit.ly/3qET0ZO
📷 Photography \u0026 Video Gear I use:
▪️Leica MR adapter (UK) https://amzn.to/3kojQnF (US) https://amzn.to/3DhEOgC
▪️Leica LM adapter (cheaper) (UK) https://amzn.to/387Enau (US) https://amzn.to/3yfUi1d
▪️Leica LM adapter 2 (UK) https://amzn.to/3gty59P (US) https://amzn.to/3gu5FfW
▪️Main Lightmeter (UK) https://amzn.to/3kfSd00 (US) https://amzn.to/2Wg4vxO
▪️Memory Cards (UK) https://amzn.to/3gu3Uzm (US) https://amzn.to/3mvcxNG
▪️Hard Drive (UK) https://amzn.to/3sWhoZP (US) https://amzn.to/3BbsPzI
▪️Film Scanner (UK) https://amzn.to/2YU29Wl (US) https://amzn.to/3zbn4Ra
▪️Main Video Camera (UK) https://amzn.to/2WicsSA (US) https://amzn.to/387obpK
▪️Main Tripod (UK) https://amzn.to/2UKcPF3 (US) https://amzn.to/3ypaP33
▪️Wireless Mic Kit (UK) https://amzn.to/388Xv83 (US) https://amzn.to/3jdvu5B
▪️Main Photo Camera (UK) https://amzn.to/2xPGlh6 / (US) https://amzn.to/36GfmS1
▪️Mini Speedlight (UK) https://amzn.to/2Nhx9sC / (US) https://amzn.to/2MJe7pG
▪️Big Speedlight (UK) https://amzn.to/2MJe7pG / (US) https://amzn.to/2HCQP5D
▪️Studio LED Light (UK) https://amzn.to/3B79BLf (US) https://amzn.to/3mtpI1L
▪️Travel LED Video Light (UK) https://amzn.to/2VUQotz / (US) https://amzn.to/3cFfsv7
▪️Main Camera Backpack (UK) https://amzn.to/2PF9AJc / (US) https://amzn.to/3amS58n
▪️Active Camera Backpack (UK) https://amzn.to/3eCMSwe / (US) https://amzn.to/2OE6EeK
▪️Walkabout Camera Bag (UK) https://amzn.to/34ZqXLx / (US) https://amzn.to/2VRHVqP
👤 Where to find me:
▪️Flickr: http://www.flickr.com/photos/32681588@N03/
▪️Facebook: https://www.facebook.com/matthewosbornephotographycouk
▪️Instagram: (Fashion) http://instagram.com/MrLeicaCom
▪️Instagram: (Weddings) http://instagram.com/MrLeicaWedding
▪️Wedding Blog: http://leicaweddingphotographer.co.uk/
▪️Website: http://www.matthewosbornephotography.co.uk
➡️ INSURANCE Aaduki UK Photography Insurance with since 2014 https://www.aaduki.com
DISCLAIMER: This description may contain affiliate links. If you purchase an item via clicking a link I will receive a small commission at no additional cost to you. Thanks for your support. Matt
improveyourphotography photographyinspiration photography mrleicacom mattosborne

🟡 Perhaps It’s Time To Join Them!   (Improve Your Photography WITHOUT Photoshop)

maybe perhaps probably ใช้ต่างกันยังไง?


Vanilla English EP.264 maybe perhaps probably ใช้ต่างกันยังไง?
ชอบกดไลค์ ใช่กดแชร์ และอย่าลืม subscribe กดกระดิ่งเป็นกำลังใจให้กี๋ด้วยนะค้าาาา แล้วเจอกันคลิปต่อๆไป เย้ๆ เจอกันค่าาาาา
LINE: https://lin.ee/A5RQK7z
Apple Podcast: Vanillaenglishchannel
SoundCloud: https://soundcloud.com/vanillaenglish357145867
Facebook: https://www.facebook.com/vanillaenglishchannel
Instagram: https://www.instagram.com/vanillaenglishchannel
Twitter: https://twitter.com/ChannelVanilla
Vanilla English Channel มาพร้อมกับสาระน่ารู้เกี่ยวกับภาษาอังกฤษ เรียนอังกฤษแบบชิลๆหนุกๆ กลมกล่อมหอมหวานเหมือนวานิลลาไปกับกี๋ ผู้ใช้ภาษาอังกฤษ รับความรู้ภาษาอังกฤษ และถ่ายทอดภาษาอังกฤษมานานกว่า 20 ปี
CAMERA: PANASONIC LUMIX GH5
LENS: PANASONIC LUMIX G 1235 f2.8
EDITING PROGRAMME: Davinci Resolve \u0026 Final Cut Pro X

maybe perhaps probably ใช้ต่างกันยังไง?

Probably, Possibly, Maybe, Perhaps แปลเหมือนกัน แต่ต่างกันยังไง?


🚩หลังจากรู้ไปแล้วว่าใช้ต่างกันยังไง
เรามาพูดภาษาอังกฤษอย่างมีคลาสง่าย ๆ ด้วยการใช้คำว่า Probably และ Possibly!😊

Probably, Possibly, Maybe, Perhaps แปลเหมือนกัน แต่ต่างกันยังไง?

How To Turn Your Yearly Income Into Your Monthly Income – Bob Proctor [ The Law of Compensation ]


Bob Proctor teaches How Money is Earned, The Law of Compensation, and explains the difference between the Three IncomeEarning Strategies: M1, M2, and M3. FREE Download! You Were Born Rich eBook!: http://bit.ly/2qluzU6
Imagine making money without working for it.
Sound impossible, unless you’re investing it?
Well, it’s not.
Thousands of people are making twice as much money without working twice as long. In fact, relatively speaking, they’re hardly working more at all.
How are they doing it? Through Multiple Sources of Income (MSI).
MSI should be viewed as passive sources of income, not another job. Why? Because if you get a second or third job, you’ll have to trade your time for money, and eventually you’ll run out of time.
Virtually all wealthy people have several little “streams” of income coming in that eventually build into a “river” of wealth. I’ve been a huge proponent of MSI ever since I passed out on the street in the mid1960s from working too many jobs.
For more than half a century, Bob Proctor has been the foremost authority in the personal and professional development field. Bob Proctor has dedicated his adult life to helping a world of individuals realize and act on the greatness they already possess within themselves. He’s widely regarded as the grandfather of personal development, and when it comes to mastering the mind – he is simply the best.
After meeting Bob Proctor, Sandy Gallagher, an esteemed banking attorney, created Thinking into Results – the most powerful corporate transformational program of its kind. Sandy is now the CoFounder, President, and CEO of Proctor Gallagher Institute. A genius businesswoman and visioneering expert committed to improving the conscious awareness of the entire world, one individual at a time.
The good life’s expensive. \”There’s another way to live that doesn’t cost as much, \”but it isn’t any good.\” Well, a lot of what he said is true. Many years ago, a man gave me this book, Think and Grow Rich. I was flat broke. I had always been flat broke. I had never had any money. I was 26 years old, I had two months’ high school and no business experience. He said, \”Bob, you read this, do exactly what I tell you, \”you can have anything you want.\” Now, I really didn’t believe that, but I believed he believed it. And I said, all I want is some money. I figured if I had enough money, all my problems would go away. See, I was earning $4,000 a year, but I owed 6,000. If I had paid every cent I owned, or earned, in 18 months, I would have just broken even. So I really didn’t think I was going to be able to change that. Do you know that within a year, I was earning 15,000 a month. I went from 4,000 a year, to 15,000 a month, within a year. Now, I hadn’t got that much smarter. You don’t have to be very smart to earn money, but you do have to understand some basic rules, and that’s what I want to talk to you about.
1️⃣ Leave a comment below with your biggest takeaway from this video👇
2️⃣ Share this video with someone else who needs to hear this message today 🤟
3️⃣ Be the first to know when we release new videos 👍 http://goo.gl/VL0Smo
➡️ Join Bob Proctor for a FREE Online Event 👉 https://bit.ly/2L51BTb 👈
Subscribe for more!: http://goo.gl/VL0Smo
Check out our most popular video series!
1. Search for Meaning Series: https://goo.gl/ThkyCc
2. The Higher Side of You: https://goo.gl/kicjyI
3. Value from the Vault: https://goo.gl/7lCs0O
Social Media \u0026 Website:
https://www.facebook.com/OfficialBobProctor
https://twitter.com/bobproctorlive
https://www.pinterest.com/realbobproctor/
https://instagram.com/proctorgallagher
Website: http://goo.gl/kYTfZp

How To Turn Your Yearly Income Into Your Monthly Income  - Bob Proctor [ The Law of Compensation ]

นอกจากการดูบทความนี้แล้ว คุณยังสามารถดูข้อมูลที่เป็นประโยชน์อื่นๆ อีกมากมายที่เราให้ไว้ที่นี่: ดูบทความเพิ่มเติมในหมวดหมู่MAKE MONEY ONLINE

ขอบคุณที่รับชมกระทู้ครับ การใช้ perhaps

Leave a Reply

Your email address will not be published. Required fields are marked *