forked from abpuccini/maternal-mortality-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_forecast_race.py
39 lines (29 loc) · 1.34 KB
/
user_forecast_race.py
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
# Dependencies
from joblib import load
import pandas as pd
import numpy as np
def forecast_graph_race(asian, black, white, hispanic_origin, not_hispanic_origin):
# Samples
data = pd.read_csv(
"machine_learning/Resources/race_population.csv")
pop_data = data[['population_by_race']]
if asian == 1:
data_asian = data.loc[data['race'] == "Asian or Pacific Islander"]
pop_data["race_Asian or Pacific Islander"] = asian
pop_data["race_Black or African American"] = black
pop_data["race_White"] = white
pop_data["hispanic_origin_Hispanic or Latino"] = hispanic_origin
pop_data["hispanic_origin_Not Hispanic or Latino"] = not_hispanic_origin
race_data = pop_data[["race_Asian or Pacific Islander", "race_Black or African American",
"race_White", "hispanic_origin_Hispanic or Latino",
"hispanic_origin_Not Hispanic or Latino",
"population_by_race"]]
# input data to predict MMR
inputValue = np.array(health_data).reshape(1, -1)
# load the saved pipleine model
pipeline = load(
"machine_learning/models/Linear_Regression_strat_by_race_model_no_scale_Lee.sav")
# predict on the sample data
predicted_mmr_list = pipeline.predict(inputValue)
predicted_mmr = predicted_mmr_list[0][0]
return predicted_mmr