Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def initialize_weights(X):
- return np.random.rand(X.shape[1] + 1, 1)
- def insert_coeficient_to_weights_matrix(X):
- return np.insert(X, 0, 1, axis=1)
- def predict(new_X, B):
- return np.dot(new_X, B)
- def calculate_gradient(predictions, new_X, Y):
- return (1/new_X.shape[0]) * multiply_residual_by_features_matrix(predictions, new_X, Y)
- def calculate_residual(predictions, real_values):
- return np.subtract(predictions, real_values)
- def multiply_residual_by_features_matrix(predictions, new_X, Y):
- return np.dot(np.transpose(new_X), calculate_residual(predictions, Y))
- def update_weights(gradient_vector, weights):
- alfa = 0.0001
- new_weights = np.subtract(weights, (alfa * gradient_vector))
- return new_weights
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement