|
import pickle |
|
import pandas as pd |
|
from sklearn.feature_extraction.text import TfidfVectorizer |
|
from sklearn.metrics.pairwise import cosine_similarity |
|
import numpy as np |
|
from typing import List, Dict |
|
|
|
|
|
def load_model_components(model_path): |
|
with open(model_path, 'rb') as f: |
|
model_components = pickle.load(f) |
|
return model_components |
|
|
|
|
|
def recommend_jobs_for_input_skills(input_hard_skills: str, input_soft_skills: str, input_major: str, |
|
jobs_data: pd.DataFrame, model_path: str) -> List[str]: |
|
|
|
tfidf_vectorizer_skills, tfidf_vectorizer_majors, companies_skills_vec, companies_majors_vec = load_model_components(model_path) |
|
|
|
|
|
input_hard_skills_vec = tfidf_vectorizer_skills.transform([input_hard_skills]) |
|
input_soft_skills_vec = tfidf_vectorizer_skills.transform([input_soft_skills]) |
|
input_major_vec = tfidf_vectorizer_majors.transform([input_major]) |
|
|
|
|
|
input_skills_vec = (input_hard_skills_vec + input_soft_skills_vec) / 2 |
|
|
|
|
|
skills_similarity = cosine_similarity(input_skills_vec, companies_skills_vec) |
|
major_similarity = cosine_similarity(input_major_vec, companies_majors_vec) |
|
|
|
|
|
if skills_similarity.shape[1] != major_similarity.shape[1]: |
|
min_dim = min(skills_similarity.shape[1], major_similarity.shape[1]) |
|
skills_similarity = skills_similarity[:, :min_dim] |
|
major_similarity = major_similarity[:, :min_dim] |
|
|
|
|
|
combined_similarity = (skills_similarity + major_similarity) / 2 |
|
|
|
|
|
sorted_company_indices = np.argsort(-combined_similarity[0]) |
|
recommended_jobs = jobs_data.iloc[sorted_company_indices]['Major'].values[:3] |
|
|
|
return recommended_jobs.tolist() |
|
|
|
|
|
if __name__ == "__main__": |
|
input_hard_skills = "Python, Java, Finance, Excel" |
|
input_soft_skills = "Communication, Teamwork" |
|
input_major = "Computer Science" |
|
|
|
jobs_data = pd.read_csv("jobs_data.csv") |
|
model_path = "recommendation_model.pkl" |
|
|
|
recommended_jobs = recommend_jobs_for_input_skills(input_hard_skills, input_soft_skills, input_major, jobs_data, model_path) |
|
print("Recommended Jobs based on input skills and major:") |
|
print(recommended_jobs) |
|
|