
- Import Numpy As Np Import Pandas As Pd Data Pd Read Csv Hw4data Csv Def Getname Todo Add Your Full Name Instead 1 (53.75 KiB) Viewed 55 times

- Import Numpy As Np Import Pandas As Pd Data Pd Read Csv Hw4data Csv Def Getname Todo Add Your Full Name Instead 2 (107.3 KiB) Viewed 55 times
import numpy as np
import pandas as pd
data=pd.read_csv("HW4data.csv")
def getName():
#TODO: Add your full name instead of Lionel Messi
return "Lionel Messi"
def getStudentID():
#TODO: Replace X's with your student ID. It should stay as a string
and should have exactly 9 digits in it.
return "012345678"
def standardize(X):
return (X - X.mean())/X.std(), X.mean(), X.std()
#Define your functions here if necessary
def gradient_descent(data,num_iter,alpha,random_seed):
X=np.array(data['X'])
y=np.array(data['y'])
X,muX,sdX = standardize(X)
#Do not standardize y!!!!!
np.random.seed(random_seed)
#beta values are initialized here. Don't reinitialize beta values
again!!
beta0 = np.random.rand()
beta1 = np.random.rand()
J_list = []
#write your own code here
return J_list,beta0,beta1
PLEASE WRİTE PYTHON CODE!!
Your task: In this assignment, you will be fitting a logistic function using inputs x and outputs y, 1 1+e-(30+812) 1
where 30 and By are coefficients of the model. The error function of the logistic regression model is not sum of squared errors. When fitting logistic regression model, we seek minimizing cross-entropy given in the following form: n 1 1 J=- S [y en 17-wthorn) + (1 – 3. m(1-17-25) (e

] > y; In i=1 + 1 - y) In ( n +e-(+) Use gradient descent algorithm to minimize the cross cntropy and determine the cocfficients of logistic regression model 30 and 31. Recall that you are supposed to compute the gradients ago and as, J OJ Function Parameters: data: This is a dataframe containing x and y values. Be careful that you shouldn't read the csv file within the function, send the dataframe to the function. The data is uploaded to the ninova with a name "HW4.csv". The dataframe has two columns named 'x' and 'y. Columns of the dataframe arc then converted to numpy arrays in the function. Standardize only 'x' values not 'y' values! num_iter: Number of iterations. alpha: Step size random seed: Sced that is going to feed numpy's random module. Output: Your function should return a list of error values J that stores all error values through iterations, and the final Bo and B, values (only provide final coefficients) HINT: Please use the template uploaded to the ninova, read the comments in the tem- plate and strictly follow the intsructions. Do necessary testing of your function in a python file other than the python file your function is written.