Skip to content

Instantly share code, notes, and snippets.

@shaan-shah
Created August 18, 2020 13:57
Show Gist options
  • Save shaan-shah/764ef256c48ab8c63cc05291c8402938 to your computer and use it in GitHub Desktop.
Save shaan-shah/764ef256c48ab8c63cc05291c8402938 to your computer and use it in GitHub Desktop.
This gist was made to demonstrate code on medium.
def auto_applyer(leaf_value,feature_value,feature_list,df_raw1,df_test,target_column,date_column=None):
reset_rf_samples()
if date_column:
if date_column in df_test:
add_datepart(df_test,date_column)
if date_column in df_raw1:
add_datepart(df_raw1,date_column)
'''First we will pre process both test and raw data'''
train_cats(df_raw1)
apply_cats(df=df_test,trn=df_raw1)
X,y,nas=proc_df(df_raw1,target_column)
X_test,_,nas = proc_df(df_test, na_dict=nas)
X=X[feature_list]
X_test=X_test[feature_list]
z=RandomForestRegressor(n_jobs=-1,min_samples_leaf=leaf_value,max_features=feature_value,oob_score=False,n_estimators=75)
z.fit(X,y)
fi = rf_feat_importance(z,X)
graphed=fi.plot('cols', 'imp', 'barh', figsize=(12,7), legend=False)
fig_save = graphed.get_figure()
fig_save.savefig('Feature Importance.png')
print(z.predict(X_test))
return z.predict(X_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment