liveBook · Manning

Classifier

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

A classification problem is a prediction task in which the target is a class or label.

A classifier predicts a class or label rather than a continuous number. In binary classification, the target has two outcomes, such as whether an Airbnb listing’s price is above or below the median. Multiclass classification extends this idea to more than two labels. section 4.2 section 4.3.3

Start by choosing the target, then assemble predictors: the feature columns used to predict it. A continuous target can become a classifier target through a threshold, such as its mean or median, or through bins such as deciles. section 2.3 section 4.2

For a classifier, the target’s representation matters:

  • A logistic regression classifier produces a value from 0 to 1: the probability that a sample belongs to the positive class. section 4.3.3
  • A tabular fastai workflow must treat 0/1 targets as categories; numeric targets can cause the framework to select regression loss instead of cross-entropy. section 8.2.1
  • A binary prediction has a clear correctness threshold, while regression requires a continuous prediction close to the actual value. section 12.1

Classifying Airbnb listings by price band

Take listing features such as room type, neighborhood, and review data, then label each listing 1 when its price exceeds the median and 0 otherwise. Fit a processing pipeline and logistic regression, then evaluate accuracy with cross-validation. section 4.3.3 section 4.2

Listing 4.7 Logistic regression
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import make_scorer, accuracy_scorehttps://mng.bz/JY20
 
accuracy = make_scorer(accuracy_score)
cv = KFold(5, shuffle=True, random_state=0)
model = LogisticRegression(solver="saga",
                           penalty=None,
                           max_iter=1_000)                       #1
 
column_transform = ColumnTransformer(
    [('categories', categorical_onehot_encoding, low_card_categorical),
     ('numeric', numeric_standardization, continuous)],
    remainder='drop',
    verbose_feature_names_out=False,
    sparse_threshold=0.0)                                        #2
 
model_pipeline = Pipeline(
    [('processing', column_transform),
     ('modeling', model)])                                       #3
 
cv_scores = cross_validate(estimator=model_pipeline, 
                           X=data, 
                           y=target_median,
                           scoring=accuracy,
                           cv=cv, 
                           return_train_score=True,
                           return_estimator=True)                #4
 
mean_cv = np.mean(cv_scores['test_score'])
std_cv = np.std(cv_scores['test_score'])
fit_time = np.mean(cv_scores['fit_time'])
score_time = np.mean(cv_scores['score_time'])
print(f"{mean_cv:0.3f} ({std_cv:0.3f})", 
      f"fit: {fit_time:0.2f} secs pred: {score_time:0.2f} secs") #5

This pipeline pairs categorical encoding and numeric standardization with LogisticRegression, then evaluates the binary classifier through cross-validation. section 4.3.3

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

How deep it goes
Explains binary, multiclass, and multilabel use through logistic regression and target typing, without deriving its statistical functions.
Examples
Uses Airbnb prices split at the median, sklearn logistic-regression pipelines, and a fastai 0/1 target converted to strings.
What it assumes
Assumes a tabular dataset and a business objective, then teaches selecting a target before assembling predictor features.
What you can do after
Apply it via scikit-learn or fastai by defining a categorical target, preparing features, fitting a model, and checking accuracy or loss.
How it connects
Connects classification to targets, predictors, feature processing, logistic regression, cross-validation, accuracy, regression, and cross-entropy.

Also explained in

Compare how 31 books explain classifier →

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.