Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web interface for Salary Prediction #727

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added DataAnalyticsSalaryPrediction/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions DataAnalyticsSalaryPrediction/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DataAnalyticsSalaryPrediction/Model/encoder.pkl
Binary file not shown.
277 changes: 277 additions & 0 deletions DataAnalyticsSalaryPrediction/Model/model.ipynb

Large diffs are not rendered by default.

Binary file added DataAnalyticsSalaryPrediction/Model/model1
Binary file not shown.
6 changes: 6 additions & 0 deletions DataAnalyticsSalaryPrediction/Model/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pandas
numpy
scikit-learn
tensorflow
matplotlib
keras
Binary file added DataAnalyticsSalaryPrediction/Model/scaler.pkl
Binary file not shown.
20 changes: 20 additions & 0 deletions DataAnalyticsSalaryPrediction/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Data Analysis Salary Prediction - Web Interface

### Goal 🎯

The main goal of this project is to provide an easy-to-use web interface for predicting Salary of various job posts accross India based on user input parameters. This tool aims to make salary predition accessible to non-technical users by integrating a machine learning model with a user-friendly Flask web application.

### Model(s) used for the Web App 🧮

The backend part of the web app uses a pre-trained machine learning model (`../Model`) serialized with `pickle`. The model was trained on a dataset of body measurements and is designed to predict body fat percentage accurately.

### Video Demonstration 🎥



### Signature ✒️

Developed by [Akshaykumar](https://github.com/MRMORNINGSTAR2233)

- [GitHub](https://github.com/MRMORNINGSTAR2233)
- [LinkedIn](https://www.linkedin.com/in/akshay-kumar-hegde/)
56 changes: 56 additions & 0 deletions DataAnalyticsSalaryPrediction/web/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
import pickle
import numpy as np
from flask import Flask, request, jsonify, render_template
from sklearn.preprocessing import OneHotEncoder, StandardScaler
import pandas as pd
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Input


app = Flask(__name__)

def create_model(optimizer='adam'):
model = Sequential()
model.add(Input(shape=(X_resampled.shape[1],))) # Assuming X_resampled.shape[1] is known
model.add(Dense(128, activation='relu', kernel_regularizer=tf.keras.regularizers.l2(0.01)))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu', kernel_regularizer=tf.keras.regularizers.l2(0.01)))
model.add(Dropout(0.5))
model.add(Dense(32, activation='relu', kernel_regularizer=tf.keras.regularizers.l2(0.01)))
model.add(Dense(5, activation='softmax'))
model.compile(optimizer=optimizer, loss='sparse_categorical_crossentropy', metrics=['accuracy'])
return model

# Load the trained model
with open('/Users/akshay/Desktop/ML-Crate/DataAnalyticsSalaryPrediction/Model/model1', 'rb') as file:
model = pickle.load(file)

# Load the encoder and scaler
with open('/Users/akshay/Desktop/ML-Crate/DataAnalyticsSalaryPrediction/Model/encoder.pkl', 'rb') as file:
encoder = pickle.load(file)

with open('/Users/akshay/Desktop/ML-Crate/DataAnalyticsSalaryPrediction/Model/scaler.pkl', 'rb') as file:
scaler = pickle.load(file)

# Preprocessing function
def preprocess_input(data):
df = pd.DataFrame(data, index=[0])
df_encoded = encoder.transform(df)
df_scaled = scaler.transform(df_encoded)
return df_scaled

@app.route('/')
def home():
return render_template('index.html')

@app.route('/predict', methods=['POST'])
def predict():
data = request.get_json()
input_data = preprocess_input(data)
prediction = model.predict(input_data)
return jsonify({'prediction': int(prediction[0])})

if __name__ == '__main__':
app.run(debug=True)
133 changes: 133 additions & 0 deletions DataAnalyticsSalaryPrediction/web/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Salary Prediction</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}

.container {
width: 50%;
margin: 50px auto;
background: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h1 {
text-align: center;
}

form {
display: flex;
flex-direction: column;
}

label {
margin: 10px 0 5px;
}

input {
padding: 10px;
font-size: 16px;
}

button {
padding: 10px;
background: #28a745;
color: #fff;
border: none;
margin-top: 20px;
cursor: pointer;
}

button:hover {
background: #218838;
}

#result {
margin-top: 20px;
font-size: 18px;
text-align: center;
}
</style>
</head>

<body>
<div class="container">
<h1>Salary Prediction</h1>
<form id="prediction-form">
<label for="company_name">Company Name:</label>
<input type="text" id="company_name" name="Company Name" required>

<label for="job_title">Job Title:</label>
<input type="text" id="job_title" name="Job Title" required>

<label for="location">Location:</label>
<input type="text" id="location" name="Location" required>

<button type="submit">Predict Salary</button>
</form>
<div id="result"></div>
</div>
<script>
document.getElementById('prediction-form').addEventListener('submit', function (e) {
e.preventDefault();

const companyName = document.getElementById('company_name').value;
const jobTitle = document.getElementById('job_title').value;
const location = document.getElementById('location').value;

const data = {
"Company Name": companyName,
"Job Title": jobTitle,
"Location": location
};

fetch('/predict', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
let salaryRange = '';
switch (data.prediction) {
case 0:
salaryRange = 'greater than 50k';
break;
case 1:
salaryRange = 'greater than 1 lakh';
break;
case 2:
salaryRange = 'greater than 10 lakh';
break;
case 3:
salaryRange = 'greater than 15 lakh';
break;
case 4:
salaryRange = 'greater than 20 lakh';
break;
default:
salaryRange = 'unknown';
}
document.getElementById('result').innerText = `Predicted Salary Range: ${salaryRange}`;
})
.catch(error => {
console.error('Error:', error);
});

});
</script>
</body>

</html>
Loading