i think the introduction of an x0 for bias should be a multiply
so not
x 0 + b
but
x 0 * b
i think the introduction of an x0 for bias should be a multiply
so not
x 0 + b
but
x 0 * b
Hi @Andrew_Forward !!
In linear regression, the bias term (intercept) is typically added as a separate feature with a fixed value of 1. It is not multiplied by a weight.The correct equation for linear regression with a bias term is:
y = x1 * w1 + x2 * w2 + x3 * w3 + x0 * b
Here, x0 is a feature that is always set to 1, and b represents the weight (or coefficient) for the bias term.
In the given code snippet, np.ones(x1.size)
is used to create a column of ones to represent the bias term in the design matrix X
. Multiplying np.ones(x1.size)
by b
would result in incorrect calculations.
To clarify, the code provided below is correct:
x1, x2, x3, y = np.loadtxt("pizza_3_vars.txt", skiprows=1, unpack=True)
X = np.column_stack((np.ones(x1.size), x1, x2, x3))
Y = y.reshape(-1, 1)
w = train(X, Y, iterations=100000, lr=0.001)
print("\nWeights: %s" % w.T)
print("\nA few predictions:")
for i in range(5):
print("X[%d] -> %.4f (label: %d)" % (i, predict(X[i], w), Y[i]))
Here, the bias term is added as the first column of X
with np.ones(x1.size)
, and no multiplication is needed.
I hope it helps. Happy Learning
Agreed.
See how b is multiplied by x0 (as a fake “variable” that is always 1).
In the course, it is added x0 + 1. That is what I believe is a mistake.
Hi @Andrew_Forward, you are right, there’s a typo in this equation. It’ll be fixed shortly.
Thanks for pointing this out.