Find y value for respective x from python plot (matplotlib)

Question:

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?

enter image description here

Asked By: shellym

||

Answers:

We can use the interp function from the 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
Answered By: Siong Thye Goh

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.

Answered By: msklc
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.