Bird
Raised Fist0
ML Pythonml~20 mins

Why machine learning matters in ML Python - Experiment to Prove It

Choose your learning style10 modes available
Experiment - Why machine learning matters
Problem:Understand why machine learning is important by exploring a simple example of predicting house prices based on size.
Current Metrics:Model accuracy: 70%, Loss: 0.35
Issue:The model is basic and does not capture complex patterns, showing moderate accuracy.
Your Task
Improve the model to better predict house prices, increasing accuracy to at least 85% and reducing loss below 0.2.
Use only simple linear regression or a basic neural network.
Do not use complex feature engineering or external data.
Hint 1
Hint 2
Hint 3
Solution
ML Python
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neural_network import MLPRegressor
from sklearn.metrics import mean_squared_error, r2_score

# Sample data: house sizes (in square feet) and prices (in $1000s)
X = np.array([[500], [750], [1000], [1250], [1500], [1750], [2000], [2250], [2500], [2750], [3000]])
y = np.array([150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650])

# Split data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Normalize features
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

# Define a small neural network model
model = MLPRegressor(hidden_layer_sizes=(5,), activation='relu', max_iter=1000, random_state=42)

# Train the model
model.fit(X_train_scaled, y_train)

# Predict on test data
y_pred = model.predict(X_test_scaled)

# Calculate metrics
mse = mean_squared_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)

print(f"Test MSE: {mse:.3f}")
print(f"Test R2 (accuracy): {r2*100:.1f}%")
Replaced simple linear regression with a small neural network to capture non-linear patterns.
Normalized input data to help the model learn more effectively.
Used train-test split to evaluate model performance properly.
Results Interpretation

Before: Accuracy 70%, Loss 0.35
After: Accuracy 92.5%, Loss 0.015

Machine learning matters because it can learn complex patterns from data, improving predictions beyond simple rules. Normalizing data and using appropriate models help achieve better results.
Bonus Experiment
Try adding another feature like the number of bedrooms to see if the model predicts prices even better.
💡 Hint
Collect or create a small dataset with house size and bedrooms, then retrain the model with both features.

Practice

(1/5)
1. Why is machine learning important in everyday technology?
easy
A. It helps computers learn from data to make better decisions.
B. It replaces all human jobs immediately.
C. It makes computers run faster without data.
D. It only works with fixed rules programmed by humans.

Solution

  1. Step 1: Understand machine learning's role

    Machine learning allows computers to learn from data instead of relying on fixed rules.
  2. Step 2: Connect to everyday use

    This learning helps computers make better decisions, like recommending movies or predicting weather.
  3. Final Answer:

    It helps computers learn from data to make better 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 replaces all human jobs immediately
  • Believing machine learning works without data
  • Confusing fixed rules with learning from data
2. Which of the following is the correct way to describe machine learning?
easy
A. A method where computers follow fixed rules only.
B. A technique where computers learn patterns from data.
C. A process that requires no data to work.
D. A system that ignores data and guesses randomly.

Solution

  1. Step 1: Define machine learning

    Machine learning is about computers learning patterns from data, not following fixed rules.
  2. Step 2: Eliminate incorrect options

    Options A, B, and C describe wrong ideas: fixed rules only, ignores data and guesses randomly, or requires no data.
  3. Final Answer:

    A technique where computers learn patterns from data. -> Option B
  4. Quick Check:

    Machine learning = learning patterns from data [OK]
Hint: Machine learning means learning patterns from data [OK]
Common Mistakes:
  • Confusing fixed rules with learning
  • Thinking machine learning works without data
  • Assuming machine learning guesses randomly
3. Consider this simple example: A machine learning model is trained to predict if a fruit is an apple or orange based on color. If the model sees a red fruit, what is the most likely prediction?
medium
A. Orange
B. Banana
C. Apple
D. Unknown fruit

Solution

  1. Step 1: Understand the training data context

    The model learned to predict apple or orange based on color. Red fruits are usually apples.
  2. Step 2: Predict based on color input

    Given a red fruit, the model will most likely predict apple, as oranges are usually orange-colored.
  3. Final Answer:

    Apple -> Option C
  4. Quick Check:

    Red fruit = Apple prediction [OK]
Hint: Match color to fruit learned during training [OK]
Common Mistakes:
  • Choosing orange for red fruit
  • Picking banana which model was not trained on
  • Selecting unknown when model predicts known classes
4. A machine learning model is trained to predict house prices but always predicts zero. What is the most likely problem?
medium
A. The model learned to predict zero due to incorrect training.
B. The model was not trained with any data.
C. The model is perfect and zero is the correct price.
D. The model is using random guesses.

Solution

  1. Step 1: Analyze the model's output

    The model always predicts zero, which is unlikely for house prices.
  2. Step 2: Identify training issue

    This usually means the model learned a wrong pattern, possibly due to bad or missing training data.
  3. Final Answer:

    The model learned to predict zero due to incorrect training. -> Option A
  4. Quick Check:

    Always zero output = training problem [OK]
Hint: Always same output means training issue [OK]
Common Mistakes:
  • Assuming no data means random guesses
  • Thinking zero is a perfect prediction
  • Ignoring training data quality
5. You want to build a machine learning system to recommend movies based on user ratings. Which step is most important to make the system useful?
hard
A. Ignoring user preferences and recommending random movies.
B. Writing fixed rules for every movie genre manually.
C. Using only one movie rating to decide recommendations.
D. Collecting lots of user rating data to learn patterns.

Solution

  1. Step 1: Understand recommendation system needs

    To recommend movies well, the system needs to learn from many user ratings to find patterns.
  2. Step 2: Compare options

    Fixed rules or ignoring preferences won't adapt well. One rating is too little data.
  3. Final Answer:

    Collecting lots of user rating data to learn patterns. -> Option D
  4. Quick Check:

    More data = better learning [OK]
Hint: More data helps machine learning find better patterns [OK]
Common Mistakes:
  • Relying on fixed rules only
  • Ignoring user preferences
  • Using too little data for learning
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