IPA FE Subject B 2024 Question 5
A question IPA Japan published in 令和6年度 基本情報技術者試験 科目B 公開問題 問5, translated into English. ITPEC is based on the same exams.
From the answer group below, select the correct combination of answers to be inserted into A through C in the program. Here, the array index starts at 1.
There is order data that records, for each order, the list of the items purchased in one order. The table shows an example of the order data.
Table Example of order data
From the order data, the degree of association Lxy, which shows the tendency of item x and item y to be purchased in the same order, is calculated by the following formula.
Lxy = Mxy × total number of ordersKx × Ky
Here, Mxy represents the number of orders in which item x and item y were purchased in the same order, Kx represents the number of orders in which item x was purchased, and Ky represents the number of orders in which item y was purchased. In the example in the table, MAB is 2, the total number of orders is 6, KA is 4, and KB is 3, so the degree of association LAB between item A and item B is (2 × 6) / (4 × 3) = 1.0.
The procedure putRelatedItem outputs, based on the order data stored in the global variable orders, one of the items that have the largest degree of association with the item given as the argument, and that degree of association. In the program, an item is represented by a string, an order by an array of the purchased items, and the order data by an array of orders. The order data is assumed to contain two or more kinds of items. In addition, no item other than the items in the order data is given as the argument.
Answer group
Explanation
A: arrayM[i], B: arrayK[i], C: the number of elements in orders — in the formula, arrayM[i] must count the orders that hold both items, arrayK[i] the orders that hold otherItems[i], and the multiplier is the total number of orders.
itemCount counts the orders that contain item, so it is Kx. For an order holding otherItems[i], A is increased only when item is in it too, so A counts Mxy: arrayM[i]. B is increased for every order holding otherItems[i], so it counts Ky: arrayK[i]. Then valueL is Mxy × C ÷ (Kx × Ky), so C is the total number of orders.
For item = "A": arrayK = {3, 1, 2, 2} and arrayM = {2, 0, 2, 1} for B, C, D, E, itemCount = 4; the values are 1.0, 0, 1.5 and 0.75, and the output is D, 1..
Answer (e)
Why not others:
- •(a), (b) and (c) — swap A and B, so the divisor holds the joint count: for C, never bought with A, it is 4 × 0, a division by zero, and (b) gives LAB = 2.25, not 1.0
- •(d) — multiplies by the 5 items in
allItems, not the 6 orders: same item, wrong value,D, 1.25 - •(f) — multiplies by the 4 items in
otherItems:D, 1
Key rule: This degree of association is the lift of an association rule: joint count × total orders ÷ the product of the two single-item counts.
Math & Data Science · AI-written, may contain errors
This question comes from the past questions IPA Japan publishes, translated into English by ITPEC Practice. ITPEC Practice is an independent study tool and is not affiliated with IPA or ITPEC. See the original paper (PDF) or Report an issue.