Multiple Linear Regression
Multiple Linear Regression
Out[2]:
Driving Assignmnet miles_travelled n_of_deliveries travel_time
0 1 100 4 9.3
1 2 50 3 4.8
2 3 100 4 8.9
3 4 100 2 6.5
4 5 50 2 4.2
5 6 80 2 6.2
6 7 75 3 7.4
7 8 65 4 6.0
8 9 90 3 7.6
9 10 90 2 6.1
In [3]: 1 # plot a graph between any input attribute and output label
2 import matplotlib.pyplot as plt
3 plt.scatter(data['miles_travelled'], data['travel_time'])
4 plt.ylabel = ('travel time')
5 plt.title('trend between indenpendent and dependent variable')
6 plt.show()
In [4]: 1 #Extract the input features in X and the output label in Y
2 X = data[['miles_travelled', 'n_of_deliveries']]
3 Y = data['travel_time']
4 print(X)
5 print(Y)
miles_travelled n_of_deliveries
0 100 4
1 50 3
2 100 4
3 100 2
4 50 2
5 80 2
6 75 3
7 65 4
8 90 3
9 90 2
0 9.3
1 4.8
2 8.9
3 6.5
4 4.2
5 6.2
6 7.4
7 6.0
8 7.6
9 6.1
Name: travel_time, dtype: float64
What is sklearn Scikit-learn (Sklearn) is the most useful and robust library for machine
learning in Python. It provides a selection of efficient tools for machine learning and
statistical modeling including classification, regression, clustering and dimensionality
reduction via a consistence interface in Python.
The next step is to create a linear regression model and fit it using the existing data. With
.fit(), you calculate the optimal values of the weights 𝑏₀ and 𝑏₁, using the existing input and
output (x and y) as the arguments. In other words, .fit() fits the model.
Let’s create an instance of the class LinearRegression, which will represent the regression
model:
Out[8]: LinearRegression()
Out[9]: -1.3154407102092618
In [10]: 1 # find slope for 2 independent variables
2 regr.coef_
Out[12]:
Actual value predicted values
2 8.9 9.04740
4 4.2 3.86598
[16.4753012]
The sklearn. metrics module implements several loss, score, and utility functions to measure
classification performance. Some metrics might require probability estimates of the positive
class, confidence values, or binary decisions values.
Out[14]: 0.06664817632509885
Out[15]: 0.9879315208103036
In [ ]: 1