I am fairly new to machine learning and I am learning with a book.

So if I want to classify customers by their purchases, how would that look?

Age and sex would be single features, but what about the purchase history? 1 customer could have 10.000 or more purchases (each article is categorized: electronics, hardware, software, ...) some may only have 1000 or 100.

So my data should look like this

customerId | sex  | age | purchases 
383848     |  w   | 35  | 1234, 49239   

and not like this?

customerId | sex  | age | purchase1 | purchase2 | purchase3
383848     |  w   | 35  | 1234      | 49239     | null

The examples I have done until now don't cover this - so any pointers are really appreciated.

  • 1
    $\begingroup$ Neither choice of representing the data is a good one for most purposes. For a better and principled approach, consult resources on data modeling and relational databases. $\endgroup$
    – whuber
    Commented Feb 7, 2018 at 14:56

1 Answer 1


If you have a finite number of purchase types (electronics, hardware, etc.), you could represent each category as a set of variables describing stuff like:

  • Total number of purchases in the category
  • Amount of money spent on this category
  • Statistics like average price of items bought, maximum price of items bought, etc.
  • Frequency of purchases
  • ...generally whatever is possible to extract from your data (you did not give any details how this purchase records look like)

This whole process is called feature engineering. I would recommend first generating many such features and perhaps later remove uninformative ones using some feature selection techniques. The second step is not necessary with some classifiers which can learn ignoring uninformative features.

There is no general way how to perform feature engineering: It is an art in itself and every learning task might need different features.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.