Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[PYTHON] Your first task is to complete the function gen_logistic in the following cell so as to be able to generate the logistic function for

[PYTHON] Your first task is to complete the function gen_logistic in the following cell so as to be able to generate the logistic function for a given input. The logistic function is a type of sigmoid function which has an 'S'-shape and 'squashes' its inputs to a value lying in the range [0,1].

def gen_logistic(x, w=1, b=0): """ outputing the logistic output for an input x :param x: scalar or numpy array of shape (n_samples, n_features). If only one feature, it must have the shape of (n_samples,1). :param w: weight(s); either scalar or numpy array of shape (1, n_features) :param b: bias; either scalar or numpy array of shape (1,) returns y of shape (n_samples,) """ # TODO: Finish this function to return the output of applying the sigmoid # function to the input x (Please do not use external libraries) store # the output in y and return y. Do not change the default parameter values. # Hint: This function will be used in any input shape scalar (0d), 1d vector, and 2d arrays. Please make sure it can handle all those. Following reshaping codes might help. # Hint2: You may use design matrix using concatenation, but it is not necesary. y =0 if np.isscalar(x): x = np.array(x).reshape((1,1)) if np.isscalar(w): w = np.array(w).reshape((1,1)) if np.isscalar(b): b = np.array(b).reshape((1,1)) if b.shape==(1,): b= b.reshape((1,1))

# your code here

print(y.reshape(y.shape[0],))

return y.reshape(y.shape[0],)

OBS: the code found here on chegg for this question earlier doesn't work.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions