Bird
Raised Fist0

Why Machine Learning Exists and What Rules Cannot Solve

THEORYbeginnerInterview freq: medium
Choose your preparation mode6 modes available
⚖️
Machine Learning vs Rule-Based Systems

When designing a system to detect fraudulent transactions, would you choose a machine learning model or a rule-based system? Justify your choice.

📊
Comparison
DimensionMachine LearningRule-Based Systems
Accuracy on complex dataHighLow
Training speedMediumHigh
Inference latencyMediumHigh
InterpretabilityLowHigh
Adaptability to new dataHighLow
✅
Verdict
Default to machine learning for complex, large-scale problems where patterns are not easily defined by rules. Opt for rule-based systems when interpretability and simplicity are paramount, and data patterns are stable.
💡
Key Insight
Machine learning excels in complexity and adaptability, while rule-based systems shine in simplicity and interpretability.
⚠️
Interview Trap
❌ Wrong: Always use machine learning because it's more advanced.
Ignoring the need for interpretability and the simplicity of the problem.
✅ Consider the complexity of the data and the need for interpretability before choosing machine learning over rule-based systems.
Machine Learning
"Ability to generalize from data and adapt to new patterns."
  • Requires large amounts of labeled data for training.
  • Can be computationally expensive to train and deploy.
  • Less interpretable compared to rule-based systems.
  • May overfit if not properly regularized.
Ideal When
  • n > 100K transactions with labeled outcomes.
  • Patterns in data are complex and non-linear.
  • Data distribution changes over time.
  • Sufficient computational resources are available.
Amazon uses machine learning for product recommendations due to the complex and dynamic nature of user preferences.
Rule-Based Systems
"High interpretability and straightforward implementation."
  • Struggles with complex, non-linear patterns.
  • Requires manual updates to rules as data changes.
  • Limited scalability with increasing data complexity.
  • Cannot learn from data without human intervention.
Ideal When
  • n < 10K transactions with clear, simple patterns.
  • Patterns are stable and well-understood.
  • High interpretability is required for compliance.
  • Limited computational resources are available.
Traditional banking systems use rule-based systems for initial fraud detection due to regulatory requirements for transparency.
🐍
Machine Learning - Example
▼ Show
Python
import numpy as np
from sklearn.ensemble import RandomForestClassifier
X = np.random.rand(1000, 10)
y = np.random.randint(0, 2, 1000)
model = RandomForestClassifier()
model.fit(X, y)
predictions = model.predict(X)
🐍
Rule-Based Systems - Example
▼ Show
Python
def detect_fraud(transaction):
    if transaction['amount'] > 1000 and transaction['location'] != 'home':
        return True
    return False
transactions = [{'amount': 1200, 'location': 'abroad'}, {'amount': 200, 'location': 'home'}]
results = [detect_fraud(t) for t in transactions]
✅
Use Machine Learning When
  • •n > 100K and data patterns are complex.
  • •Data distribution changes frequently.
  • •You have access to sufficient computational resources.
✅
Use Rule-Based Systems When
  • •n < 10K and patterns are simple and stable.
  • •High interpretability is required.
  • •Computational resources are limited.
↳
Nuances
  • Machine learning models can overfit on small datasets, making rule-based systems more reliable in such cases.
  • Rule-based systems can be more efficient for well-defined, stable problems where rules rarely change.
  • Machine learning models require significant computational resources, which may not be available in all scenarios.

Practice

(1/5)
1. In the context of slice-based evaluation, which of the following is a key benefit?
easy
A. It reduces the overall training time of the model.
B. It ensures the model is robust to adversarial attacks.
C. It automatically tunes hyperparameters for better performance.
D. It helps identify specific data subsets where the model performs poorly.

Solution

  1. Step 1: Understand slice-based evaluation

    Slice-based evaluation focuses on analyzing model performance on specific data subsets.
  2. Step 2: Eliminate wrong options

    It reduces the overall training time of the model. is incorrect as slice-based evaluation doesn't affect training time. It automatically tunes hyperparameters for better performance. is incorrect because it doesn't involve hyperparameter tuning. It ensures the model is robust to adversarial attacks. is incorrect as it doesn't directly address adversarial robustness.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Slice-based evaluation identifies weak data subsets. [OK]
Hint: Slice-based evaluation identifies weak data subsets. [OK]
Common Mistakes:
2. In the context of fairness in machine learning, which of the following techniques is specifically designed to ensure that a model's predictions are equally accurate across different demographic groups?
easy
A. Data augmentation
B. Adversarial debiasing
C. Cross-validation
D. Gradient boosting

Solution

  1. Step 1: Identify the technique focused on fairness.

    Adversarial debiasing is specifically designed to reduce bias by ensuring equal accuracy across groups.
  2. Step 2: Eliminate wrong options.

    Data augmentation (A) is for increasing data diversity, cross-validation (C) is for model validation, and gradient boosting (D) is for improving model accuracy, not fairness.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Adversarial debiasing ensures fairness across groups. [OK]
Hint: Adversarial debiasing ensures fairness across groups. [OK]
Common Mistakes:
3. In a scenario where computational resources are limited, which approach is more suitable for sequence-to-sequence tasks and why?
medium
A. Use RNNs because they require less memory than attention mechanisms.
B. Use RNNs because they are faster to train than attention mechanisms.
C. Use attention mechanisms because they allow for parallel processing.
D. Use attention mechanisms because they are more interpretable than RNNs.

Solution

  1. Step 1: Evaluate computational efficiency.

    Attention mechanisms allow for parallel processing, making them more efficient with limited resources.
  2. Step 2: Eliminate wrong options.

    Use RNNs because they require less memory than attention mechanisms. is incorrect as attention mechanisms can be more memory efficient due to parallelism. Use RNNs because they are faster to train than attention mechanisms. is incorrect because RNNs are slower due to sequential processing. Use attention mechanisms because they are more interpretable than RNNs. is incorrect as interpretability is not the main concern here.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Parallel processing saves resources. [OK]
Hint: Parallel processing saves resources. [OK]
Common Mistakes:
4. A recurrent neural network is not learning effectively. The loss plateaus early during training. What is the most likely cause?
medium
A. The learning rate is too high.
B. The model is overfitting.
C. The vanishing gradient problem.
D. The dataset is too small.

Solution

  1. Step 1: Identify symptoms of vanishing gradient.

    Early plateauing of loss often indicates vanishing gradients.
  2. Step 2: Eliminate other causes.

    High learning rate (A) would cause erratic loss, overfitting (B) would show low training loss, and small dataset (D) would not cause early plateau.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Early plateau = vanishing gradient. [check]
Hint: Early plateau = vanishing gradient. [check]
Common Mistakes:
5. A model trained on a specific dataset performs poorly on new data. What is a likely cause related to the No Free Lunch Theorem?
medium
A. The new data is from a different distribution.
B. The model is too simple for the new data.
C. The model was overfitted to the training dataset.
D. The model's hyperparameters were not optimized.

Solution

  1. Step 1: Consider the No Free Lunch Theorem

    The theorem implies that model performance is dataset-specific.
  2. Step 2: Eliminate wrong options

    The model is too simple for the new data. is incorrect because simplicity isn't the main issue. The model was overfitted to the training dataset. is incorrect because overfitting affects generalization, but the core issue is distribution change. The model's hyperparameters were not optimized. is incorrect because hyperparameter tuning doesn't address distribution differences.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Performance varies with data distribution. [OK]
Hint: Performance varies with data distribution. [OK]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard