Can you explain this result?
kfold = KFold(n_splits=3)
cross_val_score(logistic_regression, iris.data, iris.target, cv=kfold)
Cross-validation scores KFold(n_splits=3): [0. 0. 0.]
train_size
) points randomly as the training settest_size
), handy with very large datasetstrain_size=0.66
, test_size=0.34
but without duplicatesWhen the data is ordered, random test sets are not a good idea
TimeSeriesSplit
No strict rules, only guidelines:
Each algorithm optimizes a given objective function (on the training data)
The choice of function is limited by what can be efficiently optimized
Predicted Neg | Predicted Pos | |
---|---|---|
Actual Neg | TN | FP |
Actual Pos | FN | TP |
confusion_matrix(y_test, y_pred): [[48 5] [ 5 85]]
Comparison
Classification measure Zoo
Train models per class : one class viewed as positive, other(s) als negative, then average
micro-averaging: count total TP, FP, TN, FN (every sample equally important)
macro-averaging: average of scores $R(y_c,\hat{y_c})$ obtained on each class
Remember that linear models actually return a numeric value.
In practice, you are often interested in how certain a classifier is about each class prediction (e.g. cancer treatments).
In the binary classification case, the return value of the decision function encodes how strongly the model believes a data point belongs to the “positive” class.
Some models can also return a probability for each class with every prediction. These sum up to 1. We can visualize them again. Note that the gradient looks different now.
decision_function
and 0.5 for predict_proba
interactive(children=(FloatSlider(value=2.220446049250313e-16, description='threshold', max=1.3, min=-1.2), Ou…
interactive(children=(FloatSlider(value=-0.9899999999999998, description='threshold', max=1.4, min=-3.19), Dro…
Of course, hyperparameters affect predictions and hence also the shape of the curve
interactive(children=(FloatSlider(value=-0.9899999999999998, description='threshold', max=1.4, min=-3.19), Dro…
interactive(children=(FloatSlider(value=0.0, description='threshold', max=2.0, min=-2.0), Output()), _dom_clas…
Logistic Regression Brier score loss: 0.0322 SVM Brier score loss: 0.0795
interactive(children=(FloatSlider(value=5.0, description='cost_FN', max=10.0, min=1.0, step=1.0), FloatSlider(…
Most commonly used are
Summary Flowchart (by Andrew Ng)
hps = {'C': expon(scale=100), 'gamma': expon(scale=.1)}
scores = cross_val_score(RandomizedSearchCV(SVC(), hps, cv=3), X, y, cv=5)