0
0
ML Pythonprogramming~5 mins

Why regression predicts continuous values in ML Python

Choose your learning style9 modes available
Introduction

Regression helps us find numbers that can be any value, not just fixed choices. It predicts things like prices or temperatures that change smoothly.

Estimating house prices based on size and location
Predicting the temperature for tomorrow
Forecasting sales numbers for the next month
Calculating the amount of fuel a car will use on a trip
Syntax
ML Python
model = RegressionModel()
model.fit(training_data, target_values)
predictions = model.predict(new_data)

The model learns from data with continuous target values.

Predictions are numbers that can take any value, not just categories.

Examples
This example uses a simple linear regression to predict continuous values.
ML Python
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
A decision tree can also predict continuous values by splitting data into ranges.
ML Python
from sklearn.tree import DecisionTreeRegressor
model = DecisionTreeRegressor()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
Sample Program

This program trains a simple linear regression model to predict exam scores based on hours studied. It then predicts the score for 6 hours.

ML Python
from sklearn.linear_model import LinearRegression
import numpy as np

# Training data: hours studied vs exam score
X_train = np.array([[1], [2], [3], [4], [5]])
y_train = np.array([50, 55, 65, 70, 75])

# Create and train the model
model = LinearRegression()
model.fit(X_train, y_train)

# Predict score for 6 hours studied
X_test = np.array([[6]])
prediction = model.predict(X_test)
print(f"Predicted score for 6 hours studied: {prediction[0]:.2f}")
OutputSuccess
Important Notes

Regression models output continuous numbers, unlike classification which outputs categories.

Choosing the right regression model depends on the data shape and problem.

Summary

Regression predicts numbers that can be any value, not just fixed groups.

It is useful when the result is a quantity like price, temperature, or score.

Models learn from examples with continuous target values to make predictions.