Kaggle competition: New York City Taxi Trip Duration
<SOS> metric: RMSLE Kaggle data source: new-york-city-taxi-trip-duration<train_on_grid>
%matplotlib inline
%%script false --no-raise-error
kfolds = KFold(n_splits=10, shuffle=True, random_state=42)
 def cv_rmse(model, X=train_X, y=np.log1p(train_y)) :
rmse = np.sqrt(-cross_val_score(model, X, y, scoring="neg_mean_squared_error", cv=kfolds))
return(rmse)
 alphas2 = [5e-05, 0.0001, 0.0002, 0.0003, 0.0004, 0.0005, 0.0006, 0.0007, 0.0008]
lasso_pipe = make_pipeline(RobustScaler() , LassoCV(max_iter=1e7, alphas=alphas2, random_state=42, cv=kfolds,n_jobs=4)) 
<predict_on_test>
train = '.. /input/train.csv'
test = '.. /input/test.csv'
dfTrain = pd.read_csv(train)
 dfTest = pd.read_csv(test )
%%script false --no-raise-error
meta_xgboost = xgb.XGBRegressor(n_jobs=4)
 stack = StackingCVRegressor(regressors=[elastic_pipe, lightgbm, xg_model],meta_regressor=meta_xgboost)
 stack.fit(np.array(train_X), np.log1p(train_y))
predict_s = stack.predict(np.array(test_X))
predict_s = np.expm1(predict_s )<predict_on_test>
dfTrain.isna().sum()
predict = predict_l<save_to_csv>
dfTest.isna().sum()
sub = pd.concat([test_ids, pd.Series(predict)], axis=1)
 sub = sub.rename(columns={0:'SalePrice'})
 sub.to_csv('sumbission.csv', index=False, header=True )<import_modules>
print(dfTrain.loc[dfTrain['trip_duration'] > 350000] )
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.linear_model import Lasso,Ridge,ElasticNet
from xgboost import XGBRegressor
from lightgbm import LGBMRegressor
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import GridSearchCV<load_from_csv>
dfTrain = dfTrain[dfTrain['passenger_count']>= 1]
train = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/train.csv')
 test = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/test.csv' )<concatenate>
dfTrain['pickup_datetime'] = pd.to_datetime(dfTrain['pickup_datetime'])
 dfTest['pickup_datetime'] = pd.to_datetime(dfTest['pickup_datetime'])
 dfTrain['month'] = dfTrain['pickup_datetime'].dt.month
dfTrain['day'] = dfTrain['pickup_datetime'].dt.day
dfTrain['weekday'] = dfTrain['pickup_datetime'].dt.weekday
dfTrain['hour'] = dfTrain['pickup_datetime'].dt.hour
dfTrain['minute'] = dfTrain['pickup_datetime'].dt.minute
dfTest['month'] = dfTest['pickup_datetime'].dt.month
dfTest['day'] = dfTest['pickup_datetime'].dt.day
dfTest['weekday'] = dfTest['pickup_datetime'].dt.weekday
dfTest['hour'] = dfTest['pickup_datetime'].dt.hour
dfTest['minute'] = dfTest['pickup_datetime'].dt.minute
dfTrain['trip_duration'] = np.log1p(dfTrain['trip_duration'].values)
 dfTrain.head()
data = pd.concat([train,test] )<data_type_conversions>
selection_train = ["passenger_count", "pickup_longitude", "pickup_latitude", "dropoff_longitude","dropoff_latitude","month", "day", "weekday", "hour", "minute"]
selection_test = ["passenger_count", "pickup_longitude", "pickup_latitude", "dropoff_longitude","dropoff_latitude", "month", "day", "weekday", "hour", "minute"]
y_train = dfTrain["trip_duration"]
X_train = dfTrain[selection_train]
X_test = dfTest[selection_test]
data.index = range(2919)
 data.drop(['Id','Utilities'],axis=1,inplace=True)
 data['MoSold'] = data['MoSold'].astype(str)
 data['YrSold'] = data['YrSold'].astype(str )<categorify>
print("Training...")
 m = RandomForestRegressor()
m.fit(X_train, y_train)
 %timeit
print('Done!!!' )
l2 = ['LotFrontage','MasVnrArea']
l3 = ['BsmtFinSF1','BsmtFinSF2','BsmtUnfSF','TotalBsmtSF','BsmtFullBath','BsmtHalfBath','GarageYrBlt','GarageCars','GarageArea']
for item in l2 :
data[item]= data[item].fillna(data[item].mean())
 for item in l3 :
data[item]= data[item].fillna(0 )<data_type_conversions>
pred = m.predict(X_test)
 print('Done!!!' )
data['FireplaceQu'] = data['FireplaceQu'].fillna('None')
 data['MiscFeature'] = data['MiscFeature'].fillna('None')
 data['Alley']=data['Alley'].fillna('None' )<categorify>
pred = np.expm1(pred )
l1 = data['MSZoning'].unique().tolist()
for i in range(len(l1)-1):
j = np.random.randint(0,4)
 data['MSZoning'] = data['MSZoning'].fillna(l1[j] )<categorify>
my_submission = pd.DataFrame({'id':dfTest.id, 'trip_duration':pred} )
<data_type_conversions><EOS> 
my_submission.to_csv("my_submission.csv", index=False)
 print("Done!!!" )