1. Lighthouse

Level 2 · Conversion per arm and the lift

The request

From Jordan Reyes, Head of Marketing

“Good, the split is clean. So, did the banner win? Give me the conversion rate for each group and how much better or worse the banner group did.”

Your goal

Set result to a dict: "rate_a" and "rate_b", the conversion rate (share of sessions with converted True) in each arm, "abs_lift", rate B minus rate A, and "rel_lift", that difference divided by rate A. Compute from unrounded rates, then round all four to 4 decimals.

  • Use the web_sessions DataFramenot done yet
  • Store a dict in resultnot done yet
Conversion rate per arm, Nov–Dec 2025
Conversion rate per arm, Nov–Dec 20250%1%2%3%4%5%A: no banner: 3.8%3.8%A: no bannerB: banner: 4%4%B: bannerArmSessions that converted
Conversion rate per arm, Nov–Dec 20250%1%2%3%4%5%A: no banner: 3.8%3.8%A: no bannerB: banner: 4%4%B: bannerArmSessions that converted

Each arm has 2,604 sessions. Arm A converted 98 of them, arm B 105. The axis starts at zero, so bar heights compare honestly.

Show the numbers
ArmSessions that converted
A: no banner3.8%
B: banner4%

Your code

Python

Loading the editor…

    ResultPreview of web_sessions · press Run to see yours
    Preview of web_sessions
    session_idcustomer_idstarted_atdevicesource
    1NaN2023-01-01 23:02:24mobilepaid
    2182023-01-01 15:07:49desktoppaid
    3NaN2023-01-01 16:55:46desktopdirect
    4NaN2023-01-01 12:43:28mobileorganic

    Mote checks your result

    Press Run. Each row that matches the goal becomes a firefly in your lantern.

    DataFrames

    Loaded for you as pandas DataFrames, plus pd and np.

    web_sessions40,000 rows · 7 columns
    • session_idinteger
    • customer_idinteger
    • started_attimestamp
    • devicevarchar
    • sourcevarchar
    • pages_viewedinteger
    • convertedboolean
    First 5 rows of web_sessions
    session_idcustomer_idstarted_atdevicesourcepages_viewedconverted
    1NaN2023-01-01 23:02:24mobilepaid1false
    2182023-01-01 15:07:49desktoppaid1false
    3NaN2023-01-01 16:55:46desktopdirect7false
    4NaN2023-01-01 12:43:28mobileorganic3false
    5NaN2023-01-01 13:06:21mobilesocial2false
    customers2,018 rows · 9 columns
    • customer_idinteger
    • first_namevarchar
    • last_namevarchar
    • emailvarchar
    • cityvarchar
    • statevarchar
    • signup_datedate
    • segmentvarchar
    • referral_sourcevarchar
    First 5 rows of customers
    customer_idfirst_namelast_nameemailcitystatesignup_datesegmentreferral_source
    1OwenHudsonowen.hudson@icloud.comSan FranciscoCA2022-06-02consumersearch
    2DouglasMendozadmendoza69@gmail.comAtlantaGA2022-06-02consumerNaN
    3HenryBrookshbrooks@lakesidecafe.comLos AngelesCA2022-06-04businessNaN
    4BrianGrahambgraham@bluecedarhomes.comSeattleWA2022-06-06businesspinterest
    5KyleJimenezkjimenez27@yahoo.comIndianapolisIN2022-06-07consumerNaN
    products120 rows · 8 columns
    • product_idinteger
    • namevarchar
    • categoryvarchar
    • subcategoryvarchar
    • unit_pricedecimal
    • unit_costdecimal
    • launched_ondate
    • is_activeboolean
    First 5 rows of products
    product_idnamecategorysubcategoryunit_priceunit_costlaunched_onis_active
    101Vale Velvet LoveseatFurnitureSofas1659.00NaN2023-09-11true
    102Alder Oak Coffee TableFurnitureTables919.00503.502024-05-16true
    103Orchard Rattan Dining ChairFurnitureChairs789.00429.872023-05-27true
    104Upland Oak BookcaseFurnitureStorage429.00214.702022-12-20true
    105Avery Leather Bed FrameFurnitureBeds449.00232.702021-08-31true
    orders12,000 rows · 7 columns
    • order_idinteger
    • customer_idinteger
    • order_datetimestamp
    • statusvarchar
    • channelvarchar
    • shipping_feedecimal
    • coupon_codevarchar
    First 5 rows of orders
    order_idcustomer_idorder_datestatuschannelshipping_feecoupon_code
    10011252023-01-01 20:51:19completedweb0.00NaN
    10021562023-01-02 07:58:46completedweb0.00NaN
    1003222023-01-02 10:25:27completedmarketplace4.99WELCOME10
    1004482023-01-02 11:21:51completedmarketplace4.99WELCOME10
    1005822023-01-02 11:43:36completedweb0.00WELCOME10
    order_items30,338 rows · 6 columns
    • order_item_idinteger
    • order_idinteger
    • product_idinteger
    • quantityinteger
    • unit_pricedecimal
    • discount_pctdecimal
    First 5 rows of order_items
    order_item_idorder_idproduct_idquantityunit_pricediscount_pct
    11001121931.990.00
    21001154311.990.00
    31002154411.990.00
    410021941149.000.00
    51002193219.990.00
    returns1,673 rows · 5 columns
    • return_idinteger
    • order_item_idinteger
    • returned_ondate
    • reasonvarchar
    • refund_amountdecimal
    First 5 rows of returns
    return_idorder_item_idreturned_onreasonrefund_amount
    1142023-01-10damaged83.69
    2422023-01-10wrong_item19.99
    31052023-01-14wrong_item10.99
    4242023-01-16changed_mind26.99
    51262023-01-16late20.99
    employees60 rows · 8 columns
    • employee_idinteger
    • first_namevarchar
    • last_namevarchar
    • departmentvarchar
    • titlevarchar
    • manager_idinteger
    • hire_datedate
    • salaryinteger
    First 5 rows of employees
    employee_idfirst_namelast_namedepartmenttitlemanager_idhire_datesalary
    1CatherineHaleExecutiveChief Executive OfficerNaN2016-03-01285000
    2RobertKimExecutiveChief Operating Officer12017-01-09235000
    3MeganCollinsSalesHead of Sales12018-04-16172000
    4ChloeGutierrezSalesAccount Executive32020-01-2172000
    5FrankBellSalesAccount Executive32023-05-2173000
    marketing_spend3,276 rows · 3 columns
    • spend_datedate
    • channelvarchar
    • amountdecimal
    First 5 rows of marketing_spend
    spend_datechannelamount
    2023-01-01paid492.99
    2023-01-01email37.38
    2023-01-01social200.53
    2023-01-02paid709.13
    2023-01-02email64.13

    The lesson

    Conversion rate is a mean

    A session either converted or it didn’t. Store that as True/False and the conversion rate is simply the mean of the column, because pandas counts True as 1 and False as 0:

    test.groupby("arm")["converted"].mean()
    # A    0.0376
    # B    0.0403

    Arm B, the banner, converted 105 of 2,604 sessions; arm A converted 98 of 2,604. It is worth printing the counts next to the rates (.agg(["size", "sum", "mean"])), because 105 versus 98 is a much more honest picture of the evidence than 4.03% versus 3.76%.

    Absolute and relative lift

    There are two ways to say how much better B did, and people mix them up constantly:

    • Absolute lift: rate_b - rate_a = 0.0027, or 0.27 percentage points.
    • Relative lift: (rate_b - rate_a) / rate_a = 0.071, or 7.1%.

    The relative number sounds more impressive, which is why it ends up in headlines. Both are correct; what matters is saying which one you mean. “Conversion rose 7%” read by someone who thinks in points sounds like 3.8% became 10.8%, which is not what happened.

    Use points (pp) for differences of rates, and percent for relative change. Write it as “+0.27 pp (+7.1% relative)” and nobody can misread it.

    Seven percent of what?

    Seven extra orders in two months is the real-world size of this difference. With conversions this rare, a handful of sessions moves the rate a lot: if eight of B’s 105 buyers had left without ordering, B would be the losing arm. That is the question the next level answers properly: how much of this gap could be noise?

    Common mistakes

    • Rounding before dividing. Round 0.037634 and 0.040323 to 0.0376 and 0.0403 first and the relative lift comes out 0.0718 instead of 0.0714. Compute with full precision, round at the end.
    • Dividing by the wrong arm. Relative lift is measured against the control (A). Dividing by B gives a different number that answers a different question.
    • Counting rows instead of sessions with a conversion. count() counts non-missing values, so it counts every session. Use sum() for conversions, mean() for the rate.
    • Declaring a winner from the lift alone. Every test has a winner if you only compare two numbers. The lift is the estimate; whether it is real is a separate question.

    Pick what may run on this site. You can change this any time from "Cookie settings" at the bottom of every page.