![]() ![]() ![]() # Define the inputs and targets X = D_transformed y = D # Define the mean squared error (MSE) function def mse(X, y, w): m = len(y) y_pred = np.apply_along_axis(lambda x: hw(x, w), 1, X) return (1/m) * np.sum((y_pred - y)**2) # Define the hypothesis function hw(x) def hw(x, w): return np.dot(w, x) To find the weight vector w that minimizes the MSE loss function, we can solve the normal equations: In general, however, pseudoinversion is a more general term that applies to non-square matrices. Note that if A is a square matrix and has an inverse matrix, then A⁺ = A⁻¹. Specifically, if we have a system of linear equations of the form Ax = b, where A is a non-square matrix and b is a vector, we can use pseudoinversion to find the solution for x: Pseudoinversion has a number of useful properties, for example it allows us to solve overdetermined systems of linear equations (ie when there are more equations than unknowns). Where Aᵀ is the transpose of A and (AᵀA)⁻¹ is the inversion of AᵀA if it exists. The Moore–Penrose inversion (also known as the pseudoinversion) is a generalization of the matrix inverse for non-square matrices. Which takes an input example x and a weight vector w as inputs and returns the dot product of the weight vector and the transformed input example x. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |