Kaggle competition: NBA Rookies
add_datepart(df_raw, 'pickup_datetime', time=True )<feature_engineering>
train = pd.read_csv(".. /input/train.csv")
 test = pd.read_csv(".. /input/test.csv" )
def add_travel_vector_features(df):
df["lat_diff"] = np.abs(df.dropoff_latitude - df.pickup_latitude)
 df["lon_diff"] = np.abs(df.dropoff_longitude - df.pickup_longitude)
 df['distance'] =(( df.lat_diff)**2 +(df.lon_diff)**2)**.5
add_travel_vector_features(df_raw )<prepare_x_and_y>
X_train = train.iloc[:, 2:-1].values
Y_train = train.iloc[:, 21].values
X_test = test.iloc[:, 2:].values
df, y, _ = proc_df(df_raw, 'fare_amount', skip_flds=["key"], subset=100000 )<split>
X_all = np.concatenate(( X_train, X_test), axis=0)
X_train, X_valid, y_train, y_valid = train_test_split(df, y, test_size=0.2)
 print(X_train.shape, X_valid.shape, y_train.shape, y_valid.shape )<compute_test_metric>
imputer = Imputer(missing_values = 'NaN', strategy = 'most_frequent', axis = 0)
 imputer = imputer.fit(X_all)
 X_all = imputer.transform(X_all )
def rmse(x,y): return math.sqrt(((x-y)**2 ).mean())
 def print_score(m):
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 )<train_model>
X_train = X_all[0:900,:]
X_test = X_all[900:1340,:]
%%time
m = RandomForestRegressor(n_estimators=10, n_jobs=-1)
 m.fit(X_train, y_train)
 print_score(m )<set_options>
X = X_train
Y = Y_train
gc.collect()<set_options>
sc = QuantileTransformer()
X = sc.fit_transform(X)
 X_test = sc.transform(X_test )
set_rf_samples(20000 )<train_model>
sc = AdditiveChi2Sampler()
X = sc.fit_transform(X)
 X_test = sc.transform(X_test )
%%time
m = RandomForestRegressor(n_estimators=40, n_jobs=-1, oob_score=True)
 m.fit(X_train, y_train)
 print_score(m )<train_model>
clf = AdaBoostClassifier(n_estimators = 60 , learning_rate = 0.3)
 clf.fit(X, Y)
 Y_pred = clf.predict(X)
 accuracy_score(Y, Y_pred )
%%time
m = RandomForestRegressor(n_estimators=80, max_features=0.5, n_jobs=-1, oob_score=True)
 m.fit(X_train, y_train)
 print_score(m )<train_model>
Y_test_pred = clf.predict(X_test )
<train_model><EOS> 
cols = { 'PlayerID': [i+901 for i in range(440)] , 'TARGET_5Yrs': Y_test_pred }
submission = pd.DataFrame(cols)
 print(submission)
 submission.to_csv("submission.csv", index=False )