ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing
ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing

All Courses

Introduction to Machine Learning
Chapter 1: What is Machine Learning?
Defining Machine Learning
Why Learn Machine Learning?
Examples of ML in Everyday Life
Distinguishing ML from Traditional Programming
Types of Machine Learning Systems
The Machine Learning Workflow Overview
Tools You Might Use
Quiz for Chapter 1
Chapter 2: Fundamental Concepts
Data: The Fuel for Machine Learning
Features and Labels Explained
Training, Validation, and Test Sets
Models: Learning from Data
Parameters and Hyperparameters
Introduction to Overfitting and Underfitting
Measuring Performance: Basic Metrics
Quiz for Chapter 2
Chapter 3: Supervised Learning: Regression
Understanding Regression Problems
Introduction to Linear Regression
How Linear Regression Learns
Cost Functions: Measuring Error
Gradient Descent: Finding the Best Fit
Simple Linear Regression Example
Practice: Implementing Simple Linear Regression
Quiz for Chapter 3
Chapter 4: Supervised Learning: Classification
Understanding Classification Problems
Introduction to Logistic Regression
The Sigmoid Function
Decision Boundaries
Introduction to K-Nearest Neighbors (KNN)
How KNN Works
Evaluating Classification Models
Practice: Implementing KNN for Classification
Quiz for Chapter 4
Chapter 5: Unsupervised Learning: Clustering
What is Unsupervised Learning?
Introduction to Clustering
The K-Means Algorithm
Choosing the Number of Clusters (K)
How K-Means Finds Clusters
Limitations of K-Means
Practice: Applying K-Means to Simple Data
Quiz for Chapter 5
Chapter 6: Preparing Your Data
The Importance of Data Preprocessing
Handling Missing Values
Introduction to Feature Scaling
Encoding Categorical Features
Splitting Data into Training and Testing Sets Revisited
Hands-on Practical: Basic Data Cleaning Steps
Quiz for Chapter 6
Chapter 7: Building Your First Machine Learning Model
Recap: The ML Workflow Steps
Choosing the Right Algorithm
Loading and Preparing Data with a Library
Training a Simple Model
Making Predictions
Evaluating Model Performance
Hands-on Practical: End-to-End Simple Model Building
Quiz for Chapter 7

Making Predictions

A machine learning model learns patterns from its training data once trained. But the true test of a model isn't how well it knows the data it trained on; it's how well it performs on new, unseen data. This is where making predictions comes in. The purpose of building a model is usually to apply it to future situations where the outcome is unknown.

Using the Trained Model for Predictions

Once a model is trained (often using a fit() method in libraries like Scikit-learn), it stores the learned patterns internally (as parameters). To get predictions, you typically use a method called predict(). This method takes new input data (features only, no labels) and uses the learned patterns to generate an output, which is the model's prediction for each input instance.

Imagine you trained a linear regression model to predict house prices based on square footage. The training process found the best line (defined by slope and intercept) through your training data points. Now, if you have a new house with a known square footage (but unknown price), you can feed this square footage into the predict() method of your trained model. The model will use its learned line equation (y=mx+by = mx + by=mx+b) to calculate the predicted price (yyy) for that square footage (xxx).

Preparing the Input Data

A very important point: the new data you provide to the predict() method must have the exact same structure and preprocessing as the data the model was trained on. This means:

  1. Same Features: It must contain the same features (columns) that the model expects.
  2. Same Order: The features must be in the same order.
  3. Same Preprocessing: If you scaled your training features (e.g., using Standardization or Normalization) or encoded categorical features (e.g., using One-Hot Encoding), you must apply the exact same transformations to the new data before making predictions. Use the same scaler or encoder object that was fitted on the training data.

Failure to prepare the input data correctly is a common source of errors and nonsensical predictions. The model only understands data in the format it learned from.

Making Predictions with Scikit-learn

Let's assume you have a trained model object named model (it could be a LinearRegression, LogisticRegression, KNeighborsClassifier, etc.) and your new, unseen data (features only) is stored in a variable called X_new. This X_new should be formatted appropriately (e.g., a NumPy array or pandas DataFrame with the correct columns and scaling).

Making predictions is usually straightforward:

# Assuming 'model' is your trained Scikit-learn model
# Assuming 'X_new' is your new data, preprocessed correctly

predictions = model.predict(X_new)

# Print the predictions
print(predictions)

The predictions variable will now hold the model's output for each instance in X_new.

Understanding the Output

The nature of the values in predictions depends on the type of problem your model was trained for:

  • Regression: If model is a regression model (like LinearRegression), predictions will contain continuous numerical values. For example, [250000.50, 180000.75, 310000.00] might be predicted house prices.
  • Classification: If model is a classification model (like LogisticRegression or KNeighborsClassifier), predictions will contain predicted class labels. For example, ['spam', 'not spam', 'spam'] or [1, 0, 1] (where 1 might represent 'spam' and 0 'not spam').

Getting Probabilities in Classification (Optional but Useful)

For many classification algorithms, you can get more detailed information than just the predicted class. Instead of asking "Which class does the model predict?", you can ask "What probability does the model assign to each class?". This is often done using a predict_proba() method.

# Assuming 'model' is a trained classification model
# Assuming 'X_new' is your new data, preprocessed correctly

probabilities = model.predict_proba(X_new)

# Print the probabilities
print(probabilities)

If you have two classes (e.g., 0 and 1), the output for predict_proba() might look something like this for three input instances:

[[0.1 0.9]  # Instance 1: 10% prob of class 0, 90% prob of class 1
 [0.8 0.2]  # Instance 2: 80% prob of class 0, 20% prob of class 1
 [0.4 0.6]] # Instance 3: 40% prob of class 0, 60% prob of class 1

Each row corresponds to an instance in X_new. Each column corresponds to a class (usually in sorted order, e.g., class 0 then class 1). The values in each row sum to 1. The standard predict() method typically just chooses the class with the highest probability. For instance 1 above, predict() would output class 1 (since 0.9 > 0.1). Knowing the probabilities can be valuable, especially if you want to understand the model's confidence or set different decision thresholds.

Now that you know how to use your trained model to make predictions on new data, the next logical step is to figure out how good those predictions actually are. We need ways to measure the model's performance, which is exactly what we'll cover in the next section on evaluation.

  • Scikit-learn User Guide, scikit-learn developers, 2023 - Provides a comprehensive overview of using Scikit-learn estimators, detailing methods like fit(), predict(), and predict_proba(), along with guidelines for consistent data preparation for inference.
  • Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems, Aurélien Géron, 2022 (O'Reilly Media) - A practical guide demonstrating how to train machine learning models and apply them to make predictions on new data, with emphasis on Scikit-learn and proper data handling.
  • An Introduction to Statistical Learning: With Applications in R, Gareth James, Daniela Witten, Trevor Hastie, Rob Tibshirani, 2021 (Springer) - A foundational text covering statistical learning methods, including the principles behind fitting models to data and using them for prediction and inference.

© 2026 ApX Machine Learning