Traditional programming vs Machine learning programming

H Dev
3 min readJul 28, 2023

Traditional Programming and Machine Learning Programming are two different approaches to solving problems in the field of computer science. Here’s a more detailed comparison between the two:

1. Traditional Programming:
Traditional programming, also known as rule-based or deterministic programming, involves explicitly writing a set of instructions (rules) that tell the computer how to perform a specific task. The programmer must have a deep understanding of the problem domain and provide step-by-step solutions for the computer to follow.

Key Characteristics:
- Rules: The programmer defines explicit rules or algorithms that dictate how the program should behave.
- Manual Coding: The entire logic and decision-making process are explicitly coded by the developer.
- Data Input: The input data is processed through predefined rules, and the output is generated accordingly.
- Maintenance: Any changes to the logic or rules require manual code modifications.
- Suitable For: Tasks with well-defined rules and clear solutions, such as mathematical computations and simple logical operations.

Example:
```python
# Traditional program to calculate the area of a rectangle
def calculate_area(length, width):
area = length * width
return area

length = 5
width = 10
result = calculate_area(length, width)
print(result) # Output: 50
```

Photo by Markus Winkler on Unsplash

2. Machine Learning Programming:
Machine Learning (ML) programming involves building models that can learn from data and make predictions or decisions without being explicitly programmed. Instead of manually providing rules, the programmer feeds the model with data and desired outcomes, and the model learns patterns and relationships from the data to make predictions or decisions on new, unseen data.

Key Characteristics:
- Data-Driven: Machine learning models learn patterns from data, making them capable of handling complex tasks.
- Training Phase: The model is trained on a labeled dataset to learn patterns and relationships.
- Generalization: After training, the model can generalize its knowledge to make predictions on new, unseen data.
- Maintenance: Model updates can be performed by retraining with new data instead of manually rewriting rules.
- Suitable For: Tasks where patterns are difficult to define explicitly, such as image recognition, language translation, and recommendation systems.

Example (Linear Regression in ML):
```python
# Machine Learning model to predict house prices based on house size
from sklearn.linear_model import LinearRegression

# Sample data (house size in square feet)
X = [[1000], [1500], [2000], [2500]]
# Corresponding house prices in dollars
y = [200000, 300000, 400000, 500000]

# Create and train the model
model = LinearRegression()
model.fit(X, y)

# Predict the price for a new house
new_house_size = [[1800]]
predicted_price = model.predict(new_house_size)
print(predicted_price) # Output: [360000]
```

In summary, traditional programming requires the programmer to manually specify rules, while machine learning programming relies on data and algorithms to learn from that data and make decisions. Machine learning is particularly powerful in scenarios where the underlying patterns are complex or difficult to express explicitly. Hope you got the distinction.

Happy learning, follow and clap to shower encouragement!

--

--

H Dev

just another X-shaped personality, love to learn and tinker with new tech.