liveBook · Manning

Nonlinear mapping

As explained in Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI

A nonlinear transformation maps inputs to outputs in a way that cannot be represented as a linear function.

A nonlinear mapping transforms features into predictions through relationships that a straight-line model cannot represent. It matters when a feature’s effect changes across its range or when features interact. section 7.2.3 section 1.3

A linear baseline assigns each feature an unbounded contribution that simply increases or decreases with its value. This can create implausible results when domain patterns are conditional: many bedrooms may indicate a hostel, while a long minimum stay may indicate seasonal accommodation. section 7.2.3

Address nonlinear mappings through complementary approaches:

  • Engineer transformed features so a linear model can approximate nonlinear relationships, using relevant signals and domain knowledge. section 1.3
  • Use a model that represents nonlinearities and interactions directly when the baseline is too simple; XGBoost is used as the more sophisticated next model. section 7.2.3
  • Expect a trade-off: manual feature engineering requires problem knowledge, whereas deep learning can discover nonlinear dependencies through representation learning. section 1.3

Tokyo Airbnb prediction

A linear regression baseline produced negative predictions and extreme positive outliers. Inspecting individual feature contributions linked those errors to unusually high bedroom counts or minimum-night values, motivating nonlinearities and interactions. section 7.2.3

Listing 7.14 Linear regression baseline model with diagnostic plots
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import cross_val_predict
from sklearn.metrics import r2_score, mean_squared_error, mean_absolute_error
 
lm = LinearRegression(fit_intercept=False)                  #1
lm.fit(Xt, y)                                               #2
 
cv_splits = cv.split(
    X,
    y = X["neighbourhood_more_than_30"]
)                                                           #3
y_pred_cv = cross_val_predict(
    lm, Xt, y, cv=cv_splits
)                                                           #4
prediction_range = y_pred_cv.min()} - {y_pred_cv.max()
print(f"prediction range: {prediction_range}")              #5
 
r2 = r2_score(y, y_pred_cv)
rmse = np.sqrt(mean_squared_error(y, y_pred_cv))
mae = mean_absolute_error(y, y_pred_cv)                     #6
 
print(f'R-squared: {r2:.3f}')
print(f'RMSE: {rmse:.3f}')
print(f'MAE: {mae:.3f}')
 
plt.scatter(y, y_pred_cv)                                   #7
plt.plot([y.min(), y.max()], [y.min(), y.max()], 'r--', label='Ideal Fit')
plt.axhline(
   0, color='orange', linestyle='--', label='Zero Line'
)                                                           #8
plt.xlabel('Actual')
plt.ylabel('Predicted')
plt.title('Linear Regression - Fitted Results')
plt.legend()
plt.show()

Inspect the runnable linear-regression baseline, prediction range, diagnostics, and per-feature contributions that reveal where linear assumptions fail. section 7.2.3

How Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI covers it

How deep it goes
Contrasts linear contributions with practical outlier evidence, then recommends nonlinear models or engineered features without deriving their internals.
Examples
Uses Tokyo Airbnb prices, bedroom counts, minimum-night values, prediction outliers, and per-feature contribution diagnostics.
What it assumes
Assumes familiarity with tabular features and linear prediction while explaining nonlinearity through practical data patterns.
What you can do after
Diagnose/debug with it by identifying linear-model failures and selecting feature transformations or nonlinear models.
How it connects
Connects linear models, feature engineering, interactions, deep learning, representation learning, and gradient-boosted models.

Also explained in

Compare how 7 books explain nonlinear mapping →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI. The section links point to the parts of the book it draws on.