What is machine learning?
- Machine Learning course
- Beginner
- Lesson 1/112
- 5 min
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.
Practice 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.
Starter code
from sklearn.linear_model import LinearRegression
X = [[50], [80], [120]]
y = [50000, 80000, 120000]
# buraya yazSample 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]))Expected output
100000
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 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 Correct answer
- The code is shorter
Explanation: The model finds the relationship between inputs and correct answers itself; predictions are probabilistic and approximate.
2 Write the method that trains the model.
model = LinearRegression()
model.____(X, y)
model = LinearRegression()
model.fit(X, y)
Explanation: In scikit-learn every model is trained with fit(X, y).
3 Match the concepts.
| Term | Meaning |
|---|---|
model |
The rule learned from data |
fit |
The training step |
predict |
Prediction for a new input |
parametre |
Numbers the model stores |