Data Science

Your First Model: Linear Regression

SQL Mastery Team
June 13, 2026
6 min read

Welcome to **Day 143**. We're building a robot that predicts the future.

Linear Regression: y = mx + c

Remember high school math? Linear regression finds the best straight line that goes through your data points.

The Code

from sklearn.linear_model import LinearRegression

from sklearn.model_selection import train_test_split

# 1. Prepare Data

X = df[['square_feet']]

y = df['price']

# 2. Split into Train and Test (More on this tomorrow!)

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

# 3. Fit the Model (Learning)

model = LinearRegression()

model.fit(X_train, y_train)

# 4. Predict!

prediction = model.predict([[2000]]) # Predict price for 2000 sq ft

print(f"Predicted Price: {prediction[0]}")

Why it's the "Gold Standard"

Even with complex Neural Networks, most companies still use Linear Regression for 80% of their work because it's fast, interpretable, and rarely breaks.

Your Task for Today

Model the relationship between "Price" and "Quantity" in your dataset using `LinearRegression`.

*Day 144: Training vs Testing Sets.*

Ready to put your knowledge into practice?

Join SQL Mastery and learn through interactive exercises.