|
| 1 | +#import the libraries |
| 2 | +import pandas as pd |
| 3 | +import pickle |
| 4 | + |
| 5 | +# Function to let user choose from various options |
| 6 | +def let_user_pick(options, str): |
| 7 | + print(f"Enter the {str}") |
| 8 | + for idx, element in enumerate(options): |
| 9 | + print("{}) {}".format(idx+1,element)) |
| 10 | + i = input("Enter number: ") |
| 11 | + try: |
| 12 | + if 0 < int(i) <= len(options): |
| 13 | + return options[int(i)-1] |
| 14 | + except: |
| 15 | + pass |
| 16 | + return None |
| 17 | + |
| 18 | +# Function to convert yes or no to boolean |
| 19 | +def know_language(yes_no): |
| 20 | + if yes_no.lower() == 'y' or yes_no.lower() == 'yes' or yes_no == '1': |
| 21 | + return 1 |
| 22 | + else: |
| 23 | + return 0 |
| 24 | + |
| 25 | +# Make an empty dataframe df |
| 26 | +data = [['0','0','0','0','0','0','0','0']] |
| 27 | +df = pd.DataFrame(data, columns = ['Sector','python_yn','job_sim','R_yn','tableau','power bi','ml','dl']) |
| 28 | + |
| 29 | +# Take Sector as an input from user |
| 30 | +sectors = ['Information Technology','Business Services','Education','Business Services','Finance', 'Government','Travel & Tourism'] |
| 31 | +sect = let_user_pick(sectors, 'Sector') |
| 32 | +df['Sector'][0] = sect |
| 33 | + |
| 34 | +# Take job role as an input from user |
| 35 | +job_role = ['Software Enginner', 'data scientist', 'data engineer', 'analyst', 'Machine Learnig Engineer', 'director', 'manager'] |
| 36 | +job_simp = let_user_pick(job_role, 'Job Role') |
| 37 | +if job_simp == 'Software Engineer': |
| 38 | + job_simp = 'na' |
| 39 | +elif job_simp == 'Machine Learnig Engineer': |
| 40 | + job_simp = 'mle' |
| 41 | +df['job_sim'][0] = job_simp |
| 42 | + |
| 43 | +# Asking for skills from user |
| 44 | +python = know_language(input('Do you know python?(Y/N)')) |
| 45 | +df['python_yn'][0] = python |
| 46 | + |
| 47 | +r = know_language(input('Do you know R?(Y/N)')) |
| 48 | +df['R_yn'][0] = r |
| 49 | + |
| 50 | +tableau = know_language(input('Do you know Tableau?(Y/N)')) |
| 51 | +df['tableau'][0] = tableau |
| 52 | + |
| 53 | +Power_Bi = know_language(input('Do you know Power Bi?(Y/N)')) |
| 54 | +df['power bi'][0] = Power_Bi |
| 55 | + |
| 56 | +Machine_Learning = know_language(input('Do you know Machine Learning?(Y/N)')) |
| 57 | +df['ml'][0] = Machine_Learning |
| 58 | + |
| 59 | +Deep_Learning = know_language(input('Do you know Deep Learning?(Y/N)')) |
| 60 | +df['dl'][0] = Deep_Learning |
| 61 | + |
| 62 | +#Load the model |
| 63 | +with open('./Salary Predictor/models/random_forest2_model.sav', 'rb') as f: |
| 64 | + random_forest_model = pickle.load(f) |
| 65 | + |
| 66 | +# load the columns file |
| 67 | +with open('./Salary Predictor/models/model_columns1.pkl', 'rb') as f: |
| 68 | + model_columns = pickle.load(f) |
| 69 | + |
| 70 | +# Query into the model to fet results |
| 71 | +query_ = pd.get_dummies(pd.DataFrame(df, index = [0]), prefix=['Sector','job_sim'], columns=['Sector','job_sim']) |
| 72 | +query = query_.reindex(columns = model_columns, fill_value= 0) |
| 73 | +prediction = list(random_forest_model.predict(query)) |
| 74 | +final_val = round(prediction[0],2) |
| 75 | + |
| 76 | +print(f'Your Estimated Annual Salary will be {final_val}K Dollars') |
0 commit comments