Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task B: Product Ranking (linearly-ranked, 4 Marks) In addition to selecting products based on hard conditions, users should also be allowed to indicate their preferences

image text in transcribed
Task B: Product Ranking (linearly-ranked, 4 Marks) In addition to selecting products based on hard conditions, users should also be allowed to indicate their preferences by numeric weights for individual (numerical) product features. We represent a set of weights as a list, which contains at position j the weight for feature j or None if the user does not have a preference weight for that feature (or if that feature is not numeric). For example, the weighting of a user looking for a cheap phone (every $100 worth one negative point) with small screen (every 0.1 inch worth one positive point) and long battery life (every 1000mAh worth one positive point) is represented by the following list: 3>2 screen_battery_price = [None, None, 10. 1/1000, -1/100] Implement a function linearly ranked (products, weights) that accepts as input a product database and preference weights and returns as output a list of products ordered according to a numeric score resulting from the linear combination of all specified individual preferences. The detailed specification of this function is as follows. Input: Product table products, list of weights weights of length equal to the number of columns in products containing at position i the linear weight for product feature column i or None if no weight is specified for column i (must be None for non-numeric column). At least one weight must be different from None. Output: A new table containing all products from the input table in decreasing order of the linear score given, for a product prod in products, by the sum of prod [i] weights [i] over all column indices i with weights [1] !-None. For example with the phone database from the overview section and a simple weighting scheme putting all weight on battery mpacity we get: 3>3 battery = [None, None, None, 1, None] 3>3 limearly_ranked (phones, battery) [['Reno Z' , 'Oppo' , 6.4, 4036, 397]. ['Galaxy S20' , 'Samsung' , 6.2, 4000, 1248], ['Nova ST', 'Huawei', 6.26. 2760, 497]. ['V40 Thing' , 'LG' , 6.4, 3200, 698], ['1Phomell', 'Apple", 6.1, 3110, 1260]] In contrast, with the above compromise between screen size, battery, and price we get: 3>> limearly_ranked (phones, screen_battery_price) [['Reno Z' , 'Oppo' , 6.4, 4036, 397]. ['Nova ST', 'Huawei', 6.26, 3750, 497], ['V40 Thing' , 'Lo', 6.4, 3300, 698]. ['Galaxy $20', 'Samsung', 6.2, 4000, 1248], ['iPhomell', "Apple', 6.1, 3110, 1280]] The input table is not changed by the function. That is after calling it, we still have: > > phones [[ 'iPhonell', 'Apple', 6.1. 2110, 1290], ['Galaxy $20', 'Samsung', 6.2, 4000, 1344], ['Nova ST' , 'Huawei", 6.26. 2760, 497], ['V40 Thing', 'LG', 6.4, 2300, 898], ['Reno 2', 'Oppo' , 6.4, 4035, 297]]

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

Unity From Zero To Proficiency Beginner A Step By Step Guide To Coding Your First Game

Authors: Patrick Felicia

1st Edition

1091872023, 978-1091872028

More Books

Students also viewed these Programming questions