Machine Learning/Data Science Interview
Cheat sheets
Aqeel Anwar
Version: 0.1.0.1
This document contains cheat sheets on various topics asked during a Machine Learn-
ing/Data science interview. This document is constantly updated to include more topics.
Click here to get the updated version
Table of Contents
Machine Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1. Bias-Variance Trade-off . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Publicité
2. Imbalanced Data in Classification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3. Principal Component Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4. Bayes’ Theorem and Classifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
5. Regression Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
6. Regularization in ML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
7. Convolutional Neural Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
8. Famous CNNs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
9. Ensemble Methods in Machine Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Behavioral Interview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1. How to prepare for behavioral interview? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
Publicité
2. How to answer a behavioral question? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Page 1 of 15
Page 2 of 15
(cid:78)(cid:66)(cid:98)(cid:83)(cid:32)(cid:36)(cid:115)(cid:82)(cid:60)(cid:36)(cid:27)(cid:89)(cid:83)(cid:32)(cid:36)(cid:115)(cid:82)(cid:78)(cid:66)(cid:98)(cid:83)(cid:122)(cid:115)(cid:132)(cid:36)(cid:115)(cid:116)(cid:123)(cid:130)(cid:60)(cid:36)(cid:27)(cid:89)(cid:83)(cid:122)(cid:115)(cid:132)(cid:36)(cid:115)(cid:116)(cid:123)(cid:130)(cid:60)(cid:36)(cid:27)(cid:89)(cid:83)(cid:32)(cid:36)(cid:115)(cid:82)(cid:78)(cid:66)(cid:98)(cid:83)(cid:122)(cid:115)(cid:132)(cid:36)(cid:115)(cid:116)(cid:123)(cid:130)(cid:78)(cid:66)(cid:98)(cid:83)(cid:32)(cid:36)(cid:115)(cid:82)(cid:60)(cid:36)(cid:27)(cid:89)(cid:83)(cid:122)(cid:115)(cid:132)(cid:36)(cid:115)(cid:116)(cid:123)(cid:130)(cid:61)(cid:116)(cid:73)(cid:130)(cid:132)(cid:84)(cid:80)(cid:36)(cid:28)(cid:28)(cid:36)(cid:116)(cid:27)(cid:33)(cid:37)(cid:130)(cid:132)(cid:84)(cid:80)(cid:36)(cid:28)(cid:28)(cid:36)(cid:116)(cid:27)(cid:70)(cid:90)(cid:82)(cid:28)(cid:83)(cid:105)(cid:36)(cid:27)(cid:89)(cid:28)(cid:32)(cid:36)(cid:115)(cid:82)(cid:122)(cid:115)(cid:132)(cid:36)(cid:115)(cid:116)(cid:123)(cid:130)(cid:101)(cid:132)(cid:132)(cid:66)(cid:132)(cid:95)(cid:132)(cid:130)(cid:80)(cid:130)(cid:132)(cid:132)(cid:130)(cid:73)(cid:83)(cid:36)(cid:80)(cid:83)(cid:82)(cid:36)(cid:57)(cid:130)(cid:83)(cid:66)(cid:80)(cid:83)(cid:73)(cid:115)(cid:28)(cid:115)(cid:82)(cid:130)(cid:28)(cid:83)(cid:36)(cid:82)(cid:83)(cid:82)(cid:56)(cid:115)(cid:106)(cid:106)(cid:95)(cid:132)(cid:130)(cid:80)(cid:130)(cid:132)(cid:132)(cid:130)(cid:73)(cid:83)(cid:36)(cid:80)(cid:83)(cid:82)(cid:36)(cid:57)(cid:130)(cid:83)(cid:66)(cid:80)(cid:83)(cid:73)(cid:115)(cid:28)(cid:115)(cid:82)(cid:130)(cid:28)(cid:83)(cid:36)(cid:82)(cid:83)(cid:106)(cid:115)(cid:132)(cid:27)(cid:130)What is Bias?•Error between average model prediction and ground truth•The bias of the estimated function tells us the capacity of the underlying model to predict the valuesWhat is Variance?•Average variability in the model prediction for the given dataset•The variance of the estimated function tells you how much the function can adjust to the change in the datasetHigh BiasHigh VarianceOverly-simplified ModelUnder-fittingHigh error on both test and train dataOverly-complex ModelOver-fittingLow error on train data and high on testStarts modelling the noise in the inputBias variance Trade-off•Increasing bias reduces variance and vice-versa•Error = bias2+ variance +irreducible error•The best model is where the error is reduced.•Compromise between bias and varianceCheat Sheet –Bias-Variance TradeoffSource: https://www.cheatsheets.aqeel-anwar.comMinimum ErrorPage 3 of 15
Source: https://www.cheatsheets.aqeel-anwar.comClassifier that always predicts label blue yields prediction accuracy of 90%Blue: Label 1Green: Label 0Accuracy =Correct PredictionsTotal PredictionsCheat Sheet –Imbalanced Data in ClassificationAccuracy= TPTN+TPFN+FPTN++TPTPFN+Recall, Sensitivity=True +verateTrue PositiveFalse PositiveFalse NegativeTrue NegativeActual Labels10Predicted Labels01TNTNFP+Specificity = TPTPFP+Precision= FPTNFP+False +verate = F1 score = 2x(Prec+ Rec) (Precx Rec) (Is your prediction correct?) (What did you predict)True Negative(Your prediction is correct) (You predicted 0)Performance metrics associated with Class 1Accuracy: %age correct prediction Correct prediction over total predictionsOne value for entire networkPrecision: Exactnessof modelFrom the detected cats, how many were Each class/label has a valueactually catsRecall: Completenessof modelCorrectly detected cats over total catsEach class/label has a valueF1 Score: Combines Precision/RecallHarmonic mean of Precision and RecallEach class/label has a valueAccuracy doesn’t always give the correct insight about your trained modelPossible solutions1.Data Replication: Replicate the available data until the number of samples are comparable2.Synthetic Data: Images: Rotate, dilate, crop, add noise to existing input images and create new data3.Modified Loss: Modify the loss to reflect greater error when misclassifying smaller sample setBlue: Label 1Green: Label 0No straight line (y=ax) passing through origin can perfectly separate data. Best solution: line y=0, predict all labels blueStraight line (y=ax+b) can perfectly separate data.Green class will no longer be predicted as blueIncrease model complexity𝑙𝑜𝑠𝑠=𝑎∗𝒍𝒐𝒔𝒔𝒈𝒓𝒆𝒆𝒏+𝑏∗𝒍𝒐𝒔𝒔𝒃𝒍𝒖𝒆𝑎>𝑏Blue: Label 1Green: Label 04.Change the algorithm: Increase the model/algorithm complexity so that the two classes are perfectly separable (Con: Overfitting)Source: https://www.cheatsheets.aqeel-anwar.comPage 4 of 15
Source: https://www.cheatsheets.aqeel-anwar.comCheat Sheet –PCA Dimensionality ReductionFeature # 1 (F1)Feature # 2 (F2)VarianceF2F1Feature # 2Feature # 1New Feature # 1New Feature # 2VarianceF2F1VarianceF2F2Feature # 2Feature # 1New Feature # 1New Feature # 2What is PCA?•Based on the dataset find a new set of orthogonal feature vectors in such a way that the data spread is maximum in the direction of the feature vector (or dimension)•Rates the feature vector in the decreasing order of data spread (or variance)•The datapoints have maximum variance in the first feature vector, and minimum variance in the last feature vector•The variance of the datapoints in the direction of feature vector can be termed as a measure of information in that direction.Steps1.Standardize the datapoints2.Find the covariance matrix from the given datapoints3.Carry out eigen-value decomposition of the covariance matrix4.Sort the eigenvalues and eigenvectorsDimensionality Reduction with PCA•Keep the first m out of n feature vectors rated by PCA. These m vectors will be the best m vectors preserving the maximum information that could have been preserved with m vectors on the given datasetSteps:1.Carry out steps 1-4 from above2.Keep first m feature vectors from the sorted eigenvector matrix3.Transform the data for the new basis (feature vectors)4.The importance of the feature vector is proportional to the magnitude of the eigen valueFigure 1: Datapoints with feature vectors as x and y-axisFigure 2: The cartesian coordinate system is rotated to maximize the standard deviation along any one axis (new feature # 2)Figure 3: Remove the feature vector with minimum standard deviation of datapoints (new feature # 1) and project the data on new feature # 2Figure 2Figure 1Figure 3Source: https://www.cheatsheets.aqeel-anwar.comPage 5 of 15
Source: https://www.cheatsheets.aqeel-anwar.comSource: https://www.cheatsheets.aqeel-anwar.comCheat Sheet –Bayes Theorem and ClassifierWhat is Bayes’Theorem?•Describestheprobabilityofanevent,basedonpriorknowledgeofconditionsthatmightberelatedtotheevent.LikelihoodPrior ProbabilityEvidenceBayes’TheoremPosterior ProbabilityP(B A)P(A B)P(A)P(B)Example•Probability of fire P(F) = 1%•Probability of smoke P(S) = 10%•Prob of smoke given there is a fire P(S F) = 90%•What is the probability that there is a fire given we see a smoke P(F S)?•HowtheprobabilityofaneventchangeswhenwehaveknowledgeofanothereventP(A)P(AB)Usually, a better estimate than P(A)Maximum AposterioriProbability (MAP) EstimationTheMAPestimateoftherandomvariabley,giventhatwehaveobservediid(x1,x2,x3,…),isgivenby.Wetrytoaccommodateourpriorknowledgewhenestimating.Maximum Likelihood Estimation (MLE)TheMAPestimateoftherandomvariabley,giventhatwehaveobservediid(x1,x2,x3,…),isgivenby.Weassumewedon’thaveanypriorknowledgeofthequantitybeingestimated.MLE is a special case of MAP where our prior is uniform (all values are equally likely)Naïve Bayes’Classifier (Instantiation of MAP as classifier)Suppose we have two classes, y=y1and y=y2. Say we have more than one evidence/features (x1, x2, x3, …), using Bayes’theoremBayes’theorem assumes the features (x1, x2, x3, …) are i.i.d. i.eMAPMLEˆˆy that maximizes the product of priorand likelihoody that maximizes only the likelihoodPage 6 of 15
Source: https://www.cheatsheets.aqeel-anwar.comCheat Sheet –Regression AnalysisWhatisRegressionAnalysis?Fittingafunctionf(.)todatapointsyi=f(xi)undersomeerrorfunction.Basedontheestimatedfunctionanderror,wehavethefollowingtypesofregressionWhat does it fit?Estimated functionError FunctionLinearA line in n dimensionsPolynomialA polynomial of order kBayesian LinearGaussian distribution for each pointRidgeLinear/polynomialLASSOLinear/polynomialLogisticLinear/polynomial with sigmoidyxLinear RegressionyxPolynomial RegressionyxLogistic RegressionLabel 1Label 0yxBayesian Linear Regression1.LinearRegression:Fitsalineminimizingthesumofmean-squarederrorforeachdatapoint.2.PolynomialRegression:Fitsapolynomialoforderk(k+1unknowns)minimizingthesumofmean-squarederrorforeachdatapoint.3.BayesianRegression:Foreachdatapoint,fitsagaussiandistributionbyminimizingthemean-squarederror.Asthenumberofdatapointsxiincreases,itconvergestopointestimatesi.e.4.RidgeRegression:Canfiteitheraline,orpolynomialminimizingthesumofmean-squarederrorforeachdatapointandtheweightedL2normofthefunctionparametersbeta.5.LASSORegression:Canfiteitheraline,orpolynomialminimizingthethesumofmean-squarederrorforeachdatapointandtheweightedL1normofthefunctionparametersbeta.6.LogisticRegression:Canfiteitheraline,orpolynomialwithsigmoidactivationminimizingthebinarycross-entropylossforeachdatapoint.Thelabelsyarebinaryclasslabels.VisualRepresentation:Summary:Page 7 of 15
Source: https://www.cheatsheets.aqeel-anwar.comCheat Sheet –Regularization in MLTypesofRegularization:1.Modifythelossfunction:•L2Regularization:Preventstheweightsfromgettingtoolarge(definedbyL2norm).Largertheweights,morecomplexthemodelis,morechancesofoverfitting.•L1Regularization:Preventstheweightsfromgettingtoolarge(definedbyL1norm).Largertheweights,morecomplexthemodelis,morechancesofoverfitting.L1regularizationintroducessparsityintheweights.Itforcesmoreweightstobezero,thanreducingthetheaveragemagnitudeofallweights•Entropy:Usedforthemodelsthatoutputprobability.Forcestheprobabilitydistributiontowardsuniformdistribution.2.Modifydatasampling:•Dataaugmentation:Createmoredatafromavailabledatabyrandomlycropping,dilating,rotating,addingsmallamountofnoiseetc.•K-foldCross-validation:Dividethedataintokgroups.Trainon(k-1)groupsandteston1group.Tryallkpossiblecombinations.3.Changetrainingapproach:•Injectingnoise:Addrandomnoisetotheweightswhentheyarebeinglearned.Itpushesthemodeltoberelativelyinsensitivetosmallvariationsintheweights,henceregularization•Dropout:Generallyusedforneuralnetworks.Connectionsbetweenconsecutivelayersarerandomlydroppedbasedonadropout-ratioandtheremainingnetworkistrainedinthecurrentiteration.Inthenextiteration,anothersetofrandomconnectionsaredropped.What is Regularization in ML?•Regularizationisanapproachtoaddressover-fittinginML.•Overfittedmodelfailstogeneralizeestimationsontestdata•Whentheunderlyingmodeltobelearnedislowbias/highvariance,orwhenwehavesmallamountofdata,theestimatedmodelispronetoover-fitting.•Regularizationreducesthevarianceofthemodel(cid:60)(cid:36)(cid:27)(cid:89)(cid:83)(cid:32)(cid:36)(cid:115)(cid:82)(cid:78)(cid:66)(cid:98)(cid:83)(cid:122)(cid:115)(cid:132)(cid:36)(cid:115)(cid:116)(cid:123)(cid:130)(cid:78)(cid:66)(cid:98)(cid:83)(cid:32)(cid:36)(cid:115)(cid:82)(cid:60)(cid:36)(cid:27)(cid:89)(cid:83)(cid:122)(cid:115)(cid:132)(cid:36)(cid:115)(cid:116)(cid:123)(cid:130)(cid:61)(cid:116)(cid:73)(cid:130)(cid:132)(cid:84)(cid:80)(cid:36)(cid:28)(cid:28)(cid:36)(cid:116)(cid:27)(cid:33)(cid:37)(cid:130)(cid:132)(cid:84)(cid:80)(cid:36)(cid:28)(cid:28)(cid:36)(cid:116)(cid:27)(cid:70)(cid:90)(cid:82)(cid:28)(cid:83)(cid:105)(cid:36)(cid:27)(cid:89)(cid:28)(cid:32)(cid:36)(cid:115)(cid:82)(cid:122)(cid:115)(cid:132)(cid:36)(cid:115)(cid:116)(cid:123)(cid:130)(cid:101)(cid:132)(cid:132)(cid:66)(cid:132)(cid:95)(cid:132)(cid:130)(cid:80)(cid:130)(cid:132)(cid:132)(cid:130)(cid:73)(cid:83)(cid:36)(cid:80)(cid:83)(cid:82)(cid:36)(cid:57)(cid:130)(cid:83)(cid:66)(cid:80)(cid:83)(cid:73)(cid:115)(cid:28)(cid:115)(cid:82)(cid:130)(cid:28)(cid:83)(cid:36)(cid:82)(cid:83)(cid:82)(cid:56)(cid:115)(cid:106)(cid:106)(cid:95)(cid:132)(cid:130)(cid:80)(cid:130)(cid:132)(cid:132)(cid:130)(cid:73)(cid:83)(cid:36)(cid:80)(cid:83)(cid:82)(cid:36)(cid:57)(cid:130)(cid:83)(cid:66)(cid:80)(cid:83)(cid:73)(cid:115)(cid:28)(cid:115)(cid:82)(cid:130)(cid:28)(cid:83)(cid:36)(cid:82)(cid:83)(cid:106)(cid:115)(cid:132)(cid:27)(cid:130)5-fold cross-validationTestTrainTestTestTestTestTrainTrainTrainTrainTrainTrainTrainConnections = 16Active = 11 (70%) Dropout-ratio = 30%Active = 11 (70%)Original NetworkFigure 2. K-fold CVFigure 3. Drop-outFigure 1. OverfittingPage 8 of 15
Source: https://www.cheatsheets.aqeel-anwar.comCheat Sheet –Famous CNNsFilter ConcatenationPrevious Layer5x5 Conv3x3 Conv1x1 Conv1x1 Conv1x1 Conv3x3 Maxpool1x1 ConvWeight layerWeight layer+f(x)xf(x)+xFigure 1 ResNetBlockFigure 2 Inception BlockAlexNet–2012Why:AlexNetwasbornoutoftheneedtoimprovetheresultsoftheImageNetchallenge.What:Thenetworkconsistsof5Convolutional(CONV)layersand3FullyConnected(FC)layers.TheactivationusedistheRectifiedLinearUnit(ReLU).How:Dataaugmentationiscarriedouttoreduceover-fitting,UsesLocalresponselocalization.VGGNet–2014Why:VGGNetwasbornoutoftheneedtoreducethe#ofparametersintheCONVlayersandimproveontrainingtimeWhat:TherearemultiplevariantsofVGGNet(VGG16,VGG19,etc.)How:Theimportantpointtonotehereisthatalltheconvkernelsareofsize3x3andmaxpoolkernelsareofsize2x2withastrideoftwo.ResNet–2015Why:NeuralNetworksarenotoriousfornotbeingabletofindasimplermappingwhenitexists.ResNetsolvesthat.What:TherearemultipleversionsofResNetXXarchitectureswhere‘XX’denotesthenumberoflayers.ThemostusedonesareResNet50andResNet101.Sincethevanishinggradientproblemwastakencareof(moreaboutitintheHowpart),CNNstartedtogetdeeperanddeeperHow:ResNetarchitecturemakesuseofshortcutconnectionsdosolvethevanishinggradientproblem.ThebasicbuildingblockofResNetisaResidualblockthatisrepeatedthroughoutthenetwork.Inception–2014Why:Lagerkernelsarepreferredformoreglobalfeatures,ontheotherhand,smallerkernelsprovidegoodresultsindetectingarea-specificfeatures.Foreffectiverecognitionofsuchavariable-sizedfeature,weneedkernelsofdifferentsizes.ThatiswhatInceptiondoes.What: The Inception network architecture consists of several inception modules of the following structure. Each inception module consists of four operations in parallel, 1x1 conv layer, 3x3 conv layer, 5x5 conv layer, max poolingHow: Inception increases the network space from which the best network is to be chosen via training. Each inception module can capture salient features at different levels.Page 9 of 15
Publicité
Source: https://www.cheatsheets.aqeel-anwar.comCheat Sheet –Convolutional Neural NetworkConvolutionalNeuralNetwork:ThedatagetsintotheCNNthroughtheinputlayerandpassesthroughvarioushiddenlayersbeforegettingtotheoutputlayer.Theoutputofthenetworkiscomparedtotheactuallabelsintermsoflossorerror.Thepartialderivativesofthislossw.r.tthetrainableweightsarecalculated,andtheweightsareupdatedthroughoneofthevariousmethodsusingbackpropagation.CNNTemplate:Mostofthecommonlyusedhiddenlayers(notall)followapattern1.Layerfunction:Basictransformingfunctionsuchasconvolutionalorfullyconnectedlayer.a.FullyConnected:Linearfunctionsbetweentheinputandtheoutput.-2.0-1.00.01.02.00.00.51.01.52.02.53.03.54.0MSELossmse=(x°ˆx)2mse=(x°ˆx)2-2.0-1.00.01.02.00.00.250.50.751.01.251.51.752.0MAELossmae=|x°ˆx|mae=|x°ˆx|-2.0-1.00.01.02.00.00.250.50.751.01.251.51.752.0HuberLossΩ12(x°ˆx)2:|x°ˆx|<∞∞|x°ˆx|°12∞2:elseæ∞=1.9Ω12(x°ˆx)2:|x°ˆx|<∞∞|x°ˆx|°12∞2:elseæ∞=1.9-2.0-1.00.01.02.00.00.51.01.52.02.53.0HingeLossΩmax(0,1°ˆx):x=1max(0,1+ˆx):x=°1æΩmax(0,1°ˆx):x=1max(0,1+ˆx):x=°1æ0.00.20.40.60.81.00.02.04.06.08.0CrossEntropyLoss°ylog(p)°(1°y)log(1°p)°ylog(p)°(1°y)log(1°p)0.00.20.40.60.81.00.00.20.40.60.81.0Input MapKernelOutput MapConvolutional Layera.ConvolutionalLayers:Theselayersareappliedto2D(3D)inputfeaturemaps.Thetrainableweightsarea2D(3D)kernel/filterthatmovesacrosstheinputfeaturemap,generatingdotproductswiththeoverlappingregionoftheinputfeaturemap.b.TransposedConvolutional(DeConvolutional)Layer:Usuallyusedtoincreasethesizeoftheoutputfeaturemap(Upsampling)Theideabehindthetransposedconvolutionallayeristoundo(notexactly)theconvolutionallayer2.Pooling:Non-trainablelayertochangethesizeofthefeaturemapa.Max/AveragePooling:Decreasethespatialsizeoftheinputlayerbasedonselectingthemaximum/averagevalueinreceptivefielddefinedbythekernelb.UnPooling:Anon-trainablelayerusedtoincreasethespatialsizeoftheinputlayerbasedonplacingtheinputpixelatacertainindexinthereceptivefieldoftheoutputdefinedbythekernel.3.Normalization:Usuallyusedjustbeforetheactivationfunctionstolimittheunboundedactivationfromincreasingtheoutputlayervaluestoohigha.LocalResponseNormalizationLRN:Anon-trainablelayerthatsquare-normalizesthepixelvaluesinafeaturemapwithinalocalneighborhood.b.BatchNormalization:Atrainableapproachtonormalizingthedatabylearningscaleandshiftvariableduringtraining.3.Activation:Introducenon-linearitysoCNNcanefficientlymapnon-linearcomplexmapping.a.Non-parametric/Staticfunctions:Linear,ReLUb.Parametricfunctions:ELU,tanh,sigmoid,LeakyReLUc.Boundedfunctions:tanh,sigmoid5.Lossfunction:QuantifieshowfarofftheCNNpredictionisfromtheactuallabels.a.RegressionLossFunctions:MAE,MSE,Huberlossb.ClassificationLossFunctions:Crossentropy,Hingelossw11x1 + b1Input Node Output Node w21x2 + b1w31*x3 + b1x1x2x3y1Fully Connected LayerPage 10 of 15
Source: https://www.cheatsheets.aqeel-anwar.comCheat Sheet –Ensemble Learning in MLComplete datasetTrain Weak Model #1Train Weak Model #2Train Weak Model #3Train Weak Model #4Input DatasetStep #1Assign equal weights to all the datapoints in the datasetStep #(n+1)aTrain a weak model with adjusted weights on all the datapoints in the datasetEnsemble Method –BoostingUniform weightsAdjusted weightsalpha1Adjusted weightsalpha2Adjusted weightsalpha3xxxxalpha3VotingFinal PredictionStep #n+2In the test phase, predict from each weak model and vote their predictions weighted by the corresponding alpha to get final predictionStep #2aTrain a weak model with equal weights to all the datapointsStep #2b•Based on the final error on the trained weak model, calculate a scalar alpha. •Use alpha to increase the weights of wrongly classified points, and decrease the weights of correctly classified points Step #3aTrain a weak model with adjusted weights on all the datapoints in the datasetStep #3b•Based on the final error on the trained weak model, calculate a scalar alpha. •Use alpha to increase the weights of wrongly classified points, and decrease the weights of correctly classified points Input DatasetSubset #1 –Weak LearnersSubset #3Subset #2 –Meta LearnerTrain Weak Model #1Train Weak Model #2Train Weak Model #3Train Weak Model #4Input DatasetStep #1Create 2 subsets from original dataset, one for training weak models and one for meta-modelStep #2Train each weak model with the weak learner datasetStep #3Train a meta-learner for which the input is the outputs of the weak models for the Meta Learner datasetTrained Weak Model #1Trained Weak Model #2Trained Weak Model #3Trained Weak Model #4Subset #1 –Weak LearnersSubset #2 –Meta LearnerMeta ModelFinal PredictionStep #4In the test phase, feed the input to the weak models, collect the output and feed it to the meta model. The output of the meta model is the final predictionEnsemble Method –StackingStep #2Train each weak model with an independent subset, in parallelSubset #1Subset #2Subset #3Subset #4Weak Model #1Weak Model #2Weak Model #3Weak Model #4VotingFinal PredictionInput DatasetStep #1Create N subsets from original dataset, one for each weak modelStep #3In the test phase, predict from each weak model and vote their predictions to get final predictionEnsemble Method –BaggingParameterBaggingBoostingStackingFocuses onReducing varianceReducing biasImproving accuracyNature of weak learners isHomogenousHomogenousHeterogenousWeak learners are aggregated bySimple votingWeighted votingLearned voting (meta-learner)WhatisEnsembleLearning?WisdomofthecrowdCombinemultipleweakmodels/learnersintoonepredictivemodeltoreducebias,varianceand/orimproveaccuracy.TypesofEnsembleLearning:Nnumberofweaklearners1.Bagging:TrainsNdifferentweakmodels(usuallyofsametypes–homogenous)withNnon-overlappingsubsetoftheinputdatasetinparallel.Inthetestphase,eachmodelisevaluated.Thelabelwiththegreatestnumberofpredictionsisselectedastheprediction.Baggingmethodsreducesvarianceoftheprediction2.Boosting:TrainsNdifferentweakmodels(usuallyofsametypes–homogenous)withthecompletedatasetinasequentialorder.Thedatapointswronglyclassifiedwithpreviousweakmodelisprovidedmoreweightstothattheycanbeclassifiedbythenextweakleanerproperly.Inthetestphase,eachmodelisevaluatedandbasedonthetesterrorofeachweakmodel,thepredictionisweightedforvoting.Boostingmethodsdecreasesthebiasoftheprediction.3.Stacking:TrainsNdifferentweakmodels(usuallyofdifferenttypes–heterogenous)withoneofthetwosubsetsofthedatasetinparallel.Oncetheweaklearnersaretrained,theyareusedtotrainedametalearnertocombinetheirpredictionsandcarryoutfinalpredictionusingtheothersubset.Intestphase,eachmodelpredictsitslabel,thesesetoflabelsarefedtothemetalearnerwhichgeneratesthefinalprediction.Theblockdiagrams,andcomparisontableforeachofthesethreemethodscanbeseenbelow.Page 11 of 15
How to prepare for behavioral interview?Collect stories, assign keywords, practicethe STAR format1/4KeywordsList important keywords that will be populated with your personal stories. Most common keywords are given in the table belowConflict ResolutionNegotiationCompromise to achieve goalCreativityFlexibilityConvincingHandling CrisisChallenging SituationWorking with difficult peopleAnother team priorities not alignedAdjust to a colleague styleTake StandHandling –vefeedbackCoworker view of youWorking with a deadlineYour strengthYour weaknessInfluence OthersHandling failureHandling unexpected situationConverting challenge to opportunityDecision without enough dataConflict ResolutionMentorship/LeadershipStories1.List all the organizations you have been a part of. For example1.Academia: BSc, MSc, PhD2.Industry: Jobs, Internship3.Societies: Cultural, Technical, Sports2.Think of stories from step 1 that can fall into one of the keywords categories. The more stories the better. You should have at least 10-15 stories.3.Create a summary table by assigning multiple keywords to each stories. This will help you filter out the stories when the question asked in the interview. An example can be seen belowStory1:[Convincing][TakeStand][influenceother]Story2:[Mentorship][Leadership]Story3:[Conflictresolution][Negotiation]Story4:[decision-without-enough-data]STAR FormatWrite down the stories in the STAR format as explained in the 2/4 part of this cheat sheet. This will help you practice the organization of story in a meaningful way.Source: https://www.cheatsheets.aqeel-anwar.comIcon Source: www.flaticon.comPage 12 of 15
How to prepare for behavioral interview?Direct, meaningful,personalized, logical*(Respective colors are used to identify these characteristics in the example)Example: “Tell us about a time when you had to convince senior executives”Icon Source: www.flaticon.comSTARSituationExplain the situation and provide necessary context for your story.TaskExplain the task and your responsibility in the situationActionWalk through the steps and actions you took to address the issueResultState the outcome of the result of your actions“IworkedasaninterninXYZcompanyinthesummerof2019.Theprojectdetailsprovidedtomewaselaborative.Aftersomeinitialbrainstorming,andresearchIrealizedthattheprojectapproachcanbemodifiedtomakeitmoreefficientintermsoftheunderlyingKPIs.Idecidedtotalktomymanageraboutit.”“Ihadanhour-longcallwithmymanagerandexplainedhimindetailtheproposedapproachandhowitcouldimprovetheKPIs.Iwasabletoconvincehim.HeaskedmeifIwillbeabletopresentmyproposedapproachforapprovalinfrontofthehigherexecutives.Iagreedtoit.IwasworkingoutoftheABC(city)officeandtheexecutivesneedtoflyinfromXYZ(city)office.”“IdidaquickbackgroundcheckontheexecutivestoknowbetterabouttheirareaofexpertisesothatIcanconvincethemaccordingly.Ipreparedanelaborative15slidepresentationstartingwithexplainingtheirapproach,movingontomyproposedapproachandfinallycomparingthemonpreliminaryresults.“Aftersomeactivediscussionwewereabletoestablishthattheproposedapproachwasbetterthantheinitialone.Theexecutivesproposedafewsmallchangestomyapproachandreallyappreciatedmystand.Attheendofmyinternship,Iwasselectedamongthe3outof68internswhogottomeettheseniorvicepresidentofthecompanyoverlunch.”2/4Source: https://www.cheatsheets.aqeel-anwar.comIcon Source: www.flaticon.comPage 13 of 15
How to answer a behavioral question?Understand, Extract, Map, Select and ApplyExample: “Tell us about a time when you had to convince senior executives”Icon Source: www.flaticon.comUnderstandExtractMapSelectApplyUnderstand the questionExample: A story where I was able to convince my seniors. Maybe they had something in mind, and I had a better approach and tried to convince themExtract keywords and tagsExtract useful keywords that encapsulates the gist of the questionExample:[Convincing], [Creative], [Leadership]Map the keyword to your storiesShortlist all the stories that fall under the keywords extracted from previous stepExample:Story1, Story2, Story3, Story4, …, Story NSelect the best story From the shortlisted stories, pick the one that best describes the question and has not been used so far in the interviewExample: Story3Apply the STAR methodApply the STAR method on the selected story to answer the questionExample: See Cheat Sheet 2/3 for details3/4Source: https://www.cheatsheets.aqeel-anwar.comIcon Source: www.flaticon.comPage 14 of 15
Behavioral InterviewCheat SheetSummarizing the behavioral interviewHow to answer a question during interviewUUnderstand the questionUnderstand the question and clarify any confusions that you haveEMSAExtract the keywordsTry to extract one or more of the keywords from the questionSelect a storySince each keyword maybe assigned to multiple stories, select the one that is most relevant and has not been used.Map the keywords to storiesBased on the keywords extracted, find the stories using the summary table created during preparation (Step 4)Apply the START formatOnce the story has been shortlisted, apply STAR format on the story to answer the question.1Gather important topics as keywordsUnderstand and collect all the important topics commonly asked in the interview2345How to prepare for the interviewCollect your storiesBased on all the organizations you have been a part of, think of all the stories that fall under the keywords aboveAssign keywords to storiesAssign each of your story one or more keywords. This will help you recall them quicklyPractice stories in STAR formatPractice each story using the STAR format. You will have to answer the question following this format.Create a summary tableCreate a summary table mapping stories to their associated keywords. This will be used during the behavioral question4/4Source: https://www.cheatsheets.aqeel-anwar.comIcon Source: www.flaticon.comFollow the Author:
Follow the author for more machine learning/data science content at
• (cid:145) Medium:https://aqeel-anwar.medium.com
• (cid:176) LinkedIn:https://www.linkedin.com/in/aqeelanwarmalik/
Version History
Publicité
• Version 0.1.0.1 - Apr 05, 2021
Fixed minor typo issues in Baye’s Theorem, Regression analysis and Classifier and
PCA dimensionality reduction cheat sheets.
• Version 0.1.0.0 - Mar 30, 2021
Initial draft with nine basics of ML and two behavioral interview cheat sheets.
Page 15 of 15