สมัครเรียนโทร. 085-350-7540 , 084-88-00-255 , ntprintf@gmail.com

AI / Machine Learning

Machine Learning Machine Learning - Mean Median Mode Machine Learning - Standard Deviation Machine Learning - Percentiles Machine Learning - Data Distribution Machine Learning - Normal Data Distribution Machine Learning - Scatter Plot Machine Learning - Linear Regression Machine Learning - Multiple Regression Machine Learning - Polynomial Regression Machine Learning - Scale Machine Learning - Train/Test Machine Learning - Decision Tree The brief history of artificial intelligence - ประวัติศาสตร์ AI ฉบับย่อ Jupyter Notebook on AWS Pandas Tutorials ตรวจจับตำแหน่งของมือจากกล้องเว็บแคมแบบเรียลไทม์ด้วย Python ง่าย ๆ ใน 2 นาที ตรวจจับวัตถุด้วย Python ใน 5 Steps ใช้ AI แบ่งส่วนภาพคนกับฉากหลังแบบง่าย ๆ แป๊บเดียวเสร็จ ใช้ AI บอกท่าทางคนด้วย Code เพียง 15 บรรทัด สร้างแอนิเมชันจากตัวการ์ตูนที่เราวาดเองด้วย Code 2 บรรทัด สร้างไฟล์ท่าเต้นสุดคิวท์ให้ตัวการ์ตูนเต้นตามใน 1 คำสั่ง Artificial Intelligence (AI) Machine Learning 8 Fun Machine Learning ProjectsFor Beginner การหาค่าเหมาะที่สุด (Optimization) Mathematical Optimization Top 20 Python Machine Learning Open Source Projects Introduction to Neural Networks Introduction to Deep Learning with TensorFlow Installing TensorFlow for Deep Learning - OPTIONAL Deep Learning with TensorFlow - Creating the Neural Network Model Deep Learning with TensorFlow - How the Network will run

Machine Learning - Multiple Regression

เรียนเขียนโปรแกรมง่ายๆกับ Expert Programming Tutor ในบท Machine Learning - Multiple Regression 
วันนี้เราจะเรียนรู้เกี่ยวกับการถดถอยหลายครั้งเป็นเหมือนการถดถอยเชิงเส้น แต่มีค่าอิสระมากกว่าหนึ่งค่าซึ่งหมายความว่าเราพยายามทำนายค่าตามตัวแปรสองตัวหรือมากกว่า ลองดูที่ชุดข้อมูลด้านล่างมันมีข้อมูลบางอย่างเกี่ยวกับรถยนต์

Toyota

Aygo

1000

790

99

Mitsubishi

Space Star

1200

1160

95

Skoda

Citigo

1000

929

95

Fiat

500

900

865

90

Mini

Cooper

1500

1140

105

VW

Up!

1000

929

105

Skoda

Fabia

1400

1109

90

Mercedes

A-Class

1500

1365

92

Ford

Fiesta

1500

1112

98

Audi

A1

1600

1150

99

Hyundai

I20

1100

980

99

Suzuki

Swift

1300

990

101

Ford

Fiesta

1000

1112

99

Honda

Civic

1600

1252

94

Hundai

I30

1600

1326

97

Opel

Astra

1600

1330

97

BMW

1

1600

1365

99

Mazda

3

2200

1280

104

Skoda

Rapid

1600

1119

104

Ford

Focus

2000

1328

105

Ford

Mondeo

1600

1584

94

Opel

Insignia

2000

1428

99

Mercedes

C-Class

2100

1365

99

Skoda

Octavia

1600

1415

99

Volvo

S60

2000

1415

99

Mercedes

CLA

1500

1465

102

Audi

A4

2000

1490

104

Audi

A6

2000

1725

114

Volvo

V70

1600

1523

109

BMW

5

2000

1705

114

Mercedes

E-Class

2100

1605

115

Volvo

XC70

2000

1746

117

Ford

B-Max

1600

1235

104

BMW

2

1600

1390

108

Opel

Zafira

1600

1405

109

Mercedes

SLK

2500

1395

120

เราสามารถทำนายการปล่อย CO2 ของรถยนต์ตามขนาดของเครื่องยนต์ แต่ด้วยการถดถอยหลายครั้งเราสามารถโยนตัวแปรเพิ่มเติมเช่นน้ำหนักของรถเพื่อให้การทำนายแม่นยำยิ่งขึ้น
มันทำงานยังไง?
ใน Python เรามีโมดูลที่จะทำงานให้เรา เริ่มต้นด้วยการ import โมดูล Pandas

import pandas

โมดูล Pandas ช่วยให้เราสามารถอ่านไฟล์ csv และส่งคืนวัตถุ DataFrame ไฟล์นี้มีวัตถุประสงค์เพื่อการทดสอบเท่านั้นนักเรียนสามารถดาวน์โหลดได้ที่นี่ : cars.csv

df = pandas.read_csv("cars.csv")

จากนั้นทำรายการค่าอิสระและเรียกใช้ตัวแปร X นี้
ใส่ค่าที่สัมพันธ์กันในตัวแปรที่เรียกว่า y

X = df[['Weight', 'Volume']]
y = df['CO2']

คำแนะนำ: เป็นเรื่องปกติที่จะตั้งชื่อรายการของค่าอิสระด้วยตัวพิมพ์ใหญ่ X และรายการค่าที่ขึ้นต่อกันด้วยตัวพิมพ์เล็ก y
เราจะใช้วิธีการบางอย่างจากโมดูล sklearn ดังนั้นเราจะต้องimport โมดูลนั้นด้วย จากโมดูล sklearn เราจะใช้วิธีการ LinearRegression () เพื่อสร้างวัตถุการถดถอยเชิงเส้น วัตถุนี้มีวิธีการที่เรียกว่า fit () ที่ใช้ค่าที่เป็นอิสระและขึ้นอยู่กับพารามิเตอร์และเติมวัตถุการถดถอยด้วยข้อมูลที่อธิบายถึงความสัมพันธ์

