Machine Learning
What is machine learning?
Machine learning is a branch of AI that enables computers to learn from data instead of explicit methods.
What is machine learning?
In classic programming you write the rules: input + rules → output. In machine learning you have inputs and the correct answers; the algorithm extracts the rule from the data: input + output → model.
# Rule written by hand
def fiyat_kural(m2):
return m2 * 1000
# Rule learned from data
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit([[50], [80], [120]], [52000, 79000, 121000])
print(model.predict([[100]]))
The model stores the pattern in the training data as a set of numbers (parameters) and produces predictions for inputs it has never seen.
Where is it used?
Anywhere writing the rule by hand is hard or impossible:
- Spam filter: learns from thousands of labelled e-mails.
- Price prediction: estimates the price from size, location and so on.
- Image recognition: finds the object from pixels.
- Recommendation systems: produce suggestions from similar users' preferences.
The workflow is always the same: collect data, train the model with fit, predict with predict, measure the result.
Exercise Your first model
Train a LinearRegression model with the given X (square metres) and y (price). Round the prediction for 100 m² to an integer with round and print it.
Show example solution
from sklearn.linear_model import LinearRegression
X = [[50], [80], [120]]
y = [50000, 80000, 120000]
model = LinearRegression()
model.fit(X, y)
print(round(model.predict([[100]])[0]))
Test yourself
-
What is the key difference between machine learning and classic programming?
- No data is needed
- The result is always exactly right
- The rules are learned from data
- The code is shorter
Show answer
The rules are learned from data — The model finds the relationship between inputs and correct answers itself; predictions are probabilistic and approximate.
-
Write the method that trains the model.
model = LinearRegression()
model.____(X, y)
Show answer
model = LinearRegression()
model.fit(X, y)
-
Match the concepts.
- model
- The rule learned from data
- fit
- The training step
- predict
- Prediction for a new input
- parametre
- Numbers the model stores
Next lesson: Supervised and unsupervised