asg12

.docx

School

Arizona State University *

*We aren’t endorsed by this school

Course

512

Subject

Mechanical Engineering

Date

Jan 9, 2024

Type

docx

Pages

5

Uploaded by BaronSteelOyster29 on coursehero.com

Name: Rishabh Singh Assignment Name: Assignment 12.1 - Logistic Regression Calculations
Screenshots: Code: import numpy as np
#define the sigmoid function def sigmoid(z): return 1/(1+np.exp(-z)) #define the loiss function for logistic regression def loss(a,y): return -(y*np.log(a)+(1-y)*np.log(1-a)) #calculate the cost function J(w,b) to measure how well them model is performing def j_cost_fn(predictions,labels): return np.mean([loss(a,y) for a, y in zip(predictions,labels)]) #calculate the gradient of J with respect to w def calculate_dw(a,y,x): return (a-y)*x #cacucalte the average gradient of J with respect to W def avg_dw(predictions,labels,inputs): return np.mean([calculate_dw(a,y,x) for a,y,x in zip(predictions,labels,inputs)]) #calculate the gradient of J with respect to b def calculate_db(a,y): return a-y #calculate the average gradient of J with respcet to b def avg_db(predictions,labels): return np.mean([calculate_db(a,y) for a ,y in zip(predictions,labels)]) #calculate descent function to update the model parameters (w and b) def gradient_descent(X,y,w,b,alpha,num_iterations): for i in range(num_iterations):
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help