Question: Please in Python and only use Numpy package Look at the sample, make sure the first classification works yeah actually hw is the name of

Please in Python and only use Numpy package

Please in Python and only use Numpy package Look at the sample,

make sure the first classification works yeah actually hw is the name

Look at the sample, make sure the first classification works

yeah actually hw is the name of the file or the class, it is not mandatory, what matters is the function

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 1D 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 () 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, wl, W2, W3... x1, x2, x3... Returns: 1D numpy array with the classification results of the test_examples: (each is either 1, or -1). 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!