Linear regression with two features can be described by the following equation:
y = a1x1 + a2x2 + intercept
Fitting multiple linear regression will solve for the coefficients a1, and a2. Consider the following code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model
file = 'https://aegis4048.github.io/downloads/notebooks/sample_data/unconv_MV_v5.csv'
df = pd.read_csv(file)[['Por', 'Perm', 'Prod']]
features = df[['Por', 'Perm']].values.reshape(-1,2)
target = df['Prod']
ols = linear_model.LinearRegression()
model = ols.fit(features, target)
predicted = model.predict(features)
coef = model.coef_
pd.DataFrame(coef, index=['Por', 'Perm'], columns=['Regression Coef']).round(2)
>>> Regression Coef
Por 244.47
Perm 97.75
The two features are Por and Perm. I want to fix the values of the regression coefficient of Perm to some fixed value, and solve only for the coefficient of Por. How can I do this in Python?