Why is x being reshaped using (-1,1) when y is of shape (1)?

this is week 2’s optional lab of feature engineering
pseudo code-

create target data

x = np.arange(0, 20, 1)
y = 1 + x**2

Engineer features

X = x**2 #<-- added engineered feature

X = X.reshape(-1, 1) x should be a 2-D Matrix
model_w,model_b = run_gradient_descent_feng(X, y, iterations=10000, alpha = 1e-5)

plt.scatter(x, y, marker=‘x’, c=‘r’, label=“Actual Value”); plt.title(“Added x**2 feature”)
plt.plot(x, np.dot(X,model_w) + model_b, label=“Predicted Value”); plt.xlabel(“x”); plt.ylabel(“y”); plt.legend();

why is reshaping being done here when both y and x are already of same dimensions?

What thos reshape function is doing is just creating a column vector instead of a line vector. I think this arangement is needed further on when ploting them.

1 Like

Adding to @gent.spah

basically reshaping helps to be 2D-array (no. of samples, number of features) allowing plotting of regression analyses between actual and predicted values

1 Like