DATA170
Exploring Data

Activity 12

Perceptron

  1. Write the Python function classify(features, weights) that uses a perceptron to classify a sample. The parameter features is a one-dimensional Numpy array of floats of the sample’s features. The parameter weights is a one-dimensional Numpy array of floats that contains the perceptron’s weights. If there are m features then there must be m + 1 weights. The first weight is the perceptron’s bias.

    For example:

    features = np.array([0.2962963, 0.625])
    weights = np.array([0.57501319,  1.34218874, -1.36311653])
    print(classify(features, weights)) # should print 0
    
    features = np.array([0.51851852, 0.33333333])
    weights = np.array([0.57501319,  1.34218874, -1.36311653])
    print(classify(features, weights)) # should print 1