Im working on a linear regression coding problem and i get this error on trying to code the feature matrix part. can you please help me correct this ?
Traceback (most recent call last): File "C:\Users\visha\AppData\Local\Continuum\anaconda3\lib\site-packages\nose\case.py", line 197, in runTest self.test(*self.arg) File "C:\Users\visha\machinelearning\test.py", line 22, in test_compute_Phi Phi = compute_Phi(x,2) File "C:\Users\visha\machinelearning\linear_regression.py", line 30, in compute_Phi Phi[:,i] = np.power(x,i).reshape(x.shape[0],) ValueError: could not broadcast input array from shape (1,3) into shape (3,1)
[code]
def compute_Phi(x,p):
x = np.asmatrix(x)
Phi = np.zeros(shape = (x.shape[0],p))
for i in range(0,p):
Phi[:,i] = np.power(x,i).reshape(x.shape[0],)
Phi = np.asmatrix(Phi)
return Phi
np.asarray(x). AvoidasmatrixPhias 2dndarray. Why did you pass it throughnp.matrixin the loop?np.matrixbehave differently when indexed. That produces confusion, which is part of why their use in new code is discouraged.