Concepts / Feature Extraction and Feature Engineering

Feature Extraction and Feature Engineering

The choice of features affects how well predictions work, and building a good representation is called feature extraction or feature engineering.

  • Programming

Why a Model Only Sees Numbers in a Pattern

A machine learning algorithm does not look at an email, a customer account, or a medical scan the way a person does. It receives numbers arranged in a predictable pattern, and everything it will ever know about a case has to pass through that arrangement. This is true whether the task is supervised, where the desired answer is known for training examples, or unsupervised, where the algorithm searches for structure without labels. In both cases the first practical question is the same: how do we write down our raw data so that a computer can reason about it?

What do you think happens?

Suppose a table of patient records has columns for age and blood pressure, but no column for gender. Can a model still predict gender from that table?

  • Yes, the algorithm will infer gender from the other columns

  • No, the algorithm can only use information that is present in the table

Reveal answer
Answer:

No, the algorithm can only use information that is present in the table.

The source makes this point directly: an algorithm can only make predictions from information that is present in the table, and a missing property cannot be recovered by the model. The rest of this article explains why that rule shapes every design decision about the table.

Rows, Columns, and the Table View

The answer used throughout introductory machine learning is to imagine the data as a table. Nearly every later idea in the field refers back to this picture, so it is worth holding it firmly in mind before looking at any algorithm. In the table view, each thing you want to reason about occupies one row. That thing might be an email, a customer, or a financial transaction. Each property that describes that thing occupies one column. A customer's age, a transaction's amount, and an email's sender location are all examples of properties that would become columns.

agefeature 1customer 1sample (row)34row 1, agegenderfeature 2customer 2sample (row)femalerow 1, genderaccount createdfeature 32019row 1, account createdpurchases per yearfeature 412row 1, purchases51row 2, agemalerow 2, gender2016row 2, account created3row 2, purchasesreads acrossreads across
Which parts of a dataset are the individual examples (rows) and which are the measured properties (columns), and where does each value sit?

The illustration above uses invented values to show the layout. Each customer is one row, so reading across row 1 tells you everything recorded about that customer. Each property is one column, so reading down the age column tells you the age of every customer in the table. The vocabulary follows this two-way reading: machine learning names samples by rows and features by columns.

Definition

A sample, also called a data point, is one row of the table and describes one entity. A feature is one column of the table and describes one property shared by all the entities.

Tracing an Online Shop Dataset

The clearest way to learn the sample and feature split is to start from a plain-language description and decide each part. The example below follows the pattern the source uses for an online shop that wants a model to reason about its customers.

Worked example

Sorting an online shop description into samples and features

An online shop wants a model that reasons about its customers. The team proposes using each customer's age, gender, the date their account was created, and how often they have bought from the shop. Identify the sample and the features.

  1. 1
    Decide what counts as a sample

    The first decision is what one entity is. Here each customer is one sample, so each customer gets one row in the table.

  2. 2
    List the properties that describe each sample

    The team has chosen four properties: age, gender, account creation date, and purchase frequency. Each describes a single customer.

  3. 3
    Map each property to a column

    Each chosen property becomes one feature, which means one column. The table therefore has one row per customer and four feature columns.

  4. 4
    Check the reading direction

    Reading down the age column gives the ages of all customers. Reading across one row gives everything recorded about one customer. The naming follows that same convention.

Result

Each customer is one sample (row). Age, gender, account creation date, and purchase frequency are the four features (columns). Choosing these four properties is a decision about which information the model is allowed to see.

The same method applies to non-customer data. A tumor image can be described in more than one way. The source gives two options. One uses the grayscale value of each pixel as a feature, so each image contributes many numeric columns. Another uses higher-level properties such as the tumor's size, shape, and color, which gives a much shorter list of columns. In both cases each tumor image is still one row. What changes is the set of columns, and that set is a decision about which properties the model will see.

Choosing Which Properties to Record

A table is only as useful as the information in it. An algorithm can only respond to properties it has been given. If a property is missing from the table, the algorithm has no way to recover it, no matter how sophisticated the method. This is the central constraint of the whole process: the columns you choose define the ceiling on what any model can learn from the data.

The source gives a useful illustration of how much a single added column can matter. Imagine a patient table that already has a few columns. Now add one more column: the patient's first name. The result changes a great deal, because a person's first name often reveals their gender. The model now has a column that carries real signal about the target. Nothing about the algorithm changed. Only the representation did.

The before and after tables contain the same patients and are read by the same algorithm. The only difference is one added column. This is why the source says the quality of the representation directly affects how well algorithms can predict.

From Raw Information to a Prediction

Choosing which properties to record is the beginning of a larger task. Building a good representation of your data is called feature extraction or feature engineering. It is the process of deciding how raw information should be turned into columns that help a model learn. The sample-and-feature table is the structure; feature engineering is the work of making that structure informative.

Raw informationemail, customer account,scanFeature extractionchoose propertiesFeature engineeringmake columns informativeSample and featuretablerows and columns of numbersLearning algorithmreads only the tablePredictionoutput for a new caseproperties chosenraw propertiesinformative columnsnumeric patternlearned pattern
What steps does raw data pass through before a prediction, and what does each step hand to the next?

Read the diagram from left to right. Raw information enters, and the chosen properties become columns. Feature engineering refines those columns so they carry useful signal. The finished table is the only thing the algorithm receives, so any information that did not survive this step cannot influence the prediction. The source treats this topic briefly and promises fuller treatment later in the book, so this article covers the core idea rather than every technique.

Judging Whether Features Are Enough

Once a table exists, the next question is whether it contains enough information for a useful prediction. A feature set that captures the relevant information lets the algorithm respond to the cases that matter. A feature set that omits the relevant information leaves the algorithm guessing from whatever remains. The same algorithm can succeed or fail depending only on which columns were recorded.

A practical check is to ask what the model would need to know to answer the question, and then ask whether that information is present in some column. If the answer depends on a property that appears nowhere in the table, the representation is incomplete, and no change to the algorithm can fix that.

Mistakes With Samples and Features

Beginners often make a small number of recurring errors when they first lay out a dataset. Each one comes from losing track of the sample and feature distinction described above.

  • Common mistake

    Treating each property as a sample

    What it looks like

    Making age a row and each customer a column

    Why it fails

    Rows are entities and columns are properties. Swapping them reverses the meaning of the table, so the model would read the data in the wrong direction.

    Do this instead

    Ask first what one entity is, then make that entity one row and make each property of it one column.

  • Common mistake

    Assuming the algorithm can recover a missing property

    What it looks like

    Expecting a model to know a customer's gender when no gender column exists

    Why it fails

    An algorithm can only make predictions from information present in the table. A missing property cannot be recovered by the model.

    Do this instead

    Check that every piece of information needed for the prediction has a column before training.

  • Common mistake

    Believing more columns always help

    What it looks like

    Adding every available field to a table without asking whether it relates to the question

    Why it fails

    The benefit comes from columns that carry real signal about the target. The source's first name example is useful because the name is related to gender.

    Do this instead

    Choose columns for the properties that relate to the prediction, and judge each addition by the information it provides.

  • Common mistake

    Confusing feature extraction with the algorithm itself

Sorting Samples and Features in Practice

MEDIUM

A library wants a model that predicts whether a book will be borrowed again. Each book in the catalog has a title, a publication year, a page count, a genre, and a count of past loans. Decide which parts are samples and which are features. Then name one property that the library does not currently record and explain whether its absence would limit the model.

Hints
  • Start by asking what one entity is. Each book is a natural candidate for one row.
  • Every descriptive property of a book that is stored in the catalog becomes a column, so the title, year, page count, genre, and loan count are candidate features.
  • For the missing property, ask whether the model would need that information to make a prediction about borrowing, and whether it could recover it from the table.

Key Takeaways

  • A learning algorithm reads only a structured table in which each row is one sample (an entity) and each column is one feature (a property of that entity).
  • Machine learning names samples by rows and features by columns, so reading down a column describes one property across all entities and reading across a row describes one entity.
  • An algorithm can only use information present in the table, so a missing property cannot be recovered by the model.
  • Feature extraction and feature engineering are the work of turning raw information into informative columns, and the quality of that representation directly affects how well predictions work.
  • A feature set is judged by whether its columns carry information relevant to the prediction, not by how many columns it contains.

Related concepts

More concepts starting with F