<jupyter_start><jupyter_text><jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text><jupyter_code>def hinge_loss_single(feature_vector, label, theta, theta_0):
    """
    Finds the hinge loss on a single data point given specific classification
    parameters.

    Args:
        feature_vector - A numpy array describing the given data point.
        label - A real valued number, the correct classification of the data
            point.
        theta - A numpy array describing the linear classifier.
        theta_0 - A real valued number representing the offset parameter.


    Returns: A real number representing the hinge loss associated with the
    given data point and parameters.
    """
    # Your code here
    z = label * np.dot(feature_vector, theta) + theta_0
    if z >= 1:
      loss = 0
    else:
      loss = 1 - z
    return loss
feature_vector = np.array([1, 2])
label, theta, theta_0 = 1, np.array([-1, 1]), -0.2
exp_res = 1 - 0.8
hinge_loss_single(feature_vector, label, theta, theta_0)<jupyter_output><empty_output><jupyter_text><jupyter_code>def hinge_loss_full(feature_matrix, labels, theta, theta_0):
    """
    Finds the total hinge loss on a set of data given specific classification
    parameters.

    Args:
        feature_matrix - A numpy matrix describing the given data. Each row
            represents a single data point.
        labels - A numpy array where the kth element of the array is the
            correct classification of the kth row of the feature matrix.
        theta - A numpy array describing the linear classifier.
        theta_0 - A real valued number representing the offset parameter.


    Returns: A real number representing the hinge loss associated with the
    given dataset and parameters. This number should be the average hinge
    loss across all of the points in the feature matrix.
    """
    # Your code here
    z = np.multiply(labels, np.dot(feature_matrix, theta) + theta_0)
    loss = np.mean(np.where(z >= 1, 0, 1 - z))
    return loss
feature_matrix = np.array([[1, 2], [1, 2]])
labels, theta, theta_0 = np.array([1, 1]), np.array([-1, 1]), -0.2
hinge_loss_full(feature_matrix, labels, theta, theta_0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08146821844225605, 'fraction_numerical': 0.01611459265890779, 'mean_word_length': 3.146567717996289, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '610102', 'license': 'MIT', 'n_tokens_mistral': 691, 'n_tokens_neox': 640, 'n_words': 251, 'path': 'Project 1: Automatic Review Analyzer.ipynb', 'repo_name': 'mlaricobar/MITx-6.86x-machine-learning-with-python', 'size': '2234'}