Skip to content
Everything About Coding

Everything About Coding

The best platform you can find for coding

Build a Simple Machine Learning Model in Python to Predict Exam Marks

Posted on June 2, 2025 c3xb6 By c3xb6 No Comments on Build a Simple Machine Learning Model in Python to Predict Exam Marks

Machine Learning (ML) is transforming industries by enabling systems to learn from data and make intelligent predictions. In this post, we will walk through a beginner-friendly example of implementing machine learning in Python using linear regression โ€” one of the simplest yet powerful ML algorithms.

We’ll build a predictive model that estimates a student’s exam score based on the number of hours they studied. This use case is ideal for beginners who are starting their machine learning journey with Python.

๐Ÿงพ Objective

To implement a linear regression model using Python and scikit-learn that can predict student performance based on study hours.

๐Ÿงฎ The Python Code

from sklearn.linear_model import LinearRegression
import numpy as np

# Sample dataset: hours studied vs scores obtained
hours = np.array([[1], [2], [3], [4], [5]])
scores = np.array([20, 40, 50, 65, 80])

# Initialize and train the model
model = LinearRegression()
model.fit(hours, scores)

# Make prediction based on user input
h = float(input('Enter hours studied: '))
prediction = model.predict([[h]])
print(prediction)

๐Ÿ“Š Understanding the Code

Importing Libraries
We use numpy for data handling and LinearRegression from sklearn.linear_model to create and train our model.

Training Data
A small dataset of hours studied vs scores is used to train the model.

Model Fitting
The .fit() method teaches the model the relationship between input (hours) and output (scores).

Prediction
The trained model predicts a score for the number of hours entered by the user.

๐ŸŽฏ Sample Output

Enter hours studied: 3.5
[57.5]

๐Ÿค– Why Use Linear Regression in Machine Learning?

Linear regression is a supervised learning algorithm used for predicting a continuous value. It is widely used in business, healthcare, education, and more to model relationships between variables and forecast outcomes.

In our example:

  • Input (X): Hours studied
  • Output (Y): Marks scored
  • The model tries to fit the best straight line (y = mx + c) that maps X to Y.

๐Ÿ’ก What You Can Do Next

  • Visualize the data and regression line using matplotlib
  • Collect real student performance data for better accuracy
  • Deploy this model as a web app using Flask or Streamlit

๐ŸŽฅ Learn by Watching

For more Python and machine learning tutorials, visit:

https://www.youtube.com/@EverythingAboutCoding

Uncategorized

Post navigation

Previous Post: ๐ŸŽ™๏ธ Smarter Speech Recognition with Python: Understanding adjust_for_ambient_noise()

Related Posts

  • Hello World Featured Image
    Say Hello to Python: The Language Behind AI, Apps, and Automation. Introduction to Python. Uncategorized
  • ๐ŸŽ™๏ธ Turn Text into Voice with Python | Beginner-Friendly TTS Project Uncategorized
  • python data types and mutable and immutable.
    ๐Ÿง  Dive Into Python Data Types: Understanding the Building Blocks of Code. Uncategorized
  • Build a Python Chatbot That Understands Typos and Similar Questions! Uncategorized
  • ๐ŸŽ™๏ธ Smarter Speech Recognition with Python: Understanding adjust_for_ambient_noise() Uncategorized

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Build a Simple Machine Learning Model in Python to Predict Exam Marks
  • ๐ŸŽ™๏ธ Smarter Speech Recognition with Python: Understanding adjust_for_ambient_noise()
  • ๐ŸŽ™๏ธ Turn Text into Voice with Python | Beginner-Friendly TTS Project
  • Build a Python Chatbot That Understands Typos and Similar Questions!
  • ๐Ÿง  Dive Into Python Data Types: Understanding the Building Blocks of Code.

Recent Comments

  1. A WordPress Commenter on Say Hello to Python: The Language Behind AI, Apps, and Automation. Introduction to Python.

Archives

  • June 2025
  • May 2025
  • April 2025

Categories

  • Programming
  • Uncategorized

Copyright © 2025 Everything About Coding.

Powered by PressBook News WordPress theme