Salary Prediction System Using Machine Learning

1. Introduction

Salary Prediction System is a beginner-friendly Machine Learning project that predicts an employee's expected salary based on factors such as years of work experience, education level, and working hours.

In many organizations, salary can be influenced by several factors. Employees with more experience may receive higher salaries, while education level and working responsibilities can also affect compensation. Machine Learning can be used to analyze historical employee data and learn the relationship between these factors and salary.

This is a Supervised Machine Learning problem because the model is trained using historical employee records where both the input information and the actual salary values are already known.

The target variable in this project is Salary, which is a continuous numerical value. Therefore, this is a Regression problem.

For this project, we use Linear Regression, a simple and commonly used Machine Learning algorithm for predicting continuous numerical values.

2. Objective

The main objective of this project is to build a Machine Learning model that learns the relationship between employee information and salary, then uses this learned relationship to predict the expected salary of a new employee.

The project demonstrates important Machine Learning concepts such as:

  • Creating an employee dataset

  • Selecting input features

  • Selecting a continuous target variable

  • Regression

  • Linear Regression

  • Model training

  • Making predictions

  • Interpreting numerical predictions

3. Features Used

The model uses three input features.

Experience Years

Experience_Years represents the number of years an employee has worked. Generally, employees with more professional experience may have higher salaries.

Education Level

Education_Level represents the employee's education level.

For this sample dataset, the values are represented numerically:

  • 1 – Basic/Undergraduate level

  • 2 – Intermediate/Higher education level

  • 3 – Advanced education level

This numerical representation allows the Machine Learning algorithm to use education as an input feature.

Working Hours

Working_Hours represents the approximate number of hours the employee works per week.

The target variable is:

Salary – The employee's salary represented as a numerical value.

4. Technologies Used

The following technologies are used:

  • Python – Main programming language.

  • Pandas – Used to create and manage the employee dataset.

  • Scikit-learn – Used to implement the Machine Learning algorithm.

  • Linear Regression – Used for predicting salary.

5. Dataset

The project uses a small sample dataset containing seven employee records.

Each record contains:

  • Experience in years

  • Education level

  • Working hours

  • Salary

Dataset

   Experience_Years  Education_Level  Working_Hours  Salary
0                 1                1             40   30000
1                 2                1             42   35000
2                 3                2             45   45000
3                 5                2             45   60000
4                 7                3             50   75000
5                10                3             50   95000
6                12                3             55  110000

The model uses these historical examples to learn the relationship between employee characteristics and salary.

6. Working Principle

The Salary Prediction System follows a basic supervised Machine Learning workflow.

First, an employee dataset is created using Python and Pandas. The dataset contains employee information and their corresponding salaries.

Next, the three input features—Experience_Years, Education_Level, and Working_Hours—are selected and stored in X.

The Salary column is selected as the target variable and stored in y.

A Linear Regression model is then created using Scikit-learn.

The model is trained using the historical employee data. During training, it learns the relationship between the employee features and their salary.

After the training process, information about a new employee is provided to the model. The model uses the learned relationship to estimate the employee's expected salary.

7. Python Implementation

The following Python program implements the Salary Prediction System.

# Import required libraries

import pandas as pd
from sklearn.linear_model import LinearRegression

# --------------------------------------------
# Step 1: Create the dataset
# --------------------------------------------

# Sample employee salary data

data = {
    "Experience_Years": [1, 2, 3, 5, 7, 10, 12],
    "Education_Level": [1, 1, 2, 2, 3, 3, 3],
    "Working_Hours": [40, 42, 45, 45, 50, 50, 55],
    "Salary": [30000, 35000, 45000, 60000, 75000, 95000, 110000]
}

# Convert dictionary into DataFrame

df = pd.DataFrame(data)

# Display dataset

print("Dataset:")
print(df)

# --------------------------------------------
# Step 2: Select input features (X)
# --------------------------------------------

X = df[
    [
        "Experience_Years",
        "Education_Level",
        "Working_Hours"
    ]
]

# --------------------------------------------
# Step 3: Select target variable (y)
# --------------------------------------------

y = df["Salary"]

# --------------------------------------------
# Step 4: Create Linear Regression model
# --------------------------------------------

model = LinearRegression()

# --------------------------------------------
# Step 5: Train the model
# --------------------------------------------

model.fit(X, y)

# --------------------------------------------
# Step 6: Predict salary
# --------------------------------------------

# New employee details:
# Experience = 6 years
# Education Level = 2
# Working Hours = 45

new_employee = [[6, 2, 45]]

predicted_salary = model.predict(new_employee)

# --------------------------------------------
# Step 7: Display prediction
# --------------------------------------------

print("\nPredicted Salary:")
print(f"${predicted_salary[0]:,.2f}")

8. Explanation of the Python Program

The program begins by importing Pandas and Linear Regression from Scikit-learn.

Pandas is used to create the employee dataset, while Linear Regression is used to predict the continuous salary value.

Step 1: Create the Dataset

A Python dictionary is created containing information about seven employees.