regr = linear_model.LinearRegression()
regr.fit(X, y)

ตอนนี้เรามีวัตถุถดถอยที่พร้อมจะคาดการณ์ค่า CO2 ตามน้ำหนักและปริมาตรของรถ

#predict the CO2 emission of a car where the weight is 2300kg, and the volume is 1300ccm:
predictedCO2 = regr.predict([[2300, 1300]])

เราคาดการณ์ว่ารถยนต์ที่มีเครื่องยนต์ 1.3 ลิตรและน้ำหนัก 2,300 กิโลกรัมจะปล่อย CO2 ประมาณ 107 กรัมทุก ๆ กิโลเมตร
ตัวอย่าง
ดูตัวอย่างการทำงานทั้งหมด

import pandas
from sklearn import linear_model
df = pandas.read_csv("cars.csv")
X = df[['Weight', 'Volume']]
y = df['CO2']
regr = linear_model.LinearRegression()
regr.fit(X, y)
#predict the CO2 emission of a car where the weight is 2300kg, and the volume is 1300ccm:
predictedCO2 = regr.predict([[2300, 1300]])
print(predictedCO2)

ผลลัพธ์

[107.2087328]

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

import pandas
from sklearn import linear_model
df = pandas.read_csv("cars.csv")
X = df[['Weight', 'Volume']]
y = df['CO2']
regr = linear_model.LinearRegression()
regr.fit(X, y)
print(regr.coef_)

ผลลัพธ์

[0.00755095 0.00780526]

อธิบายผล
อาร์เรย์ผลลัพธ์แสดงค่าสัมประสิทธิ์ของน้ำหนักและปริมาตร
น้ำหนัก: 0.00755095
ปริมาณ: 0.00780526
ค่าเหล่านี้บอกเราว่าหากน้ำหนักเพิ่มขึ้น 1 กรัมการปล่อย CO2 จะเพิ่มขึ้น 0.00755095g และหากขนาดเครื่องยนต์ (ปริมาตร) เพิ่มขึ้น 1 ccm การปล่อย CO2 จะเพิ่มขึ้น 0.00780526 g
ผมคิดว่านั่นเป็นการเดาที่ยุติธรรม แต่ลองทดสอบดูสิ!
เราคาดการณ์ไว้แล้วว่าหากรถยนต์ที่มีเครื่องยนต์ขนาด 1300 ซีซีเอ็มน้ำหนัก 2300 กก. การปล่อย CO2 จะอยู่ที่ประมาณ 107 กรัม จะเป็นอย่างไรถ้าเราเพิ่มน้ำหนัก 1,000 กิโลกรัม?
ตัวอย่าง
คัดลอกโค้ดจากตัวอย่างก่อนหน้านี้ แต่เปลี่ยนน้ำหนักจาก 2300 เป็น 3300

import pandas
from sklearn import linear_model
df = pandas.read_csv("cars.csv")
X = df[['Weight', 'Volume']]
y = df['CO2']
regr = linear_model.LinearRegression()
regr.fit(X, y)
predictedCO2 = regr.predict([[3300, 1300]])
print(predictedCO2)

ผลลัพธ์

[114.75968007]

เราคาดการณ์ว่ารถยนต์ที่มีเครื่องยนต์ 1.3 ลิตรและน้ำหนัก 3300 กิโลกรัมจะปล่อย CO2 ประมาณ 115 กรัมสำหรับทุก ๆ กิโลเมตรที่ขับ
ซึ่งแสดงว่าสัมประสิทธิ์ 0.00755095 นั้นถูกต้อง   
107.2087328 + (1000 * 0.00755095) = 114.75968
แปลจากhttps://www.w3schools.com/python/python_ml_multiple_regression.asp


Tag ที่น่าสนใจ: machine_learning multiple_regression programming_tutor data_prediction linear_regression data_analysis car_data regression_analysis programming python data_science statistical_model predictive_modeling data_visualization statistical_analysis


บทความนี้อาจจะมีที่ผิด กรุณาตรวจสอบก่อนใช้

หากมีข้อผิดพลาด/ต้องการพูดคุยเพิ่มเติมเกี่ยวกับบทความนี้ กรุณาแจ้งที่ http://m.me/Expert.Programming.Tutor

ไม่อยากอ่าน Tutorial อยากมาเรียนเลยทำอย่างไร?

สมัครเรียน ONLINE ได้ทันทีที่ https://elearn.expert-programming-tutor.com

หรือติดต่อ

085-350-7540 (DTAC)
084-88-00-255 (AIS)
026-111-618
หรือทาง EMAIL: NTPRINTF@GMAIL.COM

แผนที่ ที่ตั้งของอาคารของเรา

แผนผังการเรียนเขียนโปรแกรม

Link อื่นๆ

Allow sites to save and read cookie data.
Cookies are small pieces of data created by sites you visit. They make your online experience easier by saving browsing information. We use cookies to improve your experience on our website. By browsing this website, you agree to our use of cookies.

Copyright (c) 2013 expert-programming-tutor.com. All rights reserved. | 085-350-7540 | 084-88-00-255 | ntprintf@gmail.com

ติดต่อเราได้ที่

085-350-7540 (DTAC)
084-88-00-255 (AIS)
026-111-618
หรือทาง EMAIL: NTPRINTF@GMAIL.COM
แผนที่ ที่ตั้งของอาคารของเรา