50  Clustering

50.1 DBSCAN

50.2 k-Means Clustering

The \(k\)-means algorithm is an unsupervised learning algorithm that has a loose relationship to the \(k\)-nearest neighbor classifier. The \(k\)-means algorithm works as follows:

  • Step 1: Randomly choose \(k\) centers. Assign points to cluster.

  • Step 2: Determine the distances of each data point to the centroids and re-assign each point to the closest cluster centroid based upon minimum distance

  • Step 3: Calculate cluster centroids again

  • Step 4: Repeat steps 2 and 3 until we reach global optima where no improvements are possible and no switching of data points from one cluster to other.

  • Video: K-means clustering

50.3 DDMO-Additional Videos

50.4 DDMO-Exercises

Exercise 50.1 (Smaller Bins) What happens when we use smaller bins in a histogram?

Exercise 50.2 (Density Curve) Why plot a curve to approximate a histogram?

Exercise 50.3 (TwoSDQuestion) How many samples are plus/minus two SD around the mean?

Exercise 50.4 (OneSDQuestion) How many samples are plus/minus one SD around the mean?

Exercise 50.5 (ThreeSDQuestion) How many samples are plus/minus three SD around the mean?

Exercise 50.6 (DataRangeQuestion) You have a mean at 100 and a SD of 10. Where are 95% of the data?

Exercise 50.7 (PeakHeightQuestion) If the peak is very high, is the SD low or high?

Exercise 50.8 (ProbabilityQuestion) If we have a certain curve and want to calculate the probability of values equal to 20 if the mean is 20.

Exercise 50.9 (MeanDifferenceQuestion) The difference between \(\mu\) and x-bar?

Exercise 50.10 (EstimateMeanQuestion) How do you calculate the sample mean?

Exercise 50.11 (SigmaSquaredQuestion) What is sigma squared?

Exercise 50.12 (EstimatedSDQuestion) What is the formula for the estimated standard deviation?

Exercise 50.13 (VarianceDifferenceQuestion) Difference between the variance and the estimated variance?

Exercise 50.14 (ModelBenefitsQuestion) What are the benefits of using models?

Exercise 50.15 (SampleDefinitionQuestion) What is a sample in statistics?

Exercise 50.16 (RejectHypothesisQuestion) What does it mean to reject a hypothesis?

Exercise 50.17 (NullHypothesisQuestion) What is a null hypothesis?

Exercise 50.18 (BetterDrugQuestion) How can you show that you have found a better drug?

Exercise 50.19 (PValueIntroductionQuestion) What is the reason for introducing the p-value?

Exercise 50.20 (PValueRangeQuestion) Is there any range for p-values? Can it be negative?

Exercise 50.21 (PValueRangeQuestion) Is there any range for p-values? Can it be negative?

Exercise 50.22 (TypicalPValueQuestion) What are typical values of the p-value and what does it mean? 5%?

Exercise 50.23 (FalsePositiveQuestion) What is a false-positive?

Exercise 50.24 (CalculatePValueQuestion) How to calculate p-value?

Exercise 50.25 (SDCalculationQuestion) What is the SD if the mean is 155 and in the range from 142 - 169 there are 95% of the data?

Exercise 50.26 (SidedPValueQuestion) When do we need the two-sided p-value and when the one-sided?

Exercise 50.27 (CoinTestQuestion) Test a coin with Tail-Head-Head. What is the p-value?

Exercise 50.28 (BorderPValueQuestion) If you get exactly the 0.05 border value, can you reject?

Exercise 50.29 (OneSidedPValueCautionQuestion) Why should you be careful with a one-sided p-test?

Exercise 50.30 (BinomialDistributionQuestion) What is the binomial distribution?

Exercise 50.31 (PHackingWaysQuestion) Name two typical ways of p-hacking.

Exercise 50.32 (AvoidPHackingQuestion) How can p-hacking be avoided?

Exercise 50.33 (MultipleTestingProblemQuestion) What is the multiple testing problem?

50.4.0.1 Covariance

Exercise 50.34 (CovarianceDefinitionQuestion) What is covariance?

Exercise 50.35 (CovarianceMeaningQuestion) What is the meaning of covariance?

Exercise 50.36 (CovarianceVarianceRelationshipQuestion) What is the relationship between covariance and variance?

Exercise 50.37 (HighCovarianceQuestion) If covariance is high, is there a strong relationship?

Exercise 50.38 (ZeroCovarianceQuestion) What if the covariance is zero?

Exercise 50.39 (NegativeCovarianceQuestion) Can covariance be negative?

Exercise 50.40 (NegativeVarianceQuestion) Can variance be negative?

Exercise 50.41 (CorrelationValueQuestion) What do you do if the correlation value is 10?

Exercise 50.42 (CorrelationRangeQuestion) What is the possible range of correlation values?

Exercise 50.43 (CorrelationFormulaQuestion) What is the formula for correlation?

Exercise 50.44 (UnderstandingStatisticalPower) What is the definition of power in a statistical test?

Exercise 50.45 (DistributionEffectOnPower) What is the implication for power analysis if the samples come from the same distribution?

Exercise 50.46 (IncreasingPower) How can you increase the power if the distributions are very similar?

Exercise 50.47 (PreventingPHacking) What should be done to avoid p-hacking when the distributions are close to each other?

