Machine Learning challenges

Practice problem statements with input format, output format, constraints and solutions.

beginner

Machine Learning Introduction challenge

Build a small solution that uses Machine Learning Introduction in Machine Learning and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

dataset = [
    {"feature": 1.2, "label": "low"},
    {"feature": 3.8, "label": "high"},
    {"feature": 2.4, "label": "medium"},
]
features = [row["feature"] for row in dataset]
labels = [row["label"] for row in dataset]
print({"rows": len(dataset), "features": features, "labels": labels})

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core machine learning introduction pattern before polishing the final output.

Solution

dataset = [
    {"feature": 1.2, "label": "low"},
    {"feature": 3.8, "label": "high"},
    {"feature": 2.4, "label": "medium"},
]
features = [row["feature"] for row in dataset]
labels = [row["label"] for row in dataset]
print({"rows": len(dataset), "features": features, "labels": labels})
beginner

AI vs ML vs Deep Learning challenge

Build a small solution that uses AI vs ML vs Deep Learning in Machine Learning and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

dataset = [
    {"feature": 1.2, "label": "low"},
    {"feature": 3.8, "label": "high"},
    {"feature": 2.4, "label": "medium"},
]
features = [row["feature"] for row in dataset]
labels = [row["label"] for row in dataset]
print({"rows": len(dataset), "features": features, "labels": labels})

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core ai vs ml vs deep learning pattern before polishing the final output.

Solution

dataset = [
    {"feature": 1.2, "label": "low"},
    {"feature": 3.8, "label": "high"},
    {"feature": 2.4, "label": "medium"},
]
features = [row["feature"] for row in dataset]
labels = [row["label"] for row in dataset]
print({"rows": len(dataset), "features": features, "labels": labels})
beginner

ML Problem Framing challenge

Build a small solution that uses ML Problem Framing in Machine Learning and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

dataset = [
    {"feature": 1.2, "label": "low"},
    {"feature": 3.8, "label": "high"},
    {"feature": 2.4, "label": "medium"},
]
features = [row["feature"] for row in dataset]
labels = [row["label"] for row in dataset]
print({"rows": len(dataset), "features": features, "labels": labels})

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core ml problem framing pattern before polishing the final output.

Solution

dataset = [
    {"feature": 1.2, "label": "low"},
    {"feature": 3.8, "label": "high"},
    {"feature": 2.4, "label": "medium"},
]
features = [row["feature"] for row in dataset]
labels = [row["label"] for row in dataset]
print({"rows": len(dataset), "features": features, "labels": labels})
beginner

Datasets and Features challenge

Build a small solution that uses Datasets and Features in Machine Learning and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

dataset = [
    {"feature": 1.2, "label": "low"},
    {"feature": 3.8, "label": "high"},
    {"feature": 2.4, "label": "medium"},
]
features = [row["feature"] for row in dataset]
labels = [row["label"] for row in dataset]
print({"rows": len(dataset), "features": features, "labels": labels})

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core datasets and features pattern before polishing the final output.

Solution

dataset = [
    {"feature": 1.2, "label": "low"},
    {"feature": 3.8, "label": "high"},
    {"feature": 2.4, "label": "medium"},
]
features = [row["feature"] for row in dataset]
labels = [row["label"] for row in dataset]
print({"rows": len(dataset), "features": features, "labels": labels})
beginner

Labels and Targets challenge

Build a small solution that uses Labels and Targets in Machine Learning and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

dataset = [
    {"feature": 1.2, "label": "low"},
    {"feature": 3.8, "label": "high"},
    {"feature": 2.4, "label": "medium"},
]
features = [row["feature"] for row in dataset]
labels = [row["label"] for row in dataset]
print({"rows": len(dataset), "features": features, "labels": labels})

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core labels and targets pattern before polishing the final output.

Solution

dataset = [
    {"feature": 1.2, "label": "low"},
    {"feature": 3.8, "label": "high"},
    {"feature": 2.4, "label": "medium"},
]
features = [row["feature"] for row in dataset]
labels = [row["label"] for row in dataset]
print({"rows": len(dataset), "features": features, "labels": labels})
beginner

Supervised Learning challenge

