Ai Coding Tools

How to Train Your First AI Model in Just 2 Hours

By BTW Team4 min read

Comparing tools? See the AI tools tested on the show.

In short

A hands-on tutorial that guides you through the entire process of training your first AI model and deploying it in just 2 hours.

Training your first AI model can feel like an overwhelming task, especially if you're building as a solo founder or indie hacker. The myriad of tools and frameworks available can paralyze you with choices. But here's the thing: it doesn’t have to be complicated or time-consuming. In this guide, I’ll walk you through how to train a simple AI model in just 2 hours using accessible tools and a straightforward approach.

Prerequisites: What You'll Need

Before diving in, make sure you have the following:

  1. Basic Python Knowledge: Familiarity with Python is crucial as most AI tools use it.
  2. Python Installed: Ensure you have Python 3.x installed on your machine.
  3. Jupyter Notebook: This is a great environment for running Python code interactively.
  4. An Account on Google Colab: Free access to GPUs can speed up your training process.

Step 1: Set Up Your Environment

To get started, you’ll want to set up your coding environment. If you’re using Google Colab, follow these steps:

  1. Go to Google Colab.
  2. Create a new notebook.
  3. Install necessary libraries by running:
    !pip install numpy pandas scikit-learn tensorflow
    

Step 2: Choose Your Dataset

For this guide, we'll use the popular Iris dataset, which is excellent for beginners. It’s small and manageable, allowing you to focus on training without getting bogged down by complexity.

You can load the dataset directly from the UCI Machine Learning Repository using:

import pandas as pd

url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
columns = ["sepal_length", "sepal_width", "petal_length", "petal_width", "class"]
data = pd.read_csv(url, names=columns)

Step 3: Preprocess the Data

Next, we need to prepare our data for training:

  1. Handle Missing Values: Check for any missing data.
  2. Encode Categorical Variables: Convert class labels into numbers.
  3. Split the Data: Separate your dataset into features and labels, then into training and testing sets.

Here’s how you can do that:

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder

X = data.iloc[:, :-1]
y = data.iloc[:, -1]

encoder = LabelEncoder()
y = encoder.fit_transform(y)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

Step 4: Train the Model

We’ll use TensorFlow to build a simple neural network. Here’s the code:

import tensorflow as tf

model = tf.keras.Sequential([
    tf.keras.layers.Dense(10, activation='relu', input_shape=(X_train.shape[1],)),
    tf.keras.layers.Dense(3, activation='softmax')
])

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(X_train, y_train, epochs=50)

Step 5: Evaluate the Model

After training, it’s crucial to evaluate the model's performance:

loss, accuracy = model.evaluate(X_test, y_test)
print(f"Model accuracy: {accuracy:.2f}")

Troubleshooting: What Could Go Wrong

  1. Installation Issues: If libraries fail to install, check your Python version and ensure you’re using the right environment.
  2. Model Not Training Properly: Double-check your dataset for any issues and ensure your model architecture is set up correctly.
  3. Low Accuracy: Experiment with different architectures or hyperparameters. More epochs or layers can sometimes yield better results.

What's Next

Once you've trained your first model, consider the following steps:

  • Deploy Your Model: Look into platforms like Heroku or AWS to deploy your model.
  • Experiment Further: Try different datasets or model architectures to deepen your understanding.
  • Join Communities: Engage with AI communities for support and further learning.

Conclusion: Start Here

Training your first AI model doesn't have to be a daunting task. With just a couple of hours and the right tools, you can go from zero to a functioning model. Start with the Iris dataset and follow the steps outlined here to build your confidence.

What We Actually Use

In our experience, we recommend using Google Colab for its ease of use and free GPU access. TensorFlow is our go-to framework for building models due to its flexibility and community support.

If you're looking for a more extensive toolkit for AI coding, consider checking out the following tools:

| Tool | Pricing | Best For | Limitations | Our Verdict | |--------------------|---------------------------|---------------------------|------------------------------------|---------------------------------| | Google Colab | Free | Quick prototyping | Limited runtime; connection drops | Great for quick experiments | | TensorFlow | Free | Deep learning projects | Steeper learning curve | Powerful but complex | | Jupyter Notebook | Free | Interactive coding | Requires setup if not using Colab | Excellent for prototyping | | PyTorch | Free | Research and prototyping | Less beginner-friendly than TF | Preferred for dynamic models | | Scikit-learn | Free | Traditional ML algorithms | Not for deep learning | Perfect for classical ML tasks | | Hugging Face | Free tier + $20/mo pro | NLP tasks | Can get costly with large models | Excellent for language models |

Watch real AI builds every week

Built This Week is a weekly podcast where Jordan Metzner and Sam Nadler build something real with AI every episode, test new AI tools and talk with founders who build with AI.

See the tools

Watch real AI builds every week

Built This Week is a weekly podcast where Jordan Metzner and Sam Nadler build something real with AI every episode, test new AI tools and talk with founders who build with AI.

See the tools
Ai Coding Tools

3 AI Coding Tools That Are Overrated (and Why You Should Avoid Them)

3 AI Coding Tools That Are Overrated (and Why You Should Avoid Them) In the everevolving landscape of AI coding tools, it's easy to get swept up in the hype. As indie hackers and s

Nov 30, 20263 min read
Ai Coding Tools

5 Ways AI Coding Tools Can Accelerate Your MVP Development in 2026

5 Ways AI Coding Tools Can Accelerate Your MVP Development in 2026 In 2026, the landscape for indie hackers and solo founders has evolved significantly, especially with the advent

Nov 26, 20264 min read
Ai Coding Tools

5 AI Coding Tools That Make Legacy Code Feel Brand New in 2026

5 AI Coding Tools That Make Legacy Code Feel Brand New in 2026 If you’re a developer stuck maintaining legacy code, you know the frustration. It’s like navigating a maze blindfolde

Nov 23, 20264 min read
Ai Coding Tools

10 AI Coding Tools That Will Save You Hours of Debugging in 2026

10 AI Coding Tools That Will Save You Hours of Debugging in 2026 Debugging can feel like a neverending cycle of frustration. Whether you're a solo founder or an indie hacker, spend

Nov 18, 20265 min read
Ai Coding Tools

10 Common Mistakes When Using AI Coding Tools for MVP Development

10 Common Mistakes When Using AI Coding Tools for MVP Development As a founder in 2026, you’re likely aware that AI coding tools can significantly speed up the MVP development proc

Nov 16, 20264 min read
Ai Coding Tools

5 AI Coding Myths Every Beginner Developer Should Ditch in 2026

5 AI Coding Myths Every Beginner Developer Should Ditch in 2026 As a beginner developer, you’ve probably come across a ton of buzz surrounding AI coding tools. But with all the hyp

Nov 12, 20263 min read