I'm trying to find the code to find the value of 'y' to a respective 'x' value by using a plotted line graph. I've used matplotlib.pyplot to plot a graph. The 'x' value for which I want the 'y' value is not a part of the x values array. Is there a way to find the respective 'y' value for the same?
If I have to find the value of Y for X = 0.75, how do I do that?
We can use the interp function from numpy library.
import numpy as np
x = [0.01474926, 0.96923077, 1]
y = [1, 0.7875, 0]
np.interp(0.75, x,y)
0.8363082148652623
the practical way to the y-value is using np.interp
function which is also mentioned. I think the plot in the question belongs to roc_curve of LogisticRegression. So, it will be more practical to use the (precision_score, recall_score) instead of (x,y).
recall=np.interp (0.75, precision_score, recall_score)
Note: This is the 5th question of Week-3 Assignment of "Applied Machine Learning in Python by University of Michigan" Coursera Course.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With