So I'm doing some exercises to prepare for a interview test. However there's one of the assignments I don't understand. Maybe some of you can explain what they want me to do? It would help me to understand the underlying questionframes I may come across.
This is the assignment:
Logit Regression Have the function LogitRegression(arr) read the input array of 4 numbers x, y, a, b, separated by space, and return an output of two numbers for updated a and b (assume the learning rate is 1). Save up to 3 digits after the decimal points for a and b. The output should be a string in the format: a, b
def LogitRegression(arr): # code goes here return arr # keep this function call here print(LogitRegression(input()))
Logistic regression is a simple approach to do classification, and the same formula is also commonly used as the output layer in neural networks.
We assume both the input and output variables are scalars, and the logistic regression can be written as:
y = 1.0 / (1.0 + exp(-ax - b))
After observing a data example (x, y), the parameter a and b can be updated using gradient descent with a learning rate. Examples:
Input: [1, 1, 1, 1]
Output: 0.881, 0.881
Input: [2.2, 0.0, 5.1, 5.7]
Output: 7.3, 6.7
What I don't understand is, do they only give me 4 scalars and want me to train on x, y and then predict a and b. Or is a and be supposed to be weights and bias and I need to return the trained ones? The output numbers in the second example doesn't match probabilities so it can't be that. I might be overthinking this and it's just a simple thing I need to do?
This is the code I've tried:
arr = np.array([2.2, 0.0, 5.1, 5.7]) arr2 = np.array([1.0, 1.0, 1.0,1.0]) def Logit(arr): learnrate = 1 X = arr y = arr weights = arr bias = arr y_hat = 1/(1+np.exp(np.dot(X, -weights) - bias)) new_weights = weights + learnrate * (y - y_hat) * X new_bias = bias + learnrate*(y - y_hat) print(new_weights, new_bias) Logit(arr)