F1 Score by Precision and Recall

F1 score, Precision and Recall

Importing relevant libraries and packages

					import warnings
import numpy as np
import matplotlib.pyplot as plt


Defining a function to calculate F1 score based on precision and recall values

					def f1_score(precision, recall):
    score = 2*precision*recall / (precision + recall)
    score = np.nan_to_num(score)

    return score


Plotting F1 score for different values of precision and recall

					x = np.linspace(0, 1, 101)
y = np.linspace(0, 1, 101)
X, Y = np.meshgrid(x, y)
Z = f1_score(X, Y)
fig = plt.figure()
fig.set_size_inches(10, 10)
ax = plt.axes(projection='3d')
ax.plot_surface(X, Y, Z, rstride=2, cstride=3, cmap='plasma')

ax.set_title('$F_{1}$ of precision, recall', size=18)
ax.view_init(35, -65)