File size: 2,453 Bytes
0adc24e
 
 
 
 
 
 
 
9091885
 
0adc24e
9091885
 
 
 
0adc24e
9091885
 
 
 
 
 
 
 
0adc24e
 
 
9091885
0adc24e
9091885
0adc24e
 
 
 
 
9091885
0adc24e
9091885
 
 
0adc24e
 
9091885
 
 
0adc24e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import requests
import matplotlib.pyplot as plt

# Define the URL for the prediction service
url = "http://localhost:8960/predict"

# Prepare the data for the prediction
data = {
    "Age": 32,
    "DistanceFromHome": 2,
    "Education": 2,
    "NumCompaniesWorked": 0,
    "PercentSalaryHike": 2,
    "TotalWorkingYears": 8,
    "TrainingTimesLastYear": 2,
    "WorkLifeBalance": 2,
    "YearsInCurrentRole": 7,
    "YearsSinceLastPromotion": 5,
    "YearsWithCurrManager": 1,
    "BusinessTravel_Travel_Rarely": 0,
    "BusinessTravel_Travel_Frequently": 1,
    "Department_Research": 0,
    "Department_Sales": 1,
    "EducationField_Life_Sciences": 0,
    "EducationField_Medical": 0,
    "EducationField_Marketing": 0,
    "EducationField_Other": 0,
    "EducationField_Technical_Degree": 1,
    "Gender_Male": 1,
    "JobRole_Research_Scientist": 0,
    "JobRole_Sales_Executive": 0,
    "JobRole_Laboratory_Technician": 0,
    "JobRole_Manufacturing_Director": 0,
    "JobRole_Healthcare_Representative": 0,
    "JobRole_Manager": 0,
    "JobRole_Sales_Representative": 1,
    "JobRole_Research_Director": 0,
    "MaritalStatus_Married": 0,
    "MaritalStatus_Single": 1,
    "OverTime_Yes": 1
}




# Make the POST request
try:
    response = requests.post(url, json=data)
    response.raise_for_status()  # Raise an error for bad responses
    prediction = response.json()  # Parse the JSON response

    # Check if the prediction contains the expected key and is a list
    if isinstance(prediction, dict) and 'prediction' in prediction and isinstance(prediction['prediction'], list):
        survival_probabilities = prediction['prediction']
    else:
        raise ValueError("Unexpected response format: {}".format(prediction))

    # Create a list of years based on the number of predictions
    years = list(range(1, len(survival_probabilities) + 1))

    # Plot the data
    plt.figure(figsize=(10, 6))
    plt.plot(years, survival_probabilities, marker='o', linestyle='-', color='b')
    plt.xlabel('Years')
    plt.ylabel('Survival Probability')
    plt.title('Employee Survival Probability Over Time')
    plt.grid(True)
    plt.xticks(years)
    plt.ylim(0, 1)

    # Show the plot
    plt.show()

except requests.exceptions.RequestException as e:
    print("An error occurred while making the request:", e)
except ValueError as ve:
    print("Value error:", ve)
except Exception as ex:
    print("An unexpected error occurred:", ex)