Bird
Raised Fist0
ML Pythonml~20 mins

What machine learning actually is in ML Python - ML Experiment: Train & Evaluate

Choose your learning style10 modes available
Experiment - What machine learning actually is
Problem:You want to teach a computer to recognize handwritten digits from images.
Current Metrics:The model currently guesses correctly 70% of the time on new images.
Issue:The model is not accurate enough to be useful in real life.
Your Task
Improve the model so it guesses correctly at least 85% of the time on new images.
You can only change the model's training process and parameters.
You cannot add more data or change the images.
Hint 1
Hint 2
Hint 3
Solution
ML Python
import tensorflow as tf
from tensorflow.keras import layers, models

# Load dataset
mnist = tf.keras.datasets.mnist
(X_train, y_train), (X_test, y_test) = mnist.load_data()

# Normalize data
X_train, X_test = X_train / 255.0, X_test / 255.0

# Build a simple neural network model
model = models.Sequential([
    layers.Flatten(input_shape=(28, 28)),
    layers.Dense(128, activation='relu'),
    layers.Dropout(0.2),
    layers.Dense(10, activation='softmax')
])

# Compile the model
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

# Train the model
model.fit(X_train, y_train, epochs=10, validation_split=0.2)

# Evaluate the model
loss, accuracy = model.evaluate(X_test, y_test)
print(f'Test accuracy: {accuracy * 100:.2f}%')
Added a dropout layer to reduce overfitting.
Used the Adam optimizer for better learning.
Increased training epochs to 10 for better learning.
Results Interpretation

Before: 70% accuracy on new images.
After: 92% accuracy on new images.

Machine learning means teaching a computer to learn patterns from examples. By adjusting how the model learns, it can improve its guesses and become more useful.
Bonus Experiment
Try using a convolutional neural network (CNN) instead of a simple dense network to improve accuracy further.
💡 Hint
CNNs look at small parts of images and learn better features for pictures.

Practice

(1/5)
1. What is the main idea behind machine learning?
easy
A. Computers learn from data to make predictions or decisions.
B. Computers follow fixed rules written by programmers.
C. Computers only store data without processing it.
D. Computers randomly guess answers without learning.

Solution

  1. Step 1: Understand the role of data in machine learning

    Machine learning uses data to help computers learn patterns instead of fixed rules.
  2. Step 2: Compare options to the definition

    Only Computers learn from data to make predictions or decisions. correctly states that computers learn from data to predict or decide.
  3. Final Answer:

    Computers learn from data to make predictions or decisions. -> Option A
  4. Quick Check:

    Machine learning = learning from data [OK]
Hint: Machine learning means learning from data, not fixed rules. [OK]
Common Mistakes:
  • Thinking machine learning is just following fixed rules.
  • Confusing data storage with learning.
  • Believing guesses are random without learning.
2. Which of the following is the correct way to describe the machine learning process?
easy
A. Write exact rules, then apply them to data.
B. Store data without any processing.
C. Give data, teach model, use model to guess, check guesses.
D. Guess answers randomly without data.

Solution

  1. Step 1: Recall the simple steps of machine learning

    Machine learning involves giving data, teaching a model, using it to guess, and checking guesses.
  2. Step 2: Match options to these steps

    Only Give data, teach model, use model to guess, check guesses. correctly lists these steps in order.
  3. Final Answer:

    Give data, teach model, use model to guess, check guesses. -> Option C
  4. Quick Check:

    Machine learning steps = D [OK]
Hint: Remember the 4 steps: data, teach, guess, check. [OK]
Common Mistakes:
  • Confusing machine learning with rule writing.
  • Ignoring the checking step.
  • Thinking guesses are random.
3. Consider this simple example: A model is trained on data about house sizes and prices. After training, it predicts the price for a 1500 sq ft house as $300,000. What does this prediction represent?
medium
A. A fixed rule written by a programmer.
B. A prediction made by the model based on learned patterns.
C. A random guess without using data.
D. An exact price from the training data.

Solution

  1. Step 1: Understand model prediction after training

    The model uses learned patterns from training data to predict new inputs.
  2. Step 2: Identify what the prediction means

    The prediction is not random or fixed; it is based on what the model learned.
  3. Final Answer:

    A prediction made by the model based on learned patterns. -> Option B
  4. Quick Check:

    Model prediction = learned pattern guess [OK]
Hint: Model predictions come from learned data patterns. [OK]
Common Mistakes:
  • Thinking predictions are random guesses.
  • Confusing predictions with fixed rules.
  • Assuming predictions must be exact training data.
4. A student wrote this about machine learning: "Machine learning means writing exact rules for the computer to follow." What is wrong with this statement?
medium
A. Machine learning guesses answers randomly.
B. Machine learning only stores data without processing.
C. Machine learning is the same as data storage.
D. Machine learning does not involve writing exact rules; it learns from data.

Solution

  1. Step 1: Identify the misconception in the statement

    The statement wrongly says machine learning is about writing exact rules.
  2. Step 2: Clarify what machine learning actually is

    Machine learning learns patterns from data instead of fixed rules.
  3. Final Answer:

    Machine learning does not involve writing exact rules; it learns from data. -> Option D
  4. Quick Check:

    Machine learning ≠ exact rules [OK]
Hint: Machine learning learns from data, not fixed rules. [OK]
Common Mistakes:
  • Confusing machine learning with programming rules.
  • Ignoring the learning from data aspect.
  • Thinking machine learning is random guessing.
5. You want to build a system that recognizes handwritten digits. Why is machine learning a better choice than writing exact rules for this task?
hard
A. Because writing exact rules for all handwriting styles is too hard or impossible.
B. Because machine learning stores all images without processing.
C. Because machine learning guesses digits randomly.
D. Because writing exact rules is faster and easier.

Solution

  1. Step 1: Understand the challenge of handwriting recognition

    Handwriting varies a lot, making exact rules very complex or impossible to write.
  2. Step 2: Explain why machine learning helps

    Machine learning learns from many examples to handle variations automatically.
  3. Final Answer:

    Because writing exact rules for all handwriting styles is too hard or impossible. -> Option A
  4. Quick Check:

    Hard rules? Use machine learning [OK]
Hint: Use machine learning when rules are too hard to write. [OK]
Common Mistakes:
  • Thinking exact rules are easier for complex tasks.
  • Believing machine learning guesses randomly.
  • Ignoring the difficulty of handwriting variations.
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