Exercise 50.48 (SampleSizeAndPower) If there is overlap and the sample size is small, will the power be high or low?

Exercise 50.49 (FactorsAffectingPower) Which are the two main factors that affect power?

Exercise 50.50 (PurposeOfPowerAnalysis) What does power analysis tell us?

Exercise 50.51 (ExperimentRisks) What are the two risks faced when performing an experiment?

Exercise 50.52 (PerformingPowerAnalysis) How do you perform a power analysis?

Exercise 50.53 (CentralLimitTheoremExplanation) What does the Central Limit Theorem state?

Exercise 50.54 (MedianInBoxplot) What is represented by the middle line in a boxplot?

Exercise 50.55 (BoxContentInBoxplot) What does the box in a boxplot represent?

Exercise 50.56 (RSquaredDefinition) What is R-squared? Show the formula.

Exercise 50.57 (NegativeRSquared) Can the R-squared value be negative?

Exercise 50.58 (RSquaredCalculation) Perform a calculation involving R-squared.

Exercise 50.59 (LeastSquaresMeaning) What is the meaning of the least squares method?

Exercise 50.60 (RegressionVsClassification) What is the difference between regression and classification?

Exercise 50.61 (LikelihoodConcept) What is the idea of likelihood?

Exercise 50.62 (ProbabilityVsLikelihood) What is the difference between probability and likelihood?

Exercise 50.63 (TrainVsTestData) What is the difference between training and testing data?

Exercise 50.64 (SingleValidationIssue) What is the problem if you validate the model only once?

Exercise 50.65 (FoldDefinition) What is a fold in cross-validation?

Exercise 50.66 (LeaveOneOutValidation) What is leave-one-out cross-validation?

Exercise 50.67 (DrawingConfusionMatrix) Draw the confusion matrix.

Exercise 50.68 (SensitivitySpecificityCalculation1) Calculate the sensitivity and specificity for a given confusion matrix.

Exercise 50.69 (SensitivitySpecificityCalculation2) Calculate the sensitivity and specificity for a given confusion matrix.

Exercise 50.70 (BiasAndVariance) What are bias and variance?

Exercise 50.71 (MutualInformationExample) Provide an example and calculate if mutual information is high or low.

Exercise 50.72 (WhatIsPCA) What is PCA?

Exercise 50.73 (ScreePlotExplanation) What is a scree plot?

Exercise 50.74 (LeastSquaresInPCA) Does PCA use least squares?

Exercise 50.75 (PCASteps) Which steps are performed by PCA?

Exercise 50.76 (EigenvaluePC1) What is the eigenvalue of the first principal component?

Exercise 50.77 (DifferencesBetweenPoints) Are the differences between red and yellow the same as the differences between red and blue points?

Exercise 50.78 (ScalingInPCA) How to scale data in PCA?

Exercise 50.79 (DetermineNumberOfComponents) How to determine the number of principal components?

Exercise 50.80 (LimitingNumberOfComponents) How is the number of principal components limited?

Exercise 50.81 (WhyUseTSNE) Why use t-SNE?

Exercise 50.82 (MainIdeaOfTSNE) What is the main idea of t-SNE?

Exercise 50.83 (BasicConceptOfTSNE) What is the basic concept of t-SNE?

Exercise 50.84 (TSNESteps) What are the steps in t-SNE?

Exercise 50.85 (HowKMeansWorks) How does K-means clustering work?

Exercise 50.86 (QualityOfClusters) How can the quality of the resulting clusters be calculated?

Exercise 50.87 (IncreasingK) Why is it not a good idea to increase k too much?

Exercise 50.88 (CorePointInDBSCAN) What is a core point in DBSCAN?

Exercise 50.89 (AddingVsExtending) What is the difference between adding and extending in DBSCAN?

Exercise 50.90 (OutliersInDBSCAN) What are outliers in DBSCAN?

Exercise 50.91 (AdvantagesAndDisadvantagesOfK) What are the advantages and disadvantages of k = 1 and k = 100 in K-nearest neighbors?

Exercise 50.92 (NaiveBayesFormula) What is the formula for Naive Bayes?

Exercise 50.93 (CalculateProbabilities) Calculate the probabilities for a given example using Naive Bayes.

Exercise 50.94 (UnderflowProblem) Why is underflow a problem in Gaussian Naive Bayes?

Exercise 50.95 (Tree Usage) For what can we use trees?

Exercise 50.96 (Tree Usage) Based on a shown tree graph:

  • How can you use this tree?
  • What is the root node?
  • What are branches and internal nodes?
  • What are the leafs?
  • Are the leafs pure or impure?
  • Which of the leafs is more impure?

Exercise 50.97 (Tree Feature Importance) Is the most or least important feature on top?

Exercise 50.98 (Tree Feature Imputation) How can you fill a gap/missing data?

Solution 50.1 (Tree Feature Imputation).

  • Mean
  • Median
  • Comparing to column with high correlation

Exercise 50.99 (Regression Tree Limitations) What are limitations?

Exercise 50.100 (Regression Tree Score) How is the tree score calculated?

Exercise 50.101 (Regression Tree Alpha Value Small) What can we say about the tree if the alpha value is small?

Exercise 50.102 (Regression Tree Increase Alpha Value) What happens if you increase alpha?

Exercise 50.103 (Regression Tree Pruning) What is the meaning of pruning?