0
0
ML Pythonprogramming~5 mins

ML vs traditional programming in ML Python

Choose your learning style9 modes available
Introduction

We want to understand how machine learning is different from regular programming. This helps us know when to use each method.

When you have clear rules to solve a problem, like calculating a sum or sorting a list.
When you want the computer to learn patterns from data, like recognizing pictures or understanding speech.
When the problem is too complex to write exact rules, like predicting weather or recommending movies.
When you want to improve a system by learning from new examples over time.
When you need quick decisions based on past experience without writing detailed instructions.
Syntax
ML Python
Traditional Programming:
  Input + Program (rules) -> Output

Machine Learning:
  Input + Output (examples) -> Program (model)

Then:
  New Input + Program (model) -> Output

Traditional programming needs exact rules written by a person.

Machine learning creates rules by learning from examples.

Examples
We tell the computer exactly how to add numbers.
ML Python
Traditional Programming:
  Input: 5 and 3
  Program: Add the two numbers
  Output: 8
The computer learns from examples instead of being told exact rules.
ML Python
Machine Learning:
  Input: Pictures of cats and dogs with labels
  Output: Model that can tell if a new picture is a cat or dog
Sample Program

The first part shows a fixed rule to calculate area. The second part shows machine learning where the model learns from data to predict scores.

ML Python
from sklearn.linear_model import LinearRegression
import numpy as np

# Traditional programming example (simple rule):
# Calculate area of rectangle
length = 5
width = 3
area = length * width
print(f"Traditional programming area: {area}")

# Machine learning example:
# Given data of hours studied and scores, learn to predict score
X = np.array([[1], [2], [3], [4], [5]])  # hours studied
y = np.array([1.5, 3.5, 5.0, 7.0, 8.5])  # scores
model = LinearRegression()
model.fit(X, y)

# Predict score for 6 hours studied
predicted_score = model.predict([[6]])[0]
print(f"ML predicted score for 6 hours: {predicted_score:.2f}")
OutputSuccess
Important Notes

Traditional programming works well when rules are simple and clear.

Machine learning is useful when rules are hard to write but data is available.

Machine learning models improve as they see more data.

Summary

Traditional programming uses fixed rules to get answers.

Machine learning learns rules from examples to make predictions.

Choose the method based on problem complexity and data availability.