Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

What about leadership lessons from particularly good or bad bosses?

Answered: 1 week ago