Build Your First Model
Ready to write real AI code? In this lesson you'll build a classifier — an AI that can sort things into categories.
What you need
- Python 3.10+ installed
- A terminal / command prompt
- 15 minutes
The project: Fruit classifier
We'll teach an AI to tell apart apples and oranges based on two features:
- Weight (grams)
- Texture (0 = smooth, 1 = bumpy)
Step 1: Install scikit-learn
pip install scikit-learn
Step 2: Write the training data
from sklearn.tree import DecisionTreeClassifier
X_train = [
[150, 0], # apple
[170, 0], # apple
[130, 0], # apple
[200, 1], # orange
[220, 1], # orange
[180, 1], # orange
]
y_train = [0, 0, 0, 1, 1, 1]
Step 3: Train the model
model = DecisionTreeClassifier()
model.fit(X_train, y_train)
print("Model trained!")
Step 4: Make predictions
new_fruit = [[160, 0]]
prediction = model.predict(new_fruit)
if prediction[0] == 0:
print("That's an apple!")
else:
print("That's an orange!")
What just happened?
- You gave the model labeled examples (training data)
- The model found patterns (heavy + bumpy = orange)
- The model generalized to new data it never saw
This is machine learning in its simplest form!
Musubi's Challenge
Add a third fruit (bananas!) to your training data. What features would you use?
You built your first AI model. Welcome to the Builder tier!