Question
Need help finding out what to code for the mini-batch gradient Descent function. PYTHON CODE Update: Is there any other information required to receive help
Need help finding out what to code for the mini-batch gradient Descent function. PYTHON CODE
Update: Is there any other information required to receive help for this question?
X = x_train.iloc[:, :] y = np.array(pd.DataFrame(y_train.values)) #.values converts it from pandas.core.frame.DataFrame to numpy.ndarray theta = np.zeros([1, X.shape[1]]) print(X.shape, y.shape, theta.shape)
# Let's define a cost function... def cal_cost(theta, X, y): ''' Calculates the cost for given X and Y. The following shows and example of a single dimensional X theta = Vector of thetas
''' m = len(y) predictions = X.dot(theta) cost = (1/2*m) * np.sum(np.square(predictions-y)) return cost
def minibatch_gradient_descent(X,y,theta,learning_rate=0.01,iterations = 10,batch_size =50): ''' X = Matrix of X without added bias units y = Vector of Y TO DO: Return the final theta vector and array of cost history over iterations '''
cost_history = np.zeros(iterations)
""" TO DO: Implement code for Minibatch Gradient Descent """
return theta, cost_history
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started