Build a small solution that uses Supervised Learning in Machine Learning and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

dataset = [
    {"feature": 1.2, "label": "low"},
    {"feature": 3.8, "label": "high"},
    {"feature": 2.4, "label": "medium"},
]
features = [row["feature"] for row in dataset]
labels = [row["label"] for row in dataset]
print({"rows": len(dataset), "features": features, "labels": labels})

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core supervised learning pattern before polishing the final output.

Solution

dataset = [
    {"feature": 1.2, "label": "low"},
    {"feature": 3.8, "label": "high"},
    {"feature": 2.4, "label": "medium"},
]
features = [row["feature"] for row in dataset]
labels = [row["label"] for row in dataset]
print({"rows": len(dataset), "features": features, "labels": labels})
beginner

Unsupervised Learning challenge

Build a small solution that uses Unsupervised Learning in Machine Learning and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

dataset = [
    {"feature": 1.2, "label": "low"},
    {"feature": 3.8, "label": "high"},
    {"feature": 2.4, "label": "medium"},
]
features = [row["feature"] for row in dataset]
labels = [row["label"] for row in dataset]
print({"rows": len(dataset), "features": features, "labels": labels})

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core unsupervised learning pattern before polishing the final output.

Solution

dataset = [
    {"feature": 1.2, "label": "low"},
    {"feature": 3.8, "label": "high"},
    {"feature": 2.4, "label": "medium"},
]
features = [row["feature"] for row in dataset]
labels = [row["label"] for row in dataset]
print({"rows": len(dataset), "features": features, "labels": labels})
beginner

Regression challenge

Build a small solution that uses Regression in Machine Learning and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

hours = [1, 2, 3, 4]
scores = [42, 51, 63, 72]
slope = 10
intercept = 32
predictions = [slope * hour + intercept for hour in hours]
mae = sum(abs(actual - pred) for actual, pred in zip(scores, predictions)) / len(scores)
print({"predictions": predictions, "mae": mae})

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core regression pattern before polishing the final output.

Solution

hours = [1, 2, 3, 4]
scores = [42, 51, 63, 72]
slope = 10
intercept = 32
predictions = [slope * hour + intercept for hour in hours]
mae = sum(abs(actual - pred) for actual, pred in zip(scores, predictions)) / len(scores)
print({"predictions": predictions, "mae": mae})
beginner

Classification challenge

Build a small solution that uses Classification in Machine Learning and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

actual = [1, 0, 1, 1, 0, 0]
predicted = [1, 0, 0, 1, 1, 0]
true_positive = sum(a == 1 and p == 1 for a, p in zip(actual, predicted))
false_positive = sum(a == 0 and p == 1 for a, p in zip(actual, predicted))
false_negative = sum(a == 1 and p == 0 for a, p in zip(actual, predicted))
precision = true_positive / (true_positive + false_positive)
recall = true_positive / (true_positive + false_negative)
print({"precision": round(precision, 2), "recall": round(recall, 2)})

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core classification pattern before polishing the final output.

Solution

actual = [1, 0, 1, 1, 0, 0]
predicted = [1, 0, 0, 1, 1, 0]
true_positive = sum(a == 1 and p == 1 for a, p in zip(actual, predicted))
false_positive = sum(a == 0 and p == 1 for a, p in zip(actual, predicted))
false_negative = sum(a == 1 and p == 0 for a, p in zip(actual, predicted))
precision = true_positive / (true_positive + false_positive)
recall = true_positive / (true_positive + false_negative)
print({"precision": round(precision, 2), "recall": round(recall, 2)})
beginner

Clustering challenge

Build a small solution that uses Clustering in Machine Learning and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

points = [2, 3, 10, 11, 12, 25]
centers = [3, 11]
clusters = {center: [] for center in centers}
for point in points:
    nearest = min(centers, key=lambda center: abs(point - center))
    clusters[nearest].append(point)
print(clusters)

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core clustering pattern before polishing the final output.

Solution

points = [2, 3, 10, 11, 12, 25]
centers = [3, 11]
clusters = {center: [] for center in centers}
for point in points:
    nearest = min(centers, key=lambda center: abs(point - center))
    clusters[nearest].append(point)
print(clusters)