Hồi quy bội
Hồi quy bội giống như hồi quy tuyến tính, nhưng với nhiều hơn một giá trị độc lập, có nghĩa là chúng ta cố gắng dự đoán một giá trị dựa trên hai hoặc nhiều biến.two or more variables.
Hãy xem bộ dữ liệu bên dưới, nó chứa một số thông tin về xe hơi.
Xe hơi | Người mẫu | Âm lượng | Trọng lượng | CO2 |
Toyota | Aygo | 1000 | 790 | 99 |
Mitsubishi | Ngôi sao không gian | 1200 | 1160 | 95 |
Skoda | Citigo | 1000 | 929 | 95 |
Fiat | 500 | 900 | 865 | 90 |
MINI | Cooper | 1500 | 1140 | 105 |
Vw | Lên! | 1000 | 929 | 105 |
Skoda | Citigo | 1400 | 1109 | 90 |
Fiat | MINI | 1500 | 1365 | 92 |
Cooper | Vw | 1500 | 1112 | 98 |
Lên! | Fabia | 1600 | 1150 | 99 |
Mercedes | Một lớp học | 1100 | 980 | 99 |
Ford | Fiesta | 1300 | 990 | 101 |
Cooper | Vw | 1000 | 1112 | 99 |
Lên! | Fabia | 1600 | 1252 | 94 |
Mercedes | Một lớp học | 1600 | 1326 | 97 |
Ford | Fiesta | 1600 | 1330 | 97 |
Audi | 1 | 1600 | 1365 | 99 |
A1 | 3 | 2200 | 1280 | 104 |
Skoda | Citigo | 1600 | 1119 | 104 |
Cooper | Vw | 2000 | 1328 | 105 |
Cooper | Vw | 1600 | 1584 | 94 |
Ford | Fiesta | 2000 | 1428 | 99 |
Fiat | MINI | 2100 | 1365 | 99 |
Skoda | Citigo | 1600 | 1415 | 99 |
Fiat | MINI | 2000 | 1415 | 99 |
Fiat | MINI | 1500 | 1465 | 102 |
Lên! | Fabia | 2000 | 1490 | 104 |
Lên! | Fabia | 2000 | 1725 | 114 |
Fiat | MINI | 1600 | 1523 | 109 |
Audi | 5 | 2000 | 1705 | 114 |
Fiat | MINI | 2100 | 1605 | 115 |
Fiat | MINI | 2000 | 1746 | 117 |
Cooper | Vw | 1600 | 1235 | 104 |
Audi | 2 | 1600 | 1390 | 108 |
Ford | Fiesta | 1600 | 1405 | 109 |
Fiat | MINI | 2500 | 1395 | 120 |
Cooper
Vw
Lên!
import pandas
Fabia
Mercedes
Một lớp học
df = pandas.read_csv["data.csv"]
Ford
Fiesta
X = df[['Weight', 'Volume']]
y = df['CO2']
Audi It is common to name the list of independent values with a upper case X, and the list of dependent values with a lower case y.
A1
from sklearn import linear_model
Hyundai
I20
regr = linear_model.LinearRegression[]
regr.fit[X, y]
Suzuki
#predict the CO2 emission of a car where the weight
is 2300kg, and the volume is 1300cm3:
predictedCO2 = regr.predict[[[2300, 1300]]]
Nhanh
Honda
Công dân
from sklearn import linear_model
Hundai
I30
y = df['CO2']
Opel
regr.fit[X, y]
Astra
predictedCO2 = regr.predict[[[2300, 1300]]]
xe BMW
Result:
Mazda
Nhanh
Tiêu điểm
Mondeo
Phù hiệu
C-Class
Nhanh
Honda
Công dân
from sklearn import linear_model
Hundai
I30
y = df['CO2']
Opel
regr.fit[X, y]
print[regr.coef_]
Result:
Mazda
Nhanh
Tiêu điểm
Mondeo
Volume: 0.00780526
Phù hiệu
C-Class
Octavia
Volvo
S60
Nhanh
Honda
Công dân
from sklearn import linear_model
Hundai
I30
y = df['CO2']
Opel
regr.fit[X, y]
PRESICTIONCO2 = regr.predict [[[3300, 1300]]]]
In [PrevictionCo2]
Result:
Chạy ví dụ »
Chúng tôi đã dự đoán rằng một chiếc xe có động cơ 1,3 lít và trọng lượng 3300 kg, sẽ giải phóng khoảng 115 gram CO2 cho mỗi km mà nó lái.
Trong đó cho thấy hệ số 0,00755095 là chính xác:
107.2087328 + [1000 * 0,00755095] = 114.75968