Question: Hi, I need help with implementing a function inferred_conditions(pos_ex, neg_ex) . Please show me a step by step guide and comments/ explanations on how you
Hi, I need help with implementing a function inferred_conditions(pos_ex, neg_ex). Please show me a step by step guide and comments/ explanations on how you wrote the methods you used
I am at straws on trying to solve this so any help would be greatly appreciated!
Index 0, 1, 2, 3, 4 in the list are for : model name, company, screen size , battery and price respectively
The function selection that may be used in the question is provided in full code!
Thank you!



Finally, we will implement a basic machine learning functionality: based on simple binary user feedback on indi- vidual products (\"like\" / \"dislike\"), our search engine should be able to automatically categorise other products as either interesting or uninteresting for the the same user. Technically, implement a function inferred_conditions (pos_ex, neg_ex) that accepts as input two prod- uct tables based on the same feature columns, one containing positive examples, i.e., products that the user likes and the other one containing negative examples, i.e., products that the user dislikes. Your function should return as output a list of conditions conditions on the given numerical features that can be used in conjunction with the function selection from Part 1 to create a personalised recommendation for the user when applied to a table of new products. In particular, the returned conditions should be consistent with the provided list of positive examples (not deselect any of the products known to be liked by the user) but exclude as many of the known negative examples as possible. In summary, the specication of the function inferred_conditions is as follows: Input: a list of products pos_ex of positive product examples and a list of products neg_ex of negative product examples, both based on the same feature columns Output: a list of conditions conds on the numeric feature columns (i.e., those that don't contain strings) that follow the same specication as used in Part 1 of the assignment and that satisfy the following to criteria: 1. selection (pos_examples, conds) == pos_examples, i.e., the inferred conditions select all positive examples, and 2. len(selection (neg-exanples, conds)) is minimal among all condition sets that satisfy the rst criterion. For instance, in our exemplary application to phones, we could imagine the following tables for positive and negative examples. >>> pos_ex = [E'iPhonell', 'Apple', 6.1, 3110, 1280], ['Nova 5T', 'Huawei', 6.26, 3750, 497], ... ['v40 ThinQ', 'LG', 6.4, 3500, 800]] >>> neg_ex = [E'Galaxy 320', 'Samsung', 6.46, 3000, 1348], ['V40 ThinQ', 'LG', 5.8, 3100, 598], ['7T', 'OnePlus', 6.3, 3300, 1200]] Another table of new phones could be as follows. >>> new_phones = [['Galaxy 89', 'Samsung', 5.8, 3000, 728], ['Galaxy Note 9', 'Samsung', 6.3, 3600, 700], ['A9 2020', 'Dppo', 6.4, 4000, 355]] See Figure 2 for an illustration of the content of these three tables mapped onto the two feature dimensions of \"Screen size\" and \"Battery capacity\". Our function allows us to infer conditions that can be used with the function selection to recommend new phones. 4000 ..X . + pos_ex neg_ex 3900 x new_phones 3750 - Battery 3500 3400 3110 3000 X 2800- 5.60 5.80 6.00 6.10 6.40 6.50 6.75 7.00 Screen size Figure 2: Example phone tables mapped onto the feature dimensions 2 ("Screen size" ) and 3 ("Battery capac- ity") with conditions (2, '>=' , 6.1), (2, '=', 3110). These conditions select all positive examples and only one negative example, which cannot be separated from the three positive examples (in these two dimensions). >>> conds = inferred_conditions (pos_ex, neg_ex) >>> selection (pos_ex, conds) [['iPhone11', 'Apple', 6.1, 3110, 1280], ['Nova 5T' , 'Huawei', 6.26, 3750, 497], ['V40 ThinQ' , 'LG' , 6.4, 3500, 800]] >>> selection (neg_ex, conds) [['7T' , 'OnePlus' , 6.3, 3300, 1200]] The inferred conditions can then be used to recommend a specific subset of the new phones to the user. >>> selection (new_phones, conds) [[' Galaxy Note 9', 'Samsung' , 6.3, 3600, 700], ['A9 2020' , 'Oppo' , 6.4, 4000, 355]]def selection(products, conditions): ListOfProducts = list() for product in products: append = True for condition in conditions: index = condition[0] operator = condition[1] value = condition[2] x = str(product[index]) + operator + str(value) if index == 0 or index == if operator == '==': if product[index != value: append = False else: if product[index] == value: append = False else: if not eval(x): append = False if append: ListhProducts.append(product) return ListOfProducts
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
