Last active
August 18, 2020 08:54
-
-
Save shaan-shah/c4dd33db24d3b92f41ce5409ec41da4d to your computer and use it in GitHub Desktop.
This is a gist to demonstrate some code on medium.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def split_vals(a,n): | |
return a[:n].copy(), a[n:].copy() | |
def rmse(x,y): return math.sqrt(((x-y)**2).mean()) | |
def print_score(m,X_train,y_train,X_valid,y_valid): | |
res = [rmse(m.predict(X_train), y_train), rmse(m.predict(X_valid), y_valid), | |
m.score(X_train, y_train), m.score(X_valid, y_valid)] | |
if hasattr(m, 'oob_score_'): res.append(m.oob_score_) | |
print(res) | |
def fx(m,X_valid,y_valid): | |
return(m.score(X_valid,y_valid)) | |
def auto_train(a,b,X_train,y_train): | |
''' a and b are the min_ leaf and max_ features respectively''' | |
q=RandomForestRegressor(n_jobs=-1, min_samples_leaf=a,max_features=b,oob_score=False) | |
q.fit(X_train, y_train) | |
return q |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment