Continuous Features
A continuous feature is numerical and can take on any value within a range, such as age or hours-per-week in the adult dataset.
A Worker Record and a Prediction Task
Imagine a program that looks at a record about one working adult and predicts whether that person earns more than 50,000 dollars a year or not. Each record describes one person through several pieces of information: how old they are, how many hours they work each week, what kind of employer they have, what their education level is, and what their occupation is. Before any learning algorithm can use these pieces of information, we need to understand what kind of information each one is. That distinction is the subject of this article.
The example dataset comes from adult income records in the United States, derived from a 1994 census database. The prediction task is a classification task: each worker belongs to one of two classes, income at most 50K or income above 50K. Predicting the exact income amount would instead be a regression task, which the source notes would be much harder. Keep this two-class setting in mind, because it is the context in which the categorical question becomes important.
What do you think happens?
Is the age of a worker a number that can fall anywhere along a scale, or a choice from a short menu of named options?
Reveal answer
A number that can fall anywhere along a scale
Age is a quantity. It answers the question how old, with a numerical value that can sit at any point within a range. That makes it a continuous feature.
Tracing One Record Column by Column
Read each column of the dataset as a question you could ask about every worker. Some columns answer a question with a number that can fall anywhere along a scale. Other columns answer a question by choosing one item from a short menu of named options. Each column in a dataset is called a feature, so the task is to decide which features behave like a scale and which behave like a menu.
Reading one worker record
A record describes a worker with age 37, hours-per-week 40, workclass Private, and education Bachelors. For each column, decide what question it answers and what kind of feature it is.
- 1Look at age
The value 37 is a count of years. It is a number, and a worker could just as well be 37.5 years old. Age therefore answers how much and is continuous.
- 2Look at hours-per-week
The value 40 is an amount of time worked each week. It sits on a numerical scale that can take any value in a range. Hours-per-week answers how many and is continuous.
- 3Look at workclass
The value Private is a named kind of employer. It is one item chosen from a fixed list of options, so it answers which one applies and is categorical.
- 4Look at education
The value Bachelors is a named education level. It is one option from a fixed list, describing a qualitative property rather than an amount, so it is categorical.
Age and hours-per-week are continuous features. Workclass and education are categorical features.
Two Questions: How Much Versus Which One
The two kinds of feature are separated by the meaning of their values. Two definitions capture the difference. The first is the continuous feature, and the second is the categorical variable. Each definition turns on a different question, and the two questions are not interchangeable.
Sorting the Adult Dataset Columns
The diagram below groups the features of the adult dataset into the two kinds. Notice that the grouping depends only on what each column means, not on whether its entries happen to be written with digits or with words. An age written as digits is still continuous, and a workclass written as words is still categorical.
Why the Model Cannot Multiply a Word
The source uses logistic regression as the starting point for the learning task. Logistic regression makes its prediction from a weighted sum of the input features. Each feature is multiplied by its own coefficient learned from the training set, the results are added together, and a constant term $b$ is included. Written with coefficients $w_1, w_2, \ldots, w_n$ for features $x_1, x_2, \ldots, x_n$, the sum has the form $w_1 x_1 + w_2 x_2 + \cdots + w_n x_n + b$.
This arithmetic only makes sense when each input is a number. For the age column, the term $w_1 x_1$ multiplies a coefficient by a real quantity, which is meaningful. For the education column, the input is the word Masters or Bachelors. A categorical value such as that cannot be multiplied by a coefficient in any meaningful way. The source makes exactly this point: the formula works when the inputs are numbers, but not when an input is a word. The data therefore has to be represented in some different way before logistic regression can be applied. The course explains that representation in its next step.
Mistakes Learners Make With Feature Types
Common mistake Deciding a feature's type from whether its entries look like digits
What it looks likeAssuming a column is numerical because it is written with numerals, or categorical because it is written with words.
Why it failsThe grouping depends only on what each column means. What matters is whether the feature answers how much or which one.
Do this insteadAsk what question the column answers about each worker. A numerical amount that can take any value in a range is continuous, and a choice from a fixed list of named options is categorical.
Common mistake Treating a categorical label as if it were a number on a scale
What it looks likeFeeding the word Bachelors straight into the weighted sum as if it were a quantity.
Why it failsA categorical variable describes a qualitative property, so multiplying its raw label by a coefficient has no meaningful result.
Do this insteadRecognize that categorical values must be represented differently before logistic regression can use them.
Common mistake Assuming a continuous feature can only take whole numbers
Why it failsA continuous feature can take on any point within a range, not only integers.
Do this insteadThink of age as a value that could sit anywhere along a scale, not only as a whole count of years.
Sorting Your Own Columns
Consider four columns from the adult dataset: age, workclass, hours-per-week, and occupation. For each one, state whether it is continuous or categorical, and say which question it answers about a worker.
Hints
- Ask whether the column answers how much or how many, or whether it answers which one of a fixed list applies.
- Age and hours-per-week are the continuous columns named in the source. Workclass and occupation are categorical columns named in the source.
A dataset has a column recording the number of years a worker has been employed, a column recording the employer type chosen from a fixed list, and a column recording the worker's education level from a fixed list. Which of these columns are continuous, and which are categorical? Justify each answer with the question the column answers.
Hints
- Years of employment is a quantity that can take any value in a range.
- Choosing one item from a fixed list describes a qualitative property.
Putting the Two Kinds Together
- 1A continuous feature is numerical and can take on any point within a range; in the adult dataset, age and hours-per-week are continuous.
- 2A categorical variable takes values from a fixed list of options and describes a qualitative property; workclass, education, sex, and occupation are categorical in the adult dataset.
- 3Continuous features answer how much or how many, while categorical variables answer which one of the listed options applies.
- 4Logistic regression computes a weighted sum of numeric inputs, so categorical values must be represented differently before the model can use them.
Key Takeaways
- A continuous feature is numerical and can take on any point within a range, such as age or hours-per-week in the adult dataset.
- A categorical variable takes values from a fixed list of options and describes a qualitative property rather than a quantity.
- Sorting a column comes down to asking whether it answers how much or which one of a fixed set of options applies.
- Logistic regression uses a weighted sum of numeric inputs, so categorical values must be represented differently before the model can use them.