How to Get Coefficient Values of Regression Object in Python


In this example we will show how to get the coefficient values of the regression object in Python.

Source Code

import pandas as pd
from sklearn import linear_model

df = pd.read_csv("advertising.csv")

X = df[["TV", "radio", "newspaper"]]
y = df["sales"]

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

print(reg.coef_)

Output:

[ 0.04576465  0.18853002 -0.00103749]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments