<jupyter_start><jupyter_text>Visualization of the Hinge loss function  Used mainly for Support Vector Machines (SVMs). If you want to find more information visit Wikipedia<jupyter_code>#importing matplotlib library for plotting our results
import matplotlib.pyplot as plt
%matplotlib inline
def hinge_loss(z, label):
    """
    Input:
    -> z - value for which we want to calculate hinge_loss()
    (In Machine Learning usually the product of feature vector and parameters)
    -> label - ground truth label of an example
    """
    if label:
        return max(0, 1-1*z)
    else:
        return max(0, 1+1*z)
#creating a list of hypothetical z values
Z = [i for i in range(-10,11)]
#setting label to 1, it can significantly change the outcome of the hinge_loss()
label = 1
#creating a list of hinge_loss() function's output performed on Z list
y1 = [hinge_loss(z, label) for z in Z]

plt.plot(Z,y1)
plt.show()
#setting label to 0, so that we can see the difference from label being equal to 1
label = 0
y2 = [hinge_loss(z, label) for z in Z]

plt.plot(Z,y2)
plt.show()
#displaying both plots on one plot
#red plot corresponds to label equal to 0
#green plot corresponds to label equal to 1
plt.plot(Z,y1,'g')
plt.plot(Z,y2,'r')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09033778476040849, 'fraction_numerical': 0.018067556952081697, 'mean_word_length': 4.055555555555555, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '495034', 'license': 'MIT', 'n_tokens_mistral': 435, 'n_tokens_neox': 407, 'n_words': 175, 'path': 'Hinge_loss.ipynb', 'repo_name': 'olafplacha/Hinge-Loss-Function', 'size': '1273'}