For example:

Experience = 1 year
Education Level = 1
Working Hours = 40
Salary = $30,000

The dictionary is converted into a Pandas DataFrame.

Step 2: Select Input Features

The three employee-related features are selected:

X = df[
    [
        "Experience_Years",
        "Education_Level",
        "Working_Hours"
    ]
]

These features are used by the model to predict salary.

Step 3: Select Target Variable

The Salary column is selected as the target variable:

y = df["Salary"]

Unlike a classification problem, salary is a continuous numerical value.

Step 4: Create the Model

A Linear Regression model is created:

model = LinearRegression()

Linear Regression is suitable because the goal is to predict a numerical value.

Step 5: Train the Model

The model is trained using:

model.fit(X, y)

During training, the model learns the relationship between experience, education level, working hours, and salary.

Step 6: Predict a New Employee's Salary

The new employee has the following details:

Experience = 6 years
Education Level = 2
Working Hours = 45

The information is provided to the trained model:

new_employee = [[6, 2, 45]]

predicted_salary = model.predict(new_employee)

The model calculates an estimated salary based on the patterns learned from the training data.

9. Prediction

Input

Experience = 6 years
Education Level = 2
Working Hours = 45

Output

Predicted Salary:

$65,500.00

The model predicts that the new employee's expected salary is $65,500.00 based on the sample dataset.

This value is an estimate produced by the Machine Learning model and does not represent a guaranteed salary.

10. How Linear Regression Works

Linear Regression is a supervised Machine Learning algorithm used to predict continuous numerical values.

In this project, the target variable is salary.

The model attempts to find a mathematical relationship between the input features and salary.

The basic idea can be represented as:

Salary =
    (Experience × Weight)
  + (Education × Weight)
  + (Working Hours × Weight)
  + Intercept

During training, Linear Regression calculates suitable coefficients for the input variables.

For example, the model learns how changes in experience, education level, and working hours are associated with changes in salary.

When a new employee is entered, the learned coefficients are used to calculate an estimated salary.

11. Advantages

The Salary Prediction project has several advantages:

  • Simple and beginner-friendly.

  • Demonstrates regression concepts.

  • Uses multiple input features.

  • Easy to implement using Python.

  • Demonstrates prediction of continuous values.

  • Linear Regression is computationally efficient.

  • Easy to understand and interpret.

  • Can be extended with additional employee information.

12. Limitations

The biggest limitation of this project is the very small sample dataset. Only seven employee records are used for training, which is not enough for a reliable real-world salary prediction system.

Real-world salaries depend on many additional factors that are not included in this example.

These may include:

  • Job position

  • Industry

  • Location

  • Company size

  • Technical skills

  • Professional certifications

  • Performance

  • Management responsibilities

  • Market demand

  • Previous salary

  • Employment type

Education level is also simplified into numerical values in this example. In a real system, education categories may need to be represented using suitable encoding methods.

The model also has not been evaluated using a separate testing dataset.

13. Future Improvements

The project can be improved by collecting a much larger and more diverse employee dataset.

Additional features can be included, such as:

  • Job title

  • Department

  • Location

  • Years of experience

  • Skills

  • Industry

  • Company size

  • Education qualification

  • Certifications

The dataset can be divided into training and testing datasets to evaluate model performance.

The prediction system can also be evaluated using regression metrics such as:

  • Mean Absolute Error (MAE)

  • Mean Squared Error (MSE)

  • Root Mean Squared Error (RMSE)

  • R² Score

Other regression algorithms can also be compared with Linear Regression, including:

  • Decision Tree Regression

  • Random Forest Regression

  • Gradient Boosting Regression

  • Support Vector Regression

Feature scaling and data preprocessing can also be introduced for more advanced implementations.

14. Real-World Applications

Salary prediction systems can be useful in several areas.

Recruitment

Companies can estimate potential salary ranges for new employees based on their experience, skills, and qualifications.

Career Planning

Employees can analyze how factors such as experience and skills may affect potential salary levels.

Human Resources

HR departments can use data-driven models to analyze salary patterns within an organization.

Job Market Analysis

Organizations can analyze salary trends across different roles, industries, and locations.

Compensation Planning

Businesses can use historical salary data to support compensation planning and budgeting.

However, real-world salary decisions should consider fairness, legal requirements, market conditions, and human judgment rather than relying solely on a Machine Learning prediction.

15. Conclusion

The Salary Prediction System Using Machine Learning project demonstrates how supervised Machine Learning can be used to predict a continuous numerical value.

The project uses Linear Regression with three input features: experience years, education level, and working hours. The model learns from historical employee data where the actual salary is already known.

For the new employee with:

Experience = 6 years
Education Level = 2
Working Hours = 45

the model produces the following prediction:

Predicted Salary:

$65,500.00

This project provides a simple introduction to regression, feature selection, model training, and numerical prediction. With a larger real-world dataset, additional features, proper evaluation, and more advanced algorithms, the system can be developed into a more comprehensive salary analysis and prediction application.