Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.7 kB
1
Indexable
Never

def predict_attrition(config, model):
    if type(config) == dict:
        df_prep = config.copy()
        df = pd.DataFrame(df_prep, index=[0])

    else:
        df = config.copy()

    # Read in and filter out columns from original data for use for the pipe
    attrition_df_temp = pd.read_csv("HR.csv")
    data_temp = attrition_df_temp.copy()
    data_temp_dropped_X = data_temp.drop(['ID', 'Name','left_Company'], axis=1)
    data_temp_dropped_Y = data_temp["left_Company"].copy()
    # Run pipeline_transformer once to make full_pipeline available for make_pipeline

    _ = pipeline_transformer(data_temp_dropped_X)

    pipe = make_pipeline(full_pipeline, model)

    # Fit the pipe onto the original data to remember possible values for each categorical feature
    pipe.fit(data_temp_dropped_X, data_temp_dropped_Y)

    y_pred = pipe.predict(df)

    probability = pipe.predict_proba(df)

    return y_pred, probability


#example

def predict():
    with open('attrition_prediction_model.bin', 'rb') as file:
        model = pickle.load(file)
        file.close()
#      28	REICHARD	Human Resources	Japan	Manager	1	1	0	1	1	0.4	1	3	1	3	6	226	9	1	0	low	M	4	2	2	2	2	2	2	3
        data_dict = {"Department":str("IT"),
                     "GEO":str("US"),
                     "Role":str("VP"),
                     "Rising_Star":int(5),
                     "Will_Relocate":int(1),
                     "Critical":int(0),
                     "Trending Perf":int(1),
                     "Talent_Level":int(1),
                     "Percent_Remote":float(0.82),
                     "EMP_Sat_OnPrem_1":int(1),
                     "EMP_Sat_Remote_1":int(3),
                     "EMP_Engagement_1":int(1),
                     "last_evaluation":int(3),
                     "number_project":int(6),
                     "average_montly_hours":int(226),
                     "time_spend_company":int(9),
                     "promotion_last_5years":int(0),
                     "salary":str("medium"),
                     "Gender":str("F"),
                     "Emp_Work_Status2":int(4),
                     "Emp_Identity":int(2),
                     "Emp_Role":int(2),
                     "Emp_Position":int(2),
                     "Emp_Title":int(2),
                     "Emp_Satisfaction":int(2),
                     "Emp_Competitive_1":int(2),
                     "Emp_Collaborative_1":int(3)}
 # Execute prediction using form data and finished model
        predict_value = predict_attrition(data_dict, model)[0]
        predict_probability = predict_attrition(data_dict, model)[1]
        print("predict_value:",predict_value)
        print("predict_probability 0 / 1 ",predict_probability)

Leave a Comment