← Articles
Tutorials2024-02-2012 min read

Building Your First ML Model with Python

Step-by-step tutorial on creating and training your first machine learning model.

pythonscikit-learntutorialbeginner

Building Your First ML Model

In this tutorial, we'll walk through creating a simple machine learning model using Python and scikit-learn.

Prerequisites

  • Python 3.8+
  • NumPy
  • Pandas
  • Scikit-learn

Getting Started

import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression

Loading Data

df = pd.read_csv("data.csv")
X = df[["feature1", "feature2", "feature3"]]
y = df["target"]

Train-Test Split

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

Training

model = LinearRegression()
model.fit(X_train, y_train)
score = model.score(X_test, y_test)
print(f"R² Score: {score:.4f}")

Next Steps

From here you can explore more complex models like Random Forests, Gradient Boosting, and Neural Networks.