Tanag3r / stratascratch_projects

Contains stratascratch data project notebooks
MIT License
0 stars 1 forks source link

fix, finish cross validation function #7

Closed Tanag3r closed 1 year ago

Tanag3r commented 1 year ago

https://github.com/Tanag3r/stratascratch_projects/blob/00969d6a7238c82e30e99e3f6e9077d73a5b7ec9/doordash_delivery_est/doordash_est.ipynb#L1

Tanag3r commented 1 year ago

Complete: ` def evalMethod_cross_validate(model,model_params=dict,dataset=pd.DataFrame,target_feature=str,n_splits=int):

evaluates a model using k-fold cross-validation

try:
    X = np.array(dataset.drop(columns=str(target_feature)))
    y = np.array(dataset[[str(target_feature)]])
    cv = KFold(n_splits=n_splits,shuffle=True,random_state=42)
    scores = cross_val_score(estimator=model,fit_params=model_params,X=X,y=y,scoring='neg_root_mean_squared_error',cv=cv,n_jobs=-1)
except Exception as ex:
    raise ex
return scores

`