BitSize Python · Machine Learning
Teach a machine by example.
Every scikit-learn program is one pipeline. Each lesson adds one block.
Part 1 · Foundations · about 12 min · free
Your pipeline
Every scikit-learn program is these six slots. Each lesson adds a block to your toolbox; pass it and the block lights up.
- Dataload, X and y 0 / 3
- Splittrain / test 0 / 2
- Prepareclean, encode, scale 0 / 14
- Modelfit 0 / 46
- Evaluatepredict, score 0 / 19
- Tunesearch the knobs 0 / 6
Data0 / 3
Split0 / 2
Prepare0 / 14
Model0 / 46
Evaluate0 / 19
Tune0 / 6
Foundations
Your first model, X and y, the kinds of learning, a fair test, over- and underfitting, validation.
- 01 Your first modelKNeighborsClassifier · fit · predict Up next
- 02 X and yX · y · .shape · features & labels Free account
- 03 Kinds of learningLinearRegression · KNeighborsRegressor · KMeans Free account
- 04 A fair testtrain_test_split · score 🔒 Subscribe
- 05 Too simple, too wigglymake_moons · train vs test score 🔒 Subscribe
- 06 Validation and hyperparameterstrain · validation · test · hyperparameters 🔒 Subscribe
A project, end to end
One housing dataset from raw table to tuned, saved model: cleaning, encoding, scaling, pipelines, cross-validation, search.
- 07 Frame the problemmean_squared_error · mean_absolute_error · RMSE 🔒 Subscribe
- 08 First look at the datainfo · describe · value_counts · hist 🔒 Subscribe
- 09 A fair test set, stratifiedpd.cut · stratify 🔒 Subscribe
- 10 Explore: maps, correlations, new featurescorr · combined features 🔒 Subscribe
- 11 Missing valuesSimpleImputer · fit · transform 🔒 Subscribe
- 12 Text categoriesOneHotEncoder · OrdinalEncoder 🔒 Subscribe
- 13 Your own transformerFunctionTransformer · BaseEstimator · TransformerMixin 🔒 Subscribe
- 14 Feature scalingStandardScaler · MinMaxScaler 🔒 Subscribe
- 15 PipelinesPipeline · make_pipeline · ColumnTransformer 🔒 Subscribe
- 16 Compare models with cross-validationcross_val_score · DecisionTreeRegressor · RandomForestRegressor 🔒 Subscribe
- 17 Tune: grid and randomized searchGridSearchCV · RandomizedSearchCV · best_params_ 🔒 Subscribe
- 18 Finish the jobfinal test · joblib · monitoring 🔒 Subscribe
Classification
Binary and many-class classifiers, the confusion matrix, precision and recall, the threshold dial, ROC.
- 19 A yes/no classifierload_digits · SGDClassifier · decision_function 🔒 Subscribe
- 20 Accuracy can lieDummyClassifier · cross_val_score(scoring="accuracy") 🔒 Subscribe
- 21 The confusion matrixconfusion_matrix · cross_val_predict 🔒 Subscribe
- 22 Precision, recall, F1precision_score · recall_score · f1_score 🔒 Subscribe
- 23 The threshold dialpredict_proba · precision_recall_curve · threshold 🔒 Subscribe
- 24 ROC and AUCroc_curve · roc_auc_score 🔒 Subscribe
- 25 Many classesOneVsRestClassifier · OneVsOneClassifier · classes_ 🔒 Subscribe
- 26 Error analysisconfusion_matrix(normalize=…) · cross_val_predict 🔒 Subscribe
- 27 Multilabel and multioutputKNeighborsClassifier (multilabel) · multioutput 🔒 Subscribe
Training linear models
The normal equation, gradient descent, polynomial features, learning curves, Ridge, Lasso, logistic and softmax.
- 28 Linear regression, solvedLinearRegression · coef_ · normal equation 🔒 Subscribe
- 29 Gradient descentlearning rate · gradient · epochs 🔒 Subscribe
- 30 Batch, stochastic, mini-batchSGDRegressor · epochs · partial_fit 🔒 Subscribe
- 31 Polynomial regressionPolynomialFeatures · degree 🔒 Subscribe
- 32 Learning curveslearning_curve · train_sizes 🔒 Subscribe
- 33 RidgeRidge · alpha 🔒 Subscribe
- 34 LassoLasso · alpha · coef_ == 0 🔒 Subscribe
- 35 Elastic NetElasticNet · l1_ratio 🔒 Subscribe
- 36 Early stoppingSGDRegressor · early_stopping · n_iter_no_change 🔒 Subscribe
- 37 Logistic regressionLogisticRegression · predict_proba · sigmoid 🔒 Subscribe
- 38 Decision boundariesLogisticRegression · C · decision boundary 🔒 Subscribe
- 39 Softmax regressionLogisticRegression (multinomial) · softmax · predict_proba 🔒 Subscribe
Support vector machines
The widest street, soft margins, kernels, SVM regression and what happens under the hood.
- 40 The widest streetSVC(kernel="linear") · support_ 🔒 Subscribe
- 41 Soft marginC · StandardScaler 🔒 Subscribe
- 42 Curved boundariesPolynomialFeatures + LinearSVC · SVC(kernel="poly") 🔒 Subscribe
- 43 The RBF kernelSVC(kernel="rbf") · gamma · C 🔒 Subscribe
- 44 SVM regressionSVR · epsilon · LinearSVR 🔒 Subscribe
- 45 SVMs under the hooddecision_function · hinge loss · kernel trick 🔒 Subscribe
Decision trees
Growing and reading a tree, how it splits, reining it in, regression trees, instability.
- 46 Grow a treeDecisionTreeClassifier · export_text · plot of the tree 🔒 Subscribe
- 47 How a tree decidespredict_proba · gini · CART 🔒 Subscribe
- 48 Rein in the treemax_depth · min_samples_leaf · max_leaf_nodes 🔒 Subscribe
- 49 Regression treesDecisionTreeRegressor · squared error 🔒 Subscribe
- 50 Unstable treesrandom_state · rotation · variance 🔒 Subscribe
Ensembles
Voting, bagging, random forests, feature importance, AdaBoost, gradient boosting, stacking.
- 51 VotingVotingClassifier · hard · soft 🔒 Subscribe
- 52 Bagging and pastingBaggingClassifier · bootstrap · oob_score 🔒 Subscribe
- 53 Random forests and extra-treesRandomForestClassifier · max_features · ExtraTreesClassifier 🔒 Subscribe
- 54 Feature importancefeature_importances_ · permutation_importance 🔒 Subscribe
- 55 AdaBoostAdaBoostClassifier · learning_rate · stumps · staged_score 🔒 Subscribe
- 56 Gradient boostingGradientBoostingRegressor · learning_rate · n_iter_no_change · HistGradientBoostingRegressor 🔒 Subscribe
- 57 StackingStackingClassifier · final_estimator · cross_val_predict 🔒 Subscribe
Dimensionality reduction
The curse of dimensionality, PCA and explained variance, compression, kernel PCA, manifold maps.
- 58 The curse of dimensionalityNumPy simulation · make_swiss_roll · projection vs manifold 🔒 Subscribe
- 59 PCAPCA · components_ · explained_variance_ratio_ 🔒 Subscribe
- 60 How many components?explained_variance_ratio_ · cumsum · PCA(n_components=0.95) 🔒 Subscribe
- 61 Compress and restoreinverse_transform · reconstruction error · IncrementalPCA · svd_solver="randomized" 🔒 Subscribe
- 62 Kernel PCAKernelPCA · kernel · gamma 🔒 Subscribe
- 63 Manifold mapsLocallyLinearEmbedding · TSNE 🔒 Subscribe
Unsupervised learning
K-Means, choosing k, DBSCAN, Gaussian mixtures, semi-supervised labels, anomaly detection.
- 64 What clustering is forKMeans · labels_ · no y 🔒 Subscribe
- 65 K-Means, step by stepKMeans · inertia_ · k-means++ 🔒 Subscribe
- 66 Choosing kinertia_ · silhouette_score · elbow 🔒 Subscribe
- 67 Where K-Means failsmake_blobs · MiniBatchKMeans 🔒 Subscribe
- 68 Clustering at workKMeans on colours · cluster distances as features 🔒 Subscribe
- 69 Few labelsLabelPropagation · LabelSpreading · representative points 🔒 Subscribe
- 70 DBSCANDBSCAN · eps · min_samples 🔒 Subscribe
- 71 Gaussian mixturesGaussianMixture · predict_proba · covariance_type 🔒 Subscribe
- 72 Anomalies and model choice with mixturesscore_samples · bic · BayesianGaussianMixture 🔒 Subscribe
- 73 Other anomaly findersIsolationForest · LocalOutlierFactor · OneClassSVM 🔒 Subscribe
Case files
Open problems end to end: churn, house prices, customer groups, odd transactions, digits.
- 74 Case file: who will cancel?pipeline · cost-based threshold · AUC 🔒 Subscribe
- 75 Case file: price the homeColumnTransformer · HistGradientBoosting · RMSE 🔒 Subscribe
- 76 Case file: find the customer groupsStandardScaler · KMeans · silhouette · GaussianMixture 🔒 Subscribe
- 77 Case file: catch the odd transactionIsolationForest · LocalOutlierFactor · review budget 🔒 Subscribe
- 78 Case file: read the digitsPipeline · PCA · SVC · GridSearchCV · confusion matrix 🔒 Subscribe