article

Consumer 3/3 - Expenditure categorization (nb article, consumer_expenditures.md)

Author: Johannes King

Excerpt

Expenditure categorization

The consumer expenditures data set is about analyzing consumer's consumption patterns to predict whether an item was purchased as a gift. Using getML's relational boosting algorithm, we can reach an out-of-sample AUC of over 90%.

Data Set

The Consumer Expenditure Data Set is a public domain data set provided by the American Bureau of Labor Statistics. It includes the diary entries, where American consumers are asked to keep diaries of the products they have purchased each month.

These consumer goods are categorized using a six-digit classification system the UCC. This system is hierarchical, meaning that every digit represents an increasingly granular category.

For instance, all UCC codes beginning with ‘200’ represent beverages. UCC codes beginning with ‘20011’ represents beer and ‘200111’ represents ‘beer and ale’ and ‘200112’ represents ‘nonalcoholic beer’

The diaries also contain a flag that indicates whether the product was purchased as a gift. The challenge is to predict that flag using other information in the diary entries.

This can be done based on the following considerations:

  • Some items are less likely to be purchased as gifts than others (for instance, it is unlikely that toilet paper is ever purchased as a gift).
  • Items that diverge from the usual consumption patterns are more likely to be gifts.

Result

Without hyperparameter optimization getML achieves an AUC of 0.91. We can slightly increase our predictive performance by conducting a hyperparameter optimization - but not by much. RelboostModel and XGBoostClassifier are both robust models that do not require a lot of optimization.

A feature generated by Relboost looks like this when transpiled to SQL

