All problems

The Logistic Regression Gradient

mediumPythonLogistic Regression

To train the late-delivery model, Kestrel Freight's trainer needs to know which way each dial should move. For one job it has the outcome, the probability the model gave, and the numbers describing that job, and it wants the steepness of that job's log loss with respect to each weight and with respect to the starting amount — how fast the charge for this prediction changes as each dial is nudged. Nothing is averaged here and no step is taken: this is one job's contribution, reported dial by dial, and the trainer combines and applies them elsewhere.

Task: Print the steepness of this job's charge for every weight, then for the starting amount.

Input

The first line holds two numbers separated by a single space: the true outcome, 1 if the delivery was late and 0 if it was not, and the probability of lateness the model gave. The second line holds one integer n, how many numbers describe the job, where 1 <= n <= 50. The third line holds those n numbers separated by single spaces, in weight order.

Output

n + 1 lines. First one line per weight, in order: dw_, the weight's number counting from 1, a single space, and that weight's steepness rounded to 4 decimal places. Then a final line: db, a single space, and the starting amount's steepness rounded to 4 decimal places.

Example:

Input:
1 0.8
2
1 2

Output:
dw_1 -0.2000
dw_2 -0.4000
db -0.2000

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…