Feature engineering
Feature engineering means creating, transforming, or selecting the inputs a machine learning model uses. For example, you might turn a purchase date into the number of days since the customer last bought something.
Also known as: признаки, фичи
What is feature engineering?
A feature is a piece of information a model receives as input. If you're predicting whether a subscription customer will cancel in the next 30 days, features might include the number of days they used the service last week and how long they've been a customer. Whether they actually cancel is the target: it tells the model what to learn during training, but it isn't an input at prediction time.
Feature engineering turns raw records into inputs that suit the task and the model. A log of hundreds of page views, for instance, can become a count of active days. That count captures a pattern that a tabular model couldn't directly read from a list of events.
How it works
Start by deciding what one prediction is about and when it's made. For a churn model scored every Monday, one training row might represent one customer as of Monday morning. From there, you can count events over a fixed window, derive a day of the week from a timestamp, or encode a category such as a subscription plan. Which transformations help depends on the algorithm: scaling can keep a large-unit variable from dominating distances in k-nearest neighbors, while a decision tree generally doesn't need it.
To see whether a feature helps, compare models with and without it using the same validation splits and metric. An improvement on the training set alone isn't enough.
Example: forecasting daily sales
A store forecasts each morning how many units of a product it will sell that day. Two candidate features are yesterday's sales and the average sales over the previous seven days. In Pandas, given one product and one row per calendar day sorted by date:
past_sales = df['units_sold'].shift(1)
df['sales_yesterday'] = past_sales
df['sales_avg_7d'] = past_sales.rolling(7).mean()
Shifting before taking the average keeps today's sales out of both features: today's total is what you're trying to predict. With multiple products, calculate the shift and rolling average separately for each product. Also check when the numbers arrive. If yesterday's total isn't posted until noon, it's not a valid input for a morning forecast.
Where it's used and what can go wrong
Feature engineering is common in tabular problems such as demand forecasting, recommendations, and churn prediction. Neural networks can learn much of their own representation from images or text, but you still have to decide what information the model can access when it makes a prediction.
A subtle form of data leakage is filling missing values with a median calculated before splitting the data. This lets the validation set influence training. Fit any transformation that learns from data on the training portion of each split, then apply it to the validation portion. Once the model is deployed, keep feature definitions consistent with training: a seven-day window shouldn't silently become a calendar-week total.
How it comes up in interviews
You may be asked to propose features for a forecasting problem and spot ones that leak information. For each feature, explain when it becomes available and what you'd do if it were missing. Then describe a fair test: for daily sales, train on an earlier period and compare a baseline with the new feature on the same later period.