CREATE TABLE "FEATURE_1_1" AS
SELECT SUM( 
    CASE
        WHEN ( t1."UCC4" IN ( '0102', '0601', '0602', '0901', '0902', '1104', '1105', '1201', '1203', '1204', '1302', '1303', '1401', '1602', '1701', '1702', '1803', '1804', '1901', '1902', '3201', '3204', '3305', '3602', '5502', '6209', '6401', '6502', '0101', '0201', '0202', '0203', '0206', '0207', '0208', '0301', '0307', '0801', '1002', '1004', '1005', '1101', '1102', '1404', '1501', '1705', '1802', '1805', '1807', '2801', '3203', '3302', '3301', '4701', '6301', '1903', '2601', '2700', '0403', '1202', '2703', '5601', '6103', '0702', '1402', '2602', '6202', '0401', '1001', '3303', '0103', '0204', '0306', '0502', '1601', '1603', '1703', '4702', '0205', '2403', '3103', '3209', '5001', '6403', '6501', '0308', '0402', '0404', '0405', '0501', '0503', '0603', '1704', '1801', '2001', '3701', '3901', '5504', '6002', '6402', '2502', '2702', '3405', '5205', '5503', '3206', '3401', '4901', '5603', '1502', '1503', '1806', '4301', '4903', '5400', '6901', '0304', '0701', '1301', '4001', '4802', '4900', '0040', '2005', '3404', '3409', '3903', '4201', '6404', '6703', '6709', '0021', '5902', '2101', '6004', '1103', '2003', '2704', '0305', '2402', '6203', '1403', '2004', '4003', '3605', '4801', '2509', '5800', '2200', '0090', '6003', '6201', '3703', '5303', '5602', '6302', '5302', '5304', '2301', '4402', '5901', '4109', '6601', '6602', '6609', '0302', '3306', '3804', '3809', '4401', '2401', '3402', '3101', '5201', '3102', '6701', '6204', '3801', '3709', '6208', '0303', '6802', '0504', '6809', '5301', '5501', '3205', '9999', '5209', '2904', '5604', '6102', '5700', '6205', '3403' ) ) AND ( t1."UCC" IN ( '010210', '060210', '090110', '090210', '110410', '110510', '120110', '120310', '120410', '130212', '130320', '140110', '160211', '180310', '180320', '180410', '190111', '190211', '320140', '320410', '330510', '360210', '550210', '620912', '640110', '650210', '010120', '020110', '020210', '020310', '020610', '020620', '020710', '020810', '020820', '030710', '080110', '100210', '100410', '100510', '110110', '110210', '170520', '170532', '180220', '180420', '180510', '180710', '280120', '190112', '190113', '330110', '470111', '630110', '190313', '260110', '040310', '120210', '190114', '190212', '190321', '270310', '560110', '070240', '140210', '190311', '190322', '260210', '620214', '040110', '070230', '100110', '140220', '010320', '030610', '050210', '160110', '160310', '170310', '170531', '140230', '240320', '320905', '500110', '650110', '030810', '040210', '040410', '040510', '050110', '050310', '060310', '160320', '170410', '180110', '200111', '550410', '600210', '170533', '190324', '250210', '270210', '310352', '520531', '550310', '320610', '490110', '560310', '150212', '180611', '180612', '490312', '540000', '690120', '030410', '070110', '130110', '170510', '320902', '400110', '480213', '490000', '190312', '200512', '200532', '340410', '340901', '390310', '420115', '640420', '670310', '002100', '590230', '210110', '180210', '480212', '640220', '110310', '270410', '030510', '240210', '320330', '620310', '130211', '140340', '200410', '320130', '200522', '470220', '520541', '480110', '250900', '580000', '220000', '620330', '009000', '190314', '600310', '620121', '130121', '190214', '490300', '010310', '530311', '560210', '240310', '630210', '310316', '530412', '620111', '200511', '230110', '340520', '440210', '140330', '690110', '660110', '660210', '660900', '670902', '030210', '340530', '440120', '550320', '620926', '340210', '320110', '180620', '620410', '620810', '030310', '690114', '050410', '680903', '590210', '240120', '320380', '190323', '600420', '620420', '530110', '550110', '190213', '310332', '620213', '999900', '560400', '290440', '310232', '570000', '320150', '630220', '430130', '340310', '640430', '440130' ) ) AND ( t2."UCC" IN ( '010210', '060110', '060210', '090110', '110410', '110510', '120110', '120310', '120410', '130212', '130310', '130320', '140110', '160211', '170110', '180320', '180410', '190111', '190211', '320410', '330510', '360210', '620912', '640110', '010120', '020110', '020210', '020310', '020810', '020820', '030110', '030710', '080110', '100410', '100510', '110110', '110210', '140420', '150110', '170532', '180220', '180420', '180510', '180710', '280120', '330210', '190112', '190113', '330110', '470111', '190313', '260110', '270000', '040310', '120210', '190114', '190212', '190321', '270310', '370213', '560110', '610310', '070240', '140210', '190311', '190322', '260210', '620214', '070230', '140220', '330310', '010320', '030610', '160110', '170531', '360350', '470211', '020510', '140230', '240320', '320905', '400210', '500110', '640310', '660000', '030810', '040210', '040410', '040510', '050110', '060310', '160320', '170410', '180110', '370125', '390120', '600210', '640210', '190324', '250210', '270210', '310352', '320904', '340510', '370211', '520531', '550310', '340110', '150212', '160212', '180611', '180612', '280140', '430120', '690120', '030410', '070110', '130110', '150211', '170510', '320420', '400110', '490000', '004000', '190312', '200512', '340410', '390310', '390321', '390322', '400220', '420115', '640410', '670310', '002100', '590230', '210110', '180210', '380340', '610320', '640220', '110310', '200310', '270410', '030510', '240210', '320330', '620310', '130211', '140340', '320130', '400310', '200522', '470220', '520541', '360311', '360312', '360330', '360420', '360513', '250900', '580000', '009000', '190314', '620121', '130121', '190214', '370314', '490300', '010310', '530311', '240310', '630210', '004100', '530210', '530412', '620111', '200511', '220120', '230110', '340520', '440210', '590110', '140330', '690110', '130122', '390210', '390223', '410120', '410901', '660110', '030210', '330610', '380210', '380901', '340530', '440120', '550320', '240110', '620926', '340210', '200531', '320232', '610110', '520110', '380410', '310220', '320110', '180620', '410130', '620410', '620221', '380110', '320221', '550330', '030310', '690114', '680220', '050410', '280110', '680903', '240120', '640120', '380320', '190323', '600420', '620420', '530110', '390230', '550110', '190213', '999900', '560400', '320521', '290440', '310232', '570000', '620510', '320150', '630220', '430130', '340310' ) ) THEN -0.022364
        WHEN ( t1."UCC4" IN ( '0102', '0601', '0602', '0901', '0902', '1104', '1105', '1201', '1203', '1204', '1302', '1303', '1401', '1602', '1701', '1702', '1803', '1804', '1901', '1902', '3201', '3204', '3305', '3602', '5502', '6209', '6401', '6502', '0101', '0201', '0202', '0203', '0206', '0207', '0208', '0301', '0307', '0801', '1002', '1004', '1005', '1101', '1102', '1404', '1501', '1705', '1802', '1805', '1807', '2801', '3203', '3302', '3301', '4701', '6301', '1903', '2601', '2700', '0403', '1202', '2703', '5601', '6103', '0702', '1402', '2602', '6202', '0401', '1001', '3303', '0103', '0204', '0306', '0502', '1601', '1603', '1703', '4702', '0205', '2403', '3103', '3209', '5001', '6403', '6501', '0308', '0402', '0404', '0405', '0501', '0503', '0603', '1704', '1801', '2001', '3701', '3901', '5504', '6002', '6402', '2502', '2702', '3405', '5205', '5503', '3206', '3401', '4901', '5603', '1502', '1503', '1806', '4301', '4903', '5400', '6901', '0304', '0701', '1301', '4001', '4802', '4900', '0040', '2005', '3404', '3409', '3903', '4201', '6404', '6703', '6709', '0021', '5902', '2101', '6004', '1103', '2003', '2704', '0305', '2402', '6203', '1403', '2004', '4003', '3605', '4801', '2509', '5800', '2200', '0090', '6003', '6201', '3703', '5303', '5602', '6302', '5302', '5304', '2301', '4402', '5901', '4109', '6601', '6602', '6609', '0302', '3306', '3804', '3809', '4401', '2401', '3402', '3101', '5201', '3102', '6701', '6204', '3801', '3709', '6208', '0303', '6802', '0504', '6809', '5301', '5501', '3205', '9999', '5209', '2904', '5604', '6102', '5700', '6205', '3403' ) ) AND ( t1."UCC" IN ( '010210', '060210', '090110', '090210', '110410', '110510', '120110', '120310', '120410', '130212', '130320', '140110', '160211', '180310', '180320', '180410', '190111', '190211', '320140', '320410', '330510', '360210', '550210', '620912', '640110', '650210', '010120', '020110', '020210', '020310', '020610', '020620', '020710', '020810', '020820', '030710', '080110', '100210', '100410', '100510', '110110', '110210', '170520', '170532', '180220', '180420', '180510', '180710', '280120', '190112', '190113', '330110', '470111', '630110', '190313', '260110', '040310', '120210', '190114', '190212', '190321', '270310', '560110', '070240', '140210', '190311', '190322', '260210', '620214', '040110', '070230', '100110', '140220', '010320', '030610', '050210', '160110', '160310', '170310', '170531', '140230', '240320', '320905', '500110', '650110', '030810', '040210', '040410', '040510', '050110', '050310', '060310', '160320', '170410', '180110', '200111', '550410', '600210', '170533', '190324', '250210', '270210', '310352', '520531', '550310', '320610', '490110', '560310', '150212', '180611', '180612', '490312', '540000', '690120', '030410', '070110', '130110', '170510', '320902', '400110', '480213', '490000', '190312', '200512', '200532', '340410', '340901', '390310', '420115', '640420', '670310', '002100', '590230', '210110', '180210', '480212', '640220', '110310', '270410', '030510', '240210', '320330', '620310', '130211', '140340', '200410', '320130', '200522', '470220', '520541', '480110', '250900', '580000', '220000', '620330', '009000', '190314', '600310', '620121', '130121', '190214', '490300', '010310', '530311', '560210', '240310', '630210', '310316', '530412', '620111', '200511', '230110', '340520', '440210', '140330', '690110', '660110', '660210', '660900', '670902', '030210', '340530', '440120', '550320', '620926', '340210', '320110', '180620', '620410', '620810', '030310', '690114', '050410', '680903', '590210', '240120', '320380', '190323', '600420', '620420', '530110', '550110', '190213', '310332', '620213', '999900', '560400', '290440', '310232', '570000', '320150', '630220', '430130', '340310', '640430', '440130' ) ) AND ( t2."UCC" NOT IN ( '010210', '060110', '060210', '090110', '110410', '110510', '120110', '120310', '120410', '130212', '130310', '130320', '140110', '160211', '170110', '180320', '180410', '190111', '190211', '320410', '330510', '360210', '620912', '640110', '010120', '020110', '020210', '020310', '020810', '020820', '030110', '030710', '080110', '100410', '100510', '110110', '110210', '140420', '150110', '170532', '180220', '180420', '180510', '180710', '280120', '330210', '190112', '190113', '330110', '470111', '190313', '260110', '270000', '040310', '120210', '190114', '190212', '190321', '270310', '370213', '560110', '610310', '070240', '140210', '190311', '190322', '260210', '620214', '070230', '140220', '330310', '010320', '030610', '160110', '170531', '360350', '470211', '020510', '140230', '240320', '320905', '400210', '500110', '640310', '660000', '030810', '040210', '040410', '040510', '050110', '060310', '160320', '170410', '180110', '370125', '390120', '600210', '640210', '190324', '250210', '270210', '310352', '320904', '340510', '370211', '520531', '550310', '340110', '150212', '160212', '180611', '180612', '280140', '430120', '690120', '030410', '070110', '130110', '150211', '170510', '320420', '400110', '490000', '004000', '190312', '200512', '340410', '390310', '390321', '390322', '400220', '420115', '640410', '670310', '002100', '590230', '210110', '180210', '380340', '610320', '640220', '110310', '200310', '270410', '030510', '240210', '320330', '620310', '130211', '140340', '320130', '400310', '200522', '470220', '520541', '360311', '360312', '360330', '360420', '360513', '250900', '580000', '009000', '190314', '620121', '130121', '190214', '370314', '490300', '010310', '530311', '240310', '630210', '004100', '530210', '530412', '620111', '200511', '220120', '230110', '340520', '440210', '590110', '140330', '690110', '130122', '390210', '390223', '410120', '410901', '660110', '030210', '330610', '380210', '380901', '340530', '440120', '550320', '240110', '620926', '340210', '200531', '320232', '610110', '520110', '380410', '310220', '320110', '180620', '410130', '620410', '620221', '380110', '320221', '550330', '030310', '690114', '680220', '050410', '280110', '680903', '240120', '640120', '380320', '190323', '600420', '620420', '530110', '390230', '550110', '190213', '999900', '560400', '320521', '290440', '310232', '570000', '620510', '320150', '630220', '430130', '340310' ) ) THEN 0.080186
        WHEN ( t1."UCC4" IN ( '0102', '0601', '0602', '0901', '0902', '1104', '1105', '1201', '1203', '1204', '1302', '1303', '1401', '1602', '1701', '1702', '1803', '1804', '1901', '1902', '3201', '3204', '3305', '3602', '5502', '6209', '6401', '6502', '0101', '0201', '0202', '0203', '0206', '0207', '0208', '0301', '0307', '0801', '1002', '1004', '1005', '1101', '1102', '1404', '1501', '1705', '1802', '1805', '1807', '2801', '3203', '3302', '3301', '4701', '6301', '1903', '2601', '2700', '0403', '1202', '2703', '5601', '6103', '0702', '1402', '2602', '6202', '0401', '1001', '3303', '0103', '0204', '0306', '0502', '1601', '1603', '1703', '4702', '0205', '2403', '3103', '3209', '5001', '6403', '6501', '0308', '0402', '0404', '0405', '0501', '0503', '0603', '1704', '1801', '2001', '3701', '3901', '5504', '6002', '6402', '2502', '2702', '3405', '5205', '5503', '3206', '3401', '4901', '5603', '1502', '1503', '1806', '4301', '4903', '5400', '6901', '0304', '0701', '1301', '4001', '4802', '4900', '0040', '2005', '3404', '3409', '3903', '4201', '6404', '6703', '6709', '0021', '5902', '2101', '6004', '1103', '2003', '2704', '0305', '2402', '6203', '1403', '2004', '4003', '3605', '4801', '2509', '5800', '2200', '0090', '6003', '6201', '3703', '5303', '5602', '6302', '5302', '5304', '2301', '4402', '5901', '4109', '6601', '6602', '6609', '0302', '3306', '3804', '3809', '4401', '2401', '3402', '3101', '5201', '3102', '6701', '6204', '3801', '3709', '6208', '0303', '6802', '0504', '6809', '5301', '5501', '3205', '9999', '5209', '2904', '5604', '6102', '5700', '6205', '3403' ) ) AND ( t1."UCC" NOT IN ( '010210', '060210', '090110', '090210', '110410', '110510', '120110', '120310', '120410', '130212', '130320', '140110', '160211', '180310', '180320', '180410', '190111', '190211', '320140', '320410', '330510', '360210', '550210', '620912', '640110', '650210', '010120', '020110', '020210', '020310', '020610', '020620', '020710', '020810', '020820', '030710', '080110', '100210', '100410', '100510', '110110', '110210', '170520', '170532', '180220', '180420', '180510', '180710', '280120', '190112', '190113', '330110', '470111', '630110', '190313', '260110', '040310', '120210', '190114', '190212', '190321', '270310', '560110', '070240', '140210', '190311', '190322', '260210', '620214', '040110', '070230', '100110', '140220', '010320', '030610', '050210', '160110', '160310', '170310', '170531', '140230', '240320', '320905', '500110', '650110', '030810', '040210', '040410', '040510', '050110', '050310', '060310', '160320', '170410', '180110', '200111', '550410', '600210', '170533', '190324', '250210', '270210', '310352', '520531', '550310', '320610', '490110', '560310', '150212', '180611', '180612', '490312', '540000', '690120', '030410', '070110', '130110', '170510', '320902', '400110', '480213', '490000', '190312', '200512', '200532', '340410', '340901', '390310', '420115', '640420', '670310', '002100', '590230', '210110', '180210', '480212', '640220', '110310', '270410', '030510', '240210', '320330', '620310', '130211', '140340', '200410', '320130', '200522', '470220', '520541', '480110', '250900', '580000', '220000', '620330', '009000', '190314', '600310', '620121', '130121', '190214', '490300', '010310', '530311', '560210', '240310', '630210', '310316', '530412', '620111', '200511', '230110', '340520', '440210', '140330', '690110', '660110', '660210', '660900', '670902', '030210', '340530', '440120', '550320', '620926', '340210', '320110', '180620', '620410', '620810', '030310', '690114', '050410', '680903', '590210', '240120', '320380', '190323', '600420', '620420', '530110', '550110', '190213', '310332', '620213', '999900', '560400', '290440', '310232', '570000', '320150', '630220', '430130', '340310', '640430', '440130' ) ) AND ( t2."UCC" IN ( '010210', '060110', '060210', '090110', '090210', '110410', '110510', '120110', '120310', '130212', '170110', '170210', '180310', '180320', '180410', '190111', '620912', '010120', '020110', '020210', '020310', '020810', '030110', '030710', '080110', '100510', '110210', '140420', '150110', '170520', '170532', '180220', '180420', '180510', '180710', '280120', '330210', '190113', '330110', '470111', '630110', '260110', '270000', '040310', '120210', '270310', '610310', '070240', '140210', '040110', '070230', '140220', '330310', '010320', '020410', '030610', '050210', '160310', '170310', '170531', '180520', '320905', '500110', '660000', '030810', '040210', '040410', '040510', '050110', '050310', '160320', '170410', '180110', '200111', '640210', '170533', '270210', '160212', '180611', '180612', '070110', '150211', '170510', '320345', '420115', '610320', '010110', '200310', '030510', '130211', '140340', '010310', '530311', '590110', '390210', '380420', '620926', '180620', '280110' ) ) THEN -0.072672
        WHEN ( t1."UCC4" IN ( '0102', '0601', '0602', '0901', '0902', '1104', '1105', '1201', '1203', '1204', '1302', '1303', '1401', '1602', '1701', '1702', '1803', '1804', '1901', '1902', '3201', '3204', '3305', '3602', '5502', '6209', '6401', '6502', '0101', '0201', '0202', '0203', '0206', '0207', '0208', '0301', '0307', '0801', '1002', '1004', '1005', '1101', '1102', '1404', '1501', '1705', '1802', '1805', '1807', '2801', '3203', '3302', '3301', '4701', '6301', '1903', '2601', '2700', '0403', '1202', '2703', '5601', '6103', '0702', '1402', '2602', '6202', '0401', '1001', '3303', '0103', '0204', '0306', '0502', '1601', '1603', '1703', '4702', '0205', '2403', '3103', '3209', '5001', '6403', '6501', '0308', '0402', '0404', '0405', '0501', '0503', '0603', '1704', '1801', '2001', '3701', '3901', '5504', '6002', '6402', '2502', '2702', '3405', '5205', '5503', '3206', '3401', '4901', '5603', '1502', '1503', '1806', '4301', '4903', '5400', '6901', '0304', '0701', '1301', '4001', '4802', '4900', '0040', '2005', '3404', '3409', '3903', '4201', '6404', '6703', '6709', '0021', '5902', '2101', '6004', '1103', '2003', '2704', '0305', '2402', '6203', '1403', '2004', '4003', '3605', '4801', '2509', '5800', '2200', '0090', '6003', '6201', '3703', '5303', '5602', '6302', '5302', '5304', '2301', '4402', '5901', '4109', '6601', '6602', '6609', '0302', '3306', '3804', '3809', '4401', '2401', '3402', '3101', '5201', '3102', '6701', '6204', '3801', '3709', '6208', '0303', '6802', '0504', '6809', '5301', '5501', '3205', '9999', '5209', '2904', '5604', '6102', '5700', '6205', '3403' ) ) AND ( t1."UCC" NOT IN ( '010210', '060210', '090110', '090210', '110410', '110510', '120110', '120310', '120410', '130212', '130320', '140110', '160211', '180310', '180320', '180410', '190111', '190211', '320140', '320410', '330510', '360210', '550210', '620912', '640110', '650210', '010120', '020110', '020210', '020310', '020610', '020620', '020710', '020810', '020820', '030710', '080110', '100210', '100410', '100510', '110110', '110210', '170520', '170532', '180220', '180420', '180510', '180710', '280120', '190112', '190113', '330110', '470111', '630110', '190313', '260110', '040310', '120210', '190114', '190212', '190321', '270310', '560110', '070240', '140210', '190311', '190322', '260210', '620214', '040110', '070230', '100110', '140220', '010320', '030610', '050210', '160110', '160310', '170310', '170531', '140230', '240320', '320905', '500110', '650110', '030810', '040210', '040410', '040510', '050110', '050310', '060310', '160320', '170410', '180110', '200111', '550410', '600210', '170533', '190324', '250210', '270210', '310352', '520531', '550310', '320610', '490110', '560310', '150212', '180611', '180612', '490312', '540000', '690120', '030410', '070110', '130110', '170510', '320902', '400110', '480213', '490000', '190312', '200512', '200532', '340410', '340901', '390310', '420115', '640420', '670310', '002100', '590230', '210110', '180210', '480212', '640220', '110310', '270410', '030510', '240210', '320330', '620310', '130211', '140340', '200410', '320130', '200522', '470220', '520541', '480110', '250900', '580000', '220000', '620330', '009000', '190314', '600310', '620121', '130121', '190214', '490300', '010310', '530311', '560210', '240310', '630210', '310316', '530412', '620111', '200511', '230110', '340520', '440210', '140330', '690110', '660110', '660210', '660900', '670902', '030210', '340530', '440120', '550320', '620926', '340210', '320110', '180620', '620410', '620810', '030310', '690114', '050410', '680903', '590210', '240120', '320380', '190323', '600420', '620420', '530110', '550110', '190213', '310332', '620213', '999900', '560400', '290440', '310232', '570000', '320150', '630220', '430130', '340310', '640430', '440130' ) ) AND ( t2."UCC" NOT IN ( '010210', '060110', '060210', '090110', '090210', '110410', '110510', '120110', '120310', '130212', '170110', '170210', '180310', '180320', '180410', '190111', '620912', '010120', '020110', '020210', '020310', '020810', '030110', '030710', '080110', '100510', '110210', '140420', '150110', '170520', '170532', '180220', '180420', '180510', '180710', '280120', '330210', '190113', '330110', '470111', '630110', '260110', '270000', '040310', '120210', '270310', '610310', '070240', '140210', '040110', '070230', '140220', '330310', '010320', '020410', '030610', '050210', '160310', '170310', '170531', '180520', '320905', '500110', '660000', '030810', '040210', '040410', '040510', '050110', '050310', '160320', '170410', '180110', '200111', '640210', '170533', '270210', '160212', '180611', '180612', '070110', '150211', '170510', '320345', '420115', '610320', '010110', '200310', '030510', '130211', '140340', '010310', '530311', '590110', '390210', '380420', '620926', '180620', '280110' ) ) THEN 0.156278
        WHEN ( t1."UCC4" NOT IN ( '0102', '0601', '0602', '0901', '0902', '1104', '1105', '1201', '1203', '1204', '1302', '1303', '1401', '1602', '1701', '1702', '1803', '1804', '1901', '1902', '3201', '3204', '3305', '3602', '5502', '6209', '6401', '6502', '0101', '0201', '0202', '0203', '0206', '0207', '0208', '0301', '0307', '0801', '1002', '1004', '1005', '1101', '1102', '1404', '1501', '1705', '1802', '1805', '1807', '2801', '3203', '3302', '3301', '4701', '6301', '1903', '2601', '2700', '0403', '1202', '2703', '5601', '6103', '0702', '1402', '2602', '6202', '0401', '1001', '3303', '0103', '0204', '0306', '0502', '1601', '1603', '1703', '4702', '0205', '2403', '3103', '3209', '5001', '6403', '6501', '0308', '0402', '0404', '0405', '0501', '0503', '0603', '1704', '1801', '2001', '3701', '3901', '5504', '6002', '6402', '2502', '2702', '3405', '5205', '5503', '3206', '3401', '4901', '5603', '1502', '1503', '1806', '4301', '4903', '5400', '6901', '0304', '0701', '1301', '4001', '4802', '4900', '0040', '2005', '3404', '3409', '3903', '4201', '6404', '6703', '6709', '0021', '5902', '2101', '6004', '1103', '2003', '2704', '0305', '2402', '6203', '1403', '2004', '4003', '3605', '4801', '2509', '5800', '2200', '0090', '6003', '6201', '3703', '5303', '5602', '6302', '5302', '5304', '2301', '4402', '5901', '4109', '6601', '6602', '6609', '0302', '3306', '3804', '3809', '4401', '2401', '3402', '3101', '5201', '3102', '6701', '6204', '3801', '3709', '6208', '0303', '6802', '0504', '6809', '5301', '5501', '3205', '9999', '5209', '2904', '5604', '6102', '5700', '6205', '3403' ) ) AND ( t2."UCC4" IN ( '0102', '0602', '0901', '1104', '1105', '1201', '1203', '1204', '1302', '1602', '1701', '1702', '1804', '1901', '3201', '3305', '5502', '6401', '6502', '0201', '0202', '0203', '0301', '0801', '1002', '1004', '1102', '1705', '1805', '3202', '3203', '3302', '3301', '6301', '1903', '2601', '2700', '1202', '6103', '0702', '1402', '3303', '1603', '0205', '3209', '6501', '6600', '0503', '1801', '2001', '3803', '6402', '3902', '3306' ) ) AND ( t2."UCC4" IN ( '1104', '1701', '5502', '6401', '0201', '0301', '1004', '3203', '3302', '2700', '1202', '0702', '6600', '2001' ) ) THEN -1.280657
        WHEN ( t1."UCC4" NOT IN ( '0102', '0601', '0602', '0901', '0902', '1104', '1105', '1201', '1203', '1204', '1302', '1303', '1401', '1602', '1701', '1702', '1803', '1804', '1901', '1902', '3201', '3204', '3305', '3602', '5502', '6209', '6401', '6502', '0101', '0201', '0202', '0203', '0206', '0207', '0208', '0301', '0307', '0801', '1002', '1004', '1005', '1101', '1102', '1404', '1501', '1705', '1802', '1805', '1807', '2801', '3203', '3302', '3301', '4701', '6301', '1903', '2601', '2700', '0403', '1202', '2703', '5601', '6103', '0702', '1402', '2602', '6202', '0401', '1001', '3303', '0103', '0204', '0306', '0502', '1601', '1603', '1703', '4702', '0205', '2403', '3103', '3209', '5001', '6403', '6501', '0308', '0402', '0404', '0405', '0501', '0503', '0603', '1704', '1801', '2001', '3701', '3901', '5504', '6002', '6402', '2502', '2702', '3405', '5205', '5503', '3206', '3401', '4901', '5603', '1502', '1503', '1806', '4301', '4903', '5400', '6901', '0304', '0701', '1301', '4001', '4802', '4900', '0040', '2005', '3404', '3409', '3903', '4201', '6404', '6703', '6709', '0021', '5902', '2101', '6004', '1103', '2003', '2704', '0305', '2402', '6203', '1403', '2004', '4003', '3605', '4801', '2509', '5800', '2200', '0090', '6003', '6201', '3703', '5303', '5602', '6302', '5302', '5304', '2301', '4402', '5901', '4109', '6601', '6602', '6609', '0302', '3306', '3804', '3809', '4401', '2401', '3402', '3101', '5201', '3102', '6701', '6204', '3801', '3709', '6208', '0303', '6802', '0504', '6809', '5301', '5501', '3205', '9999', '5209', '2904', '5604', '6102', '5700', '6205', '3403' ) ) AND ( t2."UCC4" IN ( '0102', '0602', '0901', '1104', '1105', '1201', '1203', '1204', '1302', '1602', '1701', '1702', '1804', '1901', '3201', '3305', '5502', '6401', '6502', '0201', '0202', '0203', '0301', '0801', '1002', '1004', '1102', '1705', '1805', '3202', '3203', '3302', '3301', '6301', '1903', '2601', '2700', '1202', '6103', '0702', '1402', '3303', '1603', '0205', '3209', '6501', '6600', '0503', '1801', '2001', '3803', '6402', '3902', '3306' ) ) AND ( t2."UCC4" NOT IN ( '1104', '1701', '5502', '6401', '0201', '0301', '1004', '3203', '3302', '2700', '1202', '0702', '6600', '2001' ) ) THEN 0.024361
        WHEN ( t1."UCC4" NOT IN ( '0102', '0601', '0602', '0901', '0902', '1104', '1105', '1201', '1203', '1204', '1302', '1303', '1401', '1602', '1701', '1702', '1803', '1804', '1901', '1902', '3201', '3204', '3305', '3602', '5502', '6209', '6401', '6502', '0101', '0201', '0202', '0203', '0206', '0207', '0208', '0301', '0307', '0801', '1002', '1004', '1005', '1101', '1102', '1404', '1501', '1705', '1802', '1805', '1807', '2801', '3203', '3302', '3301', '4701', '6301', '1903', '2601', '2700', '0403', '1202', '2703', '5601', '6103', '0702', '1402', '2602', '6202', '0401', '1001', '3303', '0103', '0204', '0306', '0502', '1601', '1603', '1703', '4702', '0205', '2403', '3103', '3209', '5001', '6403', '6501', '0308', '0402', '0404', '0405', '0501', '0503', '0603', '1704', '1801', '2001', '3701', '3901', '5504', '6002', '6402', '2502', '2702', '3405', '5205', '5503', '3206', '3401', '4901', '5603', '1502', '1503', '1806', '4301', '4903', '5400', '6901', '0304', '0701', '1301', '4001', '4802', '4900', '0040', '2005', '3404', '3409', '3903', '4201', '6404', '6703', '6709', '0021', '5902', '2101', '6004', '1103', '2003', '2704', '0305', '2402', '6203', '1403', '2004', '4003', '3605', '4801', '2509', '5800', '2200', '0090', '6003', '6201', '3703', '5303', '5602', '6302', '5302', '5304', '2301', '4402', '5901', '4109', '6601', '6602', '6609', '0302', '3306', '3804', '3809', '4401', '2401', '3402', '3101', '5201', '3102', '6701', '6204', '3801', '3709', '6208', '0303', '6802', '0504', '6809', '5301', '5501', '3205', '9999', '5209', '2904', '5604', '6102', '5700', '6205', '3403' ) ) AND ( t2."UCC4" NOT IN ( '0102', '0602', '0901', '1104', '1105', '1201', '1203', '1204', '1302', '1602', '1701', '1702', '1804', '1901', '3201', '3305', '5502', '6401', '6502', '0201', '0202', '0203', '0301', '0801', '1002', '1004', '1102', '1705', '1805', '3202', '3203', '3302', '3301', '6301', '1903', '2601', '2700', '1202', '6103', '0702', '1402', '3303', '1603', '0205', '3209', '6501', '6600', '0503', '1801', '2001', '3803', '6402', '3902', '3306' ) ) AND ( t1."UCC1" IN ( '2', '3', '6' ) ) THEN 0.456181
        WHEN ( t1."UCC4" NOT IN ( '0102', '0601', '0602', '0901', '0902', '1104', '1105', '1201', '1203', '1204', '1302', '1303', '1401', '1602', '1701', '1702', '1803', '1804', '1901', '1902', '3201', '3204', '3305', '3602', '5502', '6209', '6401', '6502', '0101', '0201', '0202', '0203', '0206', '0207', '0208', '0301', '0307', '0801', '1002', '1004', '1005', '1101', '1102', '1404', '1501', '1705', '1802', '1805', '1807', '2801', '3203', '3302', '3301', '4701', '6301', '1903', '2601', '2700', '0403', '1202', '2703', '5601', '6103', '0702', '1402', '2602', '6202', '0401', '1001', '3303', '0103', '0204', '0306', '0502', '1601', '1603', '1703', '4702', '0205', '2403', '3103', '3209', '5001', '6403', '6501', '0308', '0402', '0404', '0405', '0501', '0503', '0603', '1704', '1801', '2001', '3701', '3901', '5504', '6002', '6402', '2502', '2702', '3405', '5205', '5503', '3206', '3401', '4901', '5603', '1502', '1503', '1806', '4301', '4903', '5400', '6901', '0304', '0701', '1301', '4001', '4802', '4900', '0040', '2005', '3404', '3409', '3903', '4201', '6404', '6703', '6709', '0021', '5902', '2101', '6004', '1103', '2003', '2704', '0305', '2402', '6203', '1403', '2004', '4003', '3605', '4801', '2509', '5800', '2200', '0090', '6003', '6201', '3703', '5303', '5602', '6302', '5302', '5304', '2301', '4402', '5901', '4109', '6601', '6602', '6609', '0302', '3306', '3804', '3809', '4401', '2401', '3402', '3101', '5201', '3102', '6701', '6204', '3801', '3709', '6208', '0303', '6802', '0504', '6809', '5301', '5501', '3205', '9999', '5209', '2904', '5604', '6102', '5700', '6205', '3403' ) ) AND ( t2."UCC4" NOT IN ( '0102', '0602', '0901', '1104', '1105', '1201', '1203', '1204', '1302', '1602', '1701', '1702', '1804', '1901', '3201', '3305', '5502', '6401', '6502', '0201', '0202', '0203', '0301', '0801', '1002', '1004', '1102', '1705', '1805', '3202', '3203', '3302', '3301', '6301', '1903', '2601', '2700', '1202', '6103', '0702', '1402', '3303', '1603', '0205', '3209', '6501', '6600', '0503', '1801', '2001', '3803', '6402', '3902', '3306' ) ) AND ( t1."UCC1" NOT IN ( '2', '3', '6' ) ) THEN 0.841765
        ELSE NULL
    END
) AS "feature_1_1",
     t1.rowid AS "rownum"
FROM "POPULATION" t1
LEFT JOIN "EXPD" t2
ON t1."NEWID" = t2."NEWID"
WHERE datetime( t2."TIME_STAMP" ) <= datetime( t1."TIME_STAMP" )
GROUP BY t1.rowid;

This feature is mainly based on the UCC codes, both the UCC codes of the product in question (marked t1.UCC), but it also compares the UCC code to other products that the household has purchased (marked t2.UCC). This means that both the product itself, but also the household's usual consumption patterns predict whether this item was purchased as a gift.