Question: For this question, only python and numpy package are allowed to use Here is a sample output: def classify_examples (weights, test_examples): (5 pts) This function

For this question, only python and numpy package are allowed to use

For this question, only python and numpy package are allowed to use

Here is a sample output:

Here is a sample output: def classify_examples (weights, test_examples): (5 pts) This

def classify_examples (weights, test_examples): (5 pts) This function classifies examples using the perceptron algorithm. To do that, it receives one single dimensional numpy array weights, and 2D numpy array (test_examples) then returns a ID numpy array with the classification results for each example (1 is positive, and -1 if it is a negative). Parameters: weights: 1-D numpy array with the perceptron weights and bias (bias is in position o) test_examples: 2-D numpy array with the feature-values of the test examples. Note: the width (number of columns) of test_examples should be length of weights - 1. Note: assume weights and the features vectors follow the same order: e.g. we, w1, W2, W3... x1, x2, x3... Returns: 1D numpy array with the classification results of the test_examples: (each is either 1, or -1). HIIT return None In [25]: # Now simulating perceptron classification (using examples from our lecture slides) In [26]: W = np.array([-5, 1, 1]) In [27]: x = np.array( [1, 5] ) In [28]: hw.classify_examples(w, x) Out[28]: 1 In [29]: x = np.array([1, 3]) In [30]: hw.classify_examples(w, x) Out[30]: -1 In [31]: x = np.array([1, 1]) In [32]: hw.classify_examples(w, x) Out[32]: -1 In [33]: x = np.array([4, 3]) In [34] : hw.classify_examples(w, x) Out[34]: 1 In [35]: # Now we pass them as an 2D numpy array In [36]: x = np.array([ [1, 5], [1, 3], [1, 1], [4, 3] ]) In [37]: hw.classify_examples(w, x) Out[37]: array([ 1., -1., -1., 1.])

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!