How I Built My First Machine Learning Model Using Python: A Beginner's Guide
My First Machine Learning Model: Predicting Whether I Will Like a Movie
As part of my AI/ML Upgrade Phase, I built my first Machine Learning project using Python and Scikit-learn.
The goal was simple:
Although this is a small project, it helped me understand the complete Machine Learning workflow—from creating a dataset to training a model, saving it, and making predictions.
What Is Machine Learning?
In traditional programming, developers write rules manually.
If marks > 50
Pass
Else
Fail
Machine Learning works differently.
Instead of writing rules, we provide examples. The algorithm studies those examples, learns patterns, and predicts results for new data.
Step 1: Creating the Dataset
Every ML project begins with data.
length,action,comedy,liked
90,8,2,1
120,9,1,1
80,2,9,1
150,10,1,0
70,1,8,1
140,9,2,0
100,5,5,1
130,8,3,0
95,4,7,1
160,10,1,0
Column Description
- length → Movie duration (minutes)
- action → Action score (1–10)
- comedy → Comedy score (1–10)
- liked → Target value
0 = Did not like the movie
Step 2: Installing Required Libraries
pip install pandas scikit-learn joblib
Pandas
Reads and manages datasets.
Scikit-learn
Provides Machine Learning algorithms.
Joblib
Saves and loads trained models.
Step 3: Loading the Dataset
import pandas as pd
data = pd.read_csv("movies.csv")
Pandas converts the CSV file into a table that Python can understand.
Step 4: Features and Target
Features (Inputs)
X = data[['length','action','comedy']]
- Movie Length
- Action Level
- Comedy Level
Target (Output)
y = data['liked']
The model learns:
Length + Action + Comedy
↓
Like / Don't Like
Step 5: Choosing the Algorithm
For this project, I selected a Decision Tree Classifier.
from sklearn.tree import DecisionTreeClassifier
model = DecisionTreeClassifier()
A Decision Tree learns by asking questions.
Action > 7?
│
Yes
│
Length < 130?
│
Yes
│
Like
Step 6: Training the Model
model.fit(X, y)
The training process:
- Reads every example
- Finds patterns
- Creates decision rules
- Stores learned knowledge
Step 7: Saving the Model
import joblib
joblib.dump(model,"movie_model.pkl")
The file movie_model.pkl contains everything the model learned during training.
Complete Training Script
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
import joblib
data = pd.read_csv("movies.csv")
X = data[['length','action','comedy']]
y = data['liked']
model = DecisionTreeClassifier()
model.fit(X,y)
joblib.dump(model,"movie_model.pkl")
print("Model trained and saved!")
Step 8: Loading the Saved Model
import joblib
model = joblib.load("movie_model.pkl")
No retraining is required. The model is instantly ready for predictions.
Step 9: Making Predictions
length = int(input("Movie Length: "))
action = int(input("Action Level (1-10): "))
comedy = int(input("Comedy Level (1-10): "))
prediction = model.predict([[length,action,comedy]])
if prediction[0]==1:
print("You will probably LIKE this movie 🎬")
else:
print("You will probably NOT LIKE this movie ❌")
Example Prediction
Movie Length: 100
Action Level: 7
Comedy Level: 4
Output:
You will probably LIKE this movie 🎬
Conclusion
Building this movie prediction model was my first step into the world of Machine Learning, and it gave me hands-on experience with the complete ML workflow—from creating a dataset and training a model to saving it and making predictions. While the project is simple, it helped me understand the core concepts that power modern AI applications. This experience has motivated me to continue learning advanced topics such as data preprocessing, model evaluation, deep learning, and neural networks. Every expert starts with a beginner project, and this marks the beginning of my AI/ML journey.