MLCrack

    PROBABILITY & STATISTICS · INTERVIEW QUESTION

    Explain Bayes' theorem and give an ML application.

    🟢 beginner · Probability Theory

    Hint: P(A|B) = P(B|A)P(A)/P(B). Think about updating beliefs with evidence.

    Answer

    Bayes' theorem relates conditional probabilities, allowing us to update beliefs given new evidence.

    P(θ∣D)=P(D∣θ)⋅P(θ)P(D)P(\theta|D) = \frac{P(D|\theta) \cdot P(\theta)}{P(D)}

    In ML terms: posterior = likelihood × prior / evidence.

    Applications in ML

    • Naive Bayes classifier: directly applies Bayes' theorem for text classification
    • Bayesian neural networks: place distributions over weights for uncertainty estimation
    • Bayesian optimization: used for hyperparameter tuning
    • Spam filtering: computes P(spam∣words)P(\text{spam}|\text{words}) from word frequencies
    python
    from sklearn.naive_bayes import MultinomialNB # Naive Bayes for text classification clf = MultinomialNB() clf.fit(X_train_tfidf, y_train) y_pred = clf.predict(X_test_tfidf)

    The key insight is updating prior beliefs with observed data to get posterior beliefs — the foundation of Bayesian inference.