Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 805
shellym Avatar asked Mar 25 '19 17:03

shellym


2 Answers

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
like image 130
Siong Thye Goh Avatar answered Oct 02 '22 06:10

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.

like image 21
msklc Avatar answered Oct 02 '22 07:10

msklc