Skip to content

Commit

Permalink
add model_trained.joblib lighter
Browse files Browse the repository at this point in the history
  • Loading branch information
ympaik87 committed Jan 12, 2022
1 parent 83fa425 commit da64bc5
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 108 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
aws_keys.csv
starter/data/census.csv
starter/data/census_cleaned.csv
starter/model/model_trained.joblib

.DS_Store
.ipynb_checkpoints
Expand Down
59 changes: 33 additions & 26 deletions starter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@ class InferenceRequest(BaseModel):
workclass: str
fnlgt: int
education: str
education_num: int = Field(alias="education-num")
marital_status: str = Field(alias="marital-status")
# education_num: int = Field(alias="education-num")
# marital_status: str = Field(alias="marital-status")
education_num: int
marital_status: str
occupation: str
relationship: str
race: str
sex: str
capital_gain: int = Field(alias="capital-gain")
capital_loss: int = Field(alias="capital-loss")
hours_per_week: int = Field(alias="hours-per-week")
native_country: str = Field(alias="native-country")
# capital_gain: int = Field(alias="capital-gain")
# capital_loss: int = Field(alias="capital-loss")
# hours_per_week: int = Field(alias="hours-per-week")
# native_country: str = Field(alias="native-country")
capital_gain: int
capital_loss: int
hours_per_week: int
native_country: str


@app.get('/')
Expand All @@ -42,30 +48,31 @@ async def welcome():


@app.post("/items")
async def create_item(item):
async def create_item(item: dict):
return item


@app.post('/predict')
async def get_prediction(request_data: InferenceRequest = Body(
...,
example={
"age": 39,
"workclass": "State-gov",
"fnlgt": 77516,
"education": "Bachelors",
"education-num": 13,
"marital-status": "Never-married",
"occupation": "Adm-clerical",
"relationship": "Not-in-family",
"race": "White",
"sex": "Male",
"capital-gain": 2174,
"capital-loss": 0,
"hours-per-week": 40,
"native-country": "United-States"
}
)):
async def get_prediction(request_data: InferenceRequest):
# async def get_prediction(request_data: InferenceRequest = Body(
# ...,
# example={
# "age": 39,
# "workclass": "State-gov",
# "fnlgt": 77516,
# "education": "Bachelors",
# "education-num": 13,
# "marital-status": "Never-married",
# "occupation": "Adm-clerical",
# "relationship": "Not-in-family",
# "race": "White",
# "sex": "Male",
# "capital-gain": 2174,
# "capital-loss": 0,
# "hours-per-week": 40,
# "native-country": "United-States"
# }
# )):
cwd_p = os.getcwd()
trained_model = joblib.load(f"{cwd_p}/starter/model/model_trained.joblib")
encoder = joblib.load(f"{cwd_p}/starter/model/encoder.joblib")
Expand Down
Binary file modified starter/model/encoder.joblib
Binary file not shown.
Binary file added starter/model/model_trained.joblib
Binary file not shown.
160 changes: 80 additions & 80 deletions starter/model/slice_output.txt
Original file line number Diff line number Diff line change
@@ -1,99 +1,99 @@
feature,value,precision,recall,fbeta_score
workclass,State-gov,0.9465875370919882,0.9273255813953488,0.9368575624082233
workclass,Self-emp-not-inc,0.9574155653450808,0.9131652661064426,0.9347670250896057
workclass,Private,0.9503784693019344,0.9269893355209188,0.9385382059800663
workclass,Federal-gov,0.957983193277311,0.936986301369863,0.9473684210526316
workclass,Local-gov,0.9656357388316151,0.922824302134647,0.943744752308984
workclass,Self-emp-inc,0.9490131578947368,0.9616666666666667,0.955298013245033
workclass,State-gov,0.9339080459770115,0.9447674418604651,0.9393063583815029
workclass,Self-emp-not-inc,0.9560117302052786,0.9131652661064426,0.9340974212034385
workclass,Private,0.9535229202037352,0.9214520098441346,0.9372131831455988
workclass,Federal-gov,0.9482288828337875,0.9534246575342465,0.9508196721311476
workclass,Local-gov,0.9330065359477124,0.9376026272577996,0.9352989352989352
workclass,Self-emp-inc,0.964824120603015,0.96,0.9624060150375939
workclass,Without-pay,1.0,1.0,1.0
education,Bachelors,0.9535104364326376,0.9454374412041392,0.949456778460085
education,HS-grad,0.9309021113243762,0.8998144712430427,0.9150943396226415
education,11th,1.0,0.8813559322033898,0.936936936936937
education,Masters,0.9608269858541894,0.9618736383442266,0.9613500272182908
education,9th,1.0,0.92,0.9583333333333334
education,Some-college,0.9544025157232704,0.9086826347305389,0.9309815950920245
education,Assoc-acdm,0.9545454545454546,0.90234375,0.927710843373494
education,7th-8th,0.9333333333333333,0.8,0.8615384615384616
education,Doctorate,0.9713261648745519,0.9678571428571429,0.9695885509838998
education,Assoc-voc,0.950920245398773,0.9011627906976745,0.9253731343283582
education,Prof-school,0.973170731707317,0.9827586206896551,0.9779411764705881
education,5th-6th,1.0,1.0,1.0
education,10th,1.0,0.9322033898305084,0.9649122807017544
education,Bachelors,0.9478138222849083,0.9482596425211665,0.9480366799905948
education,HS-grad,0.9447368421052632,0.8880643166357453,0.9155243863563916
education,11th,0.9777777777777777,0.7457627118644068,0.8461538461538463
education,Masters,0.9759036144578314,0.9705882352941176,0.9732386673948662
education,9th,1.0,0.72,0.8372093023255813
education,Some-college,0.9393706830391404,0.9161676646706587,0.9276241000378931
education,Assoc-acdm,0.9473684210526315,0.9140625,0.9304174950298211
education,7th-8th,1.0,0.8857142857142857,0.9393939393939393
education,Doctorate,0.968421052631579,0.9857142857142858,0.976991150442478
education,Assoc-voc,0.9395770392749244,0.9040697674418605,0.9214814814814815
education,Prof-school,0.9754299754299754,0.9778325123152709,0.976629766297663
education,5th-6th,1.0,0.9166666666666666,0.9565217391304348
education,10th,0.92,0.7796610169491526,0.8440366972477064
education,Preschool,1.0,1.0,1.0
education,12th,0.9615384615384616,0.8620689655172413,0.9090909090909091
education,1st-4th,1.0,0.6666666666666666,0.8
marital-status,Never-married,0.9830917874396136,0.8659574468085106,0.920814479638009
marital-status,Married-civ-spouse,0.9476168003775366,0.9413970932958274,0.9444967074317968
marital-status,Divorced,0.9768637532133676,0.8407079646017699,0.9036860879904874
marital-status,Married-spouse-absent,1.0,0.9032258064516129,0.9491525423728813
marital-status,Separated,1.0,0.8484848484848485,0.9180327868852458
marital-status,Married-AF-spouse,1.0,0.9,0.9473684210526316
marital-status,Widowed,1.0,0.85,0.9189189189189189
occupation,Adm-clerical,0.9375,0.9036144578313253,0.920245398773006
occupation,Exec-managerial,0.9503328213005633,0.9581827568404749,0.9542416452442161
occupation,Handlers-cleaners,0.9078947368421053,0.8313253012048193,0.8679245283018868
occupation,Prof-specialty,0.9642451759364359,0.9381557150745444,0.9510215505177722
occupation,Other-service,0.991304347826087,0.8636363636363636,0.923076923076923
occupation,Sales,0.9518828451882845,0.9381443298969072,0.9449636552440291
occupation,Transport-moving,0.9518900343642611,0.8683385579937304,0.9081967213114753
occupation,Farming-fishing,0.99,0.8608695652173913,0.9209302325581394
occupation,Machine-op-inspct,0.9369747899159664,0.9102040816326531,0.9233954451345756
occupation,Tech-support,0.9377289377289377,0.920863309352518,0.9292196007259528
occupation,Craft-repair,0.9428571428571428,0.9085903083700441,0.9254066180594503
occupation,Protective-serv,0.96,0.9142857142857143,0.9365853658536586
education,12th,1.0,0.8275862068965517,0.9056603773584906
education,1st-4th,1.0,1.0,1.0
marital-status,Never-married,0.9782082324455206,0.8595744680851064,0.9150622876557191
marital-status,Married-civ-spouse,0.9476182940338661,0.9357712142522269,0.9416574933165592
marital-status,Divorced,0.9739952718676123,0.911504424778761,0.9417142857142857
marital-status,Married-spouse-absent,1.0,0.8709677419354839,0.9310344827586207
marital-status,Separated,1.0,0.8181818181818182,0.9
marital-status,Married-AF-spouse,0.9090909090909091,1.0,0.9523809523809523
marital-status,Widowed,0.9859154929577465,0.875,0.9271523178807948
occupation,Adm-clerical,0.9386503067484663,0.9216867469879518,0.9300911854103343
occupation,Exec-managerial,0.958656330749354,0.9576664945792462,0.9581611570247933
occupation,Handlers-cleaners,0.9583333333333334,0.8313253012048193,0.8903225806451613
occupation,Prof-specialty,0.9532195927352779,0.9563776918829376,0.9547960308710034
occupation,Other-service,0.9823008849557522,0.8409090909090909,0.9061224489795919
occupation,Sales,0.9553191489361702,0.9257731958762887,0.9403141361256545
occupation,Transport-moving,0.9326599326599326,0.8683385579937304,0.8993506493506493
occupation,Farming-fishing,0.9789473684210527,0.808695652173913,0.8857142857142857
occupation,Machine-op-inspct,0.9555555555555556,0.8775510204081632,0.9148936170212767
occupation,Tech-support,0.9416058394160584,0.9280575539568345,0.9347826086956521
occupation,Craft-repair,0.9442467378410438,0.8766519823788547,0.9091947458595089
occupation,Protective-serv,0.9259259259259259,0.9523809523809523,0.9389671361502347
occupation,Armed-Forces,1.0,1.0,1.0
occupation,Priv-house-serv,1.0,1.0,1.0
relationship,Not-in-family,0.9806896551724138,0.8639125151883353,0.9186046511627908
relationship,Husband,0.9492277649565063,0.9415390033456594,0.9453677510608204
relationship,Wife,0.9328571428571428,0.9409221902017291,0.9368723098995696
relationship,Own-child,1.0,0.875,0.9333333333333333
relationship,Unmarried,0.9887005649717514,0.8215962441314554,0.8974358974358975
relationship,Other-relative,1.0,0.8571428571428571,0.923076923076923
race,White,0.9532864201227729,0.930984061997368,0.9420032549193667
race,Black,0.9393063583815029,0.8879781420765027,0.9129213483146067
race,Asian-Pac-Islander,0.9471544715447154,0.9395161290322581,0.9433198380566802
race,Amer-Indian-Eskimo,1.0,0.7941176470588235,0.8852459016393442
race,Other,0.8695652173913043,0.9523809523809523,0.909090909090909
sex,Male,0.9525175270873167,0.9346466541588493,0.9434974747474748
sex,Female,0.9511961722488038,0.8938848920863309,0.9216504404265182
native-country,United-States,0.952485701715794,0.9285203716940672,0.940350369190676
native-country,Cuba,1.0,0.96,0.9795918367346939
native-country,Jamaica,0.875,0.7,0.7777777777777777
native-country,India,0.8837209302325582,0.95,0.9156626506024096
native-country,Mexico,1.0,0.9090909090909091,0.9523809523809523
native-country,Puerto-Rico,0.8571428571428571,1.0,0.923076923076923
relationship,Not-in-family,0.977088948787062,0.8809234507897934,0.926517571884984
relationship,Husband,0.9477718360071301,0.9362563831660503,0.9419789175303394
relationship,Wife,0.9437229437229437,0.9423631123919308,0.943042537851478
relationship,Own-child,0.98,0.765625,0.8596491228070174
relationship,Unmarried,0.9895287958115183,0.8873239436619719,0.9356435643564357
relationship,Other-relative,0.96875,0.8857142857142857,0.9253731343283582
race,White,0.9520814615154238,0.9296680801286737,0.9407412887475032
race,Black,0.9463276836158192,0.9153005464480874,0.9305555555555556
race,Asian-Pac-Islander,0.9658119658119658,0.9112903225806451,0.9377593360995851
race,Amer-Indian-Eskimo,0.9090909090909091,0.8823529411764706,0.8955223880597014
race,Other,0.8421052631578947,0.7619047619047619,0.8
sex,Male,0.9505187549880287,0.9310506566604128,0.9406839902061449
sex,Female,0.9591642924976258,0.908273381294964,0.9330254041570438
native-country,United-States,0.9504906986963527,0.927662616154396,0.9389379250470264
native-country,Cuba,1.0,1.0,1.0
native-country,Jamaica,1.0,0.9,0.9473684210526316
native-country,India,0.9743589743589743,0.95,0.9620253164556962
native-country,Mexico,0.96875,0.9393939393939394,0.9538461538461539
native-country,Puerto-Rico,0.9230769230769231,1.0,0.9600000000000001
native-country,Honduras,1.0,1.0,1.0
native-country,England,1.0,0.9333333333333333,0.9655172413793104
native-country,Canada,0.9411764705882353,0.8888888888888888,0.9142857142857143
native-country,Germany,0.9318181818181818,0.9318181818181818,0.9318181818181818
native-country,Iran,1.0,0.9444444444444444,0.9714285714285714
native-country,Philippines,0.9824561403508771,0.9333333333333333,0.9572649572649572
native-country,Poland,0.8888888888888888,0.7272727272727273,0.7999999999999999
native-country,England,0.9655172413793104,0.9333333333333333,0.9491525423728815
native-country,Canada,1.0,0.9166666666666666,0.9565217391304348
native-country,Germany,0.9333333333333333,0.9545454545454546,0.9438202247191012
native-country,Iran,0.9473684210526315,1.0,0.972972972972973
native-country,Philippines,0.9433962264150944,0.8333333333333334,0.8849557522123894
native-country,Poland,1.0,0.8181818181818182,0.9
native-country,Columbia,1.0,1.0,1.0
native-country,Cambodia,1.0,0.8571428571428571,0.923076923076923
native-country,Thailand,1.0,0.6666666666666666,0.8
native-country,Thailand,1.0,1.0,1.0
native-country,Ecuador,1.0,1.0,1.0
native-country,Laos,1.0,1.0,1.0
native-country,Taiwan,0.9444444444444444,0.8947368421052632,0.918918918918919
native-country,Laos,1.0,0.5,0.6666666666666666
native-country,Taiwan,1.0,1.0,1.0
native-country,Haiti,1.0,0.75,0.8571428571428571
native-country,Portugal,1.0,0.75,0.8571428571428571
native-country,Dominican-Republic,1.0,1.0,1.0
native-country,El-Salvador,1.0,1.0,1.0
native-country,France,1.0,1.0,1.0
native-country,El-Salvador,1.0,0.8888888888888888,0.9411764705882353
native-country,France,1.0,0.9166666666666666,0.9565217391304348
native-country,Guatemala,1.0,1.0,1.0
native-country,Italy,0.9583333333333334,0.9583333333333334,0.9583333333333334
native-country,China,0.9090909090909091,1.0,0.9523809523809523
native-country,South,0.875,1.0,0.9333333333333333
native-country,Japan,1.0,0.9130434782608695,0.9545454545454545
native-country,Yugoslavia,1.0,0.8333333333333334,0.9090909090909091
native-country,Italy,1.0,0.875,0.9333333333333333
native-country,China,1.0,1.0,1.0
native-country,South,0.9285714285714286,0.9285714285714286,0.9285714285714286
native-country,Japan,1.0,1.0,1.0
native-country,Yugoslavia,1.0,1.0,1.0
native-country,Peru,1.0,1.0,1.0
native-country,Outlying-US(Guam-USVI-etc),1.0,1.0,1.0
native-country,Scotland,1.0,1.0,1.0
native-country,Trinadad&Tobago,0.6666666666666666,1.0,0.8
native-country,Greece,1.0,1.0,1.0
native-country,Trinadad&Tobago,0.5,0.5,0.5
native-country,Greece,0.8888888888888888,1.0,0.9411764705882353
native-country,Nicaragua,0.6666666666666666,1.0,0.8
native-country,Vietnam,0.8333333333333334,1.0,0.9090909090909091
native-country,Hong,0.8571428571428571,1.0,0.923076923076923
native-country,Vietnam,1.0,1.0,1.0
native-country,Hong,1.0,0.8333333333333334,0.9090909090909091
native-country,Ireland,1.0,1.0,1.0
native-country,Hungary,1.0,1.0,1.0
native-country,Hungary,1.0,0.6666666666666666,0.8
native-country,Holand-Netherlands,1.0,1.0,1.0
2 changes: 1 addition & 1 deletion starter/starter/ml/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def train_model(X_train, y_train):
Trained machine learning model.
"""
cv = StratifiedKFold(shuffle=True)
model = RandomForestClassifier(n_estimators=1000)
model = RandomForestClassifier()
model.fit(X_train, y_train)
scores = cross_val_score(model, X_train, y_train, scoring='f1',
cv=cv, n_jobs=-1)
Expand Down

0 comments on commit da64bc5

Please sign in to comment.