Kaggle competition: Property price prediction challenge
col_datetime = ["pickup_datetime"]
col_types = {"key": "object",
"fare_amount": "float32",
"pickup_logitude": "float32",
"pickup_latitude": "float32",
"dropoff_longitude": "float32",
"dropoff_latitude": "float32",
"passenger_count": "int8"}<load_from_csv>
%matplotlib inline
%%time
df_raw = pd.read_csv(f'{PATH_INPUT}train.csv',
parse_dates = col_datetime,
dtype = col_types,
infer_datetime_format = True,
nrows=NROWS )<load_from_csv>
train_csv = pd.read_csv(".. /input/train_set.csv", low_memory=False)
 test_csv = pd.read_csv(".. /input/test_set.csv", low_memory=False )
df_test_raw = pd.read_csv(f'{PATH_INPUT}test.csv',
parse_dates = col_datetime,
dtype = col_types,
infer_datetime_format = True )<categorify>
X_trainvalid = train_csv.drop(["PRICE", "Id"], axis=1)
 X_test = test_csv.drop(["Id"], axis=1 )
df_raw.to_feather(f'{PATH_TMP}train_raw')
 df_test_raw.to_feather(f"{PATH_TMP}test_raw" )<drop_column>
X_traintest = pd.concat([X_trainvalid, X_test], axis=0)
 X_traintest["SALEDATE"] = pd.to_datetime(X_traintest["SALEDATE"] ).astype("int")
 X_traintest["GIS_LAST_MOD_DTTM"] = pd.to_datetime(X_traintest["GIS_LAST_MOD_DTTM"] ).astype("int" )
df_raw.drop(index=df_raw[df_raw.fare_amount <= 2.5].index, inplace=True )<drop_column>
for c in categorical_features:
X_traintest[c] = X_traintest[c].astype('category' )
df_raw.drop(index=df_raw[df_raw.passenger_count <= 0].index, inplace=True )<drop_column>
params = {
'boosting_type': 'gbdt',
'objective': 'regression',
'metric': 'l2',
'num_leaves': 511,
'learning_rate': 0.01,
'feature_fraction': 0.8,
'verbose': 0
}
df_raw.drop(index=df_raw[(df_raw.pickup_longitude <= -75)
 |(df_raw.pickup_longitude >= -72)
 |(df_raw.dropoff_longitude <= -75)
 |(df_raw.dropoff_longitude >= -72)
 |(df_raw.pickup_latitude <= 39)
 |(df_raw.pickup_latitude >= 42)
 |(df_raw.dropoff_latitude <= 39)
 |(df_raw.dropoff_latitude >= 42)].index, inplace=True)
 df_raw.reset_index(inplace=True, drop=True )<sort_values>
X_train = X_traintest.iloc[:train_csv.shape[0], :]
X_test = X_traintest.iloc[train_csv.shape[0]:, :]
y_train = np.log(train_csv["PRICE"].values)
 X_train, X_valid, y_train, y_valid = train_test_split(X_train, y_train, test_size=0.2, random_state=71)
 lgb_train = lgb.Dataset(X_train, y_train, categorical_feature=categorical_features)
 lgb_valid = lgb.Dataset(X_valid, y_valid, categorical_feature=categorical_features)
 print('Starting training...')
 model = lgb.train(
 params,
lgb_train,
valid_sets=lgb_valid,
num_boost_round=10000,
early_stopping_rounds=100 
)
df_raw.isnull().sum().sort_values(ascending=False)/len(df_raw )<sort_values>
test_pred = np.exp(model.predict(X_test))
df_test_raw.isnull().sum().sort_values(ascending=False)/len(df_test_raw )<feature_engineering>
sub_df = pd.DataFrame({"Id":test_csv["Id"].values,"PRICE":test_pred})
 sub_df.to_csv("sub_harada.csv", index=False )