0

im trying to create a custom scoring function but I am having trouble with the last line.

def scorer(y_true, y_pred):
    y_pred1 = shift(y_pred,1)
    y_pred2 = shift(y_pred,2)
    target = y_pred - y_true
    action = np.where(target > 0, 1, 0)
    diff = y_pred2 - y_pred1
    score = (action == 1).sum(diff)

My output is supposed to be the sum of the diff rows when the action is equal to 1 for that row.

Diff Action
1.28 1
2.56 0
.64 1
.32 0
5.12 0

For example, in this case it would be 1.28+.64=1.92

2
  • needs a stackoverflow.com/help/minimal-reproducible-example in particular, what is the output you see currently and what is the output you expect? Commented Apr 10, 2022 at 20:54
  • something along diff[action==1].sum() Commented Apr 10, 2022 at 21:01

1 Answer 1

1

You can put the diff directly into the np.where:

action = np.where(target > 0, y_pred2 - y_pred1, 0)     

then sum action, via

sum(action)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.