Kaggle competition: House Prices - Advanced Regression Techniques
<SOS> metric: rmsle Kaggle data source: house-prices-advanced-regression-techniques<drop_column>
GridSearchCV,
RandomizedSearchCV,
train_test_split 
)
 FunctionTransformer,
OneHotEncoder,
OrdinalEncoder,
QuantileTransformer, 
)
del models<drop_column>
pd.set_option('display.max_columns', None)
 sns.set()
def md(text: str):
display(Markdown(text))
def rmsle(y_true, y_pred):
return np.sqrt(mean_squared_log_error(y_true, y_pred))
def prepend_keys(dict_: dict, prepend: str)-> dict:
return {f"{prepend}{key}": value for key, value in dict_.items() }
del model<load_from_csv>
data_dir = "/kaggle/input/house-prices-advanced-regression-techniques"
data = pd.read_csv(os.path.join(data_dir, "train.csv"), index_col="Id")
 test = pd.read_csv(os.path.join(data_dir, "test.csv"), index_col="Id")
 sample_submission = pd.read_csv(os.path.join(data_dir, "sample_submission.csv"))
X = data.drop(columns=["SalePrice"])
 y = data["SalePrice"]
md(f"The total number of training observations is: `{len(X)}`")
 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)
 md(f"The number of observations with which we do hyperparameter tuning is: `{len(X_train)}`" )
submission_df = pd.read_csv('/kaggle/input/bengaliai-cv19' + '/sample_submission.csv' )<feature_engineering>
profile = ProfileReport(data, minimal=True, title='Pandas Profiling Report', html={'style':{'full_width':True}} )
submission_df['target'] = results<save_to_csv>
profile.to_notebook_iframe()
submission_df.to_csv('./submission.csv', index=False )<install_modules>
class FeatureAdder(TransformerMixin, BaseEstimator):
numeric_transforms = {
"sale_age": lambda df: df["YrSold"] - df["YearRemodAdd"]
}
categoric_transforms = {
"MSSubClass": lambda df: df["MSSubClass"].astype("object"),
}
def fit(self, X, y=None):
return self
def transform(self, X):
assert isinstance(X, pd.DataFrame)
 return X.assign(**self.numeric_transforms, **self.categoric_transforms )
!pip install /kaggle/input/timm-model/timm-0.3.2-py3-none-any.whl<import_modules>
numeric_cols = set(FeatureAdder().fit_transform(X ).select_dtypes(exclude="object" ).columns)
 categoric_cols = set(FeatureAdder().fit_transform(X ).select_dtypes(include="object" ).columns)
 print(numeric_cols)
 print("=" * 80)
 print(categoric_cols )
import pandas as pd
import cv2
import numpy as np
from tqdm.auto import tqdm
from matplotlib import pyplot as plt
import time
import pyarrow.parquet as pq<set_options>
zero_impute_cols = {"LotFrontage", "MasVnrArea"}
mode_impute_cols = {"Electrical", "Functional", "KitchenQual", "MSZoning", "SaleType", "Utilities"}
feature_imputer = DataFrameMapper(
 [
*gen_features(
 columns=[[col] for col in zero_impute_cols],
classes=[{"class": SimpleImputer, "strategy": "constant", "fill_value": 0}] 
),
*gen_features(
 columns=[[col] for col in numeric_cols - zero_impute_cols],
classes=[{"class": SimpleImputer, "strategy": "median"}] 
),
*gen_features(
 columns=[[col] for col in mode_impute_cols],
classes=[{"class": SimpleImputer, "strategy": "most_frequent"}] 
),
*gen_features(
 columns=[[col] for col in categoric_cols - mode_impute_cols],
classes=[{"class": SimpleImputer, "strategy": "constant", "fill_value": "Unknown"}] 
),
],
df_out=True
)
class MultiHeadSimpleModel(nn.Module):
def __init__(self, input_size, backbone, pretrained=True, dropout=0.2):
super(MultiHeadSimpleModel, self ).__init__()
self.input_size = input_size
self.backbone = backbone
self.pretrained = pretrained
self.dropout=dropout
self.backbone = create_model(self.backbone, self.pretrained, num_classes=0)
 feature_size = self.backbone.state_dict() ['bn2.weight'].shape[0]
self.root_head = nn.Linear(feature_size, 168, bias=True)
 self.consonant_head = nn.Linear(feature_size, 168, bias=True)
 self.vowel_head = nn.Linear(feature_size, 168, bias=True)
 intermid = []
intermid.append(nn.BatchNorm1d(feature_size))
intermid.append(nn.Dropout(self.dropout))
intermid.append(nn.Linear(feature_size, 512))
intermid.append(nn.BatchNorm1d(512))
self.intermid_unique = nn.ModuleList(intermid)
 torch.nn.init.kaiming_normal_(self.intermid_unique[2].weight)
 self.arc_face_unique = Arcface(512, 1295)
 def multi_head(self, input, unique):
input = self.backbone(input)
 root = self.root_head(input)
 consonant = self.consonant_head(input)
 vowel = self.vowel_head(input)
 x = self.intermid_unique[0](input)
 for inter in self.intermid_unique[1:]:
x = inter(x)
 x = F.normalize(x, p=2, dim=1)
 unique_p = self.arc_face_unique(x, unique)
 return root, consonant, vowel, unique_p
def forward(self, input, unique):
multi_head_outputs = self.multi_head(input, unique)
 return multi_head_outputs
def l2_norm(input,axis=1):
norm = torch.norm(input,2,axis,True)
 output = torch.div(input, norm)
 return output
class Arcface(nn.Module):
def __init__(self, embedding_size=512, classnum=51332, s=30., m=0.5):
super(Arcface, self ).__init__()
self.classnum = classnum
self.weight = Parameter(torch.Tensor(embedding_size,classnum))
self.weight.data.uniform_(-1, 1 ).renorm_(2,1,1e-5 ).mul_(1e5)
 self.m = m
self.s = s
self.cos_m = math.cos(m)
 self.sin_m = math.sin(m)
 self.mm = self.sin_m * m
self.threshold = math.cos(math.pi - m)
 def forward(self, embbedings, label):
nB = len(embbedings)
 kernel_norm = l2_norm(self.weight,axis=0)
 cos_theta = torch.mm(embbedings,kernel_norm)
 cos_theta = cos_theta.clamp(-1,1)
 cos_theta_2 = torch.pow(cos_theta, 2)
 sin_theta_2 = 1 - cos_theta_2
sin_theta = torch.sqrt(sin_theta_2)
 cos_theta_m =(cos_theta * self.cos_m - sin_theta * self.sin_m)
 cond_v = cos_theta - self.threshold
cond_mask = cond_v <= 0
keep_val =(cos_theta - self.mm)
 cos_theta_m[cond_mask] = keep_val[cond_mask]
output = cos_theta * 1.0
idx_ = torch.arange(0, nB, dtype=torch.long)
 output[idx_, label] = cos_theta_m[idx_, label]
output *= self.s
return output
class BengaliDataset(Dataset):
def __init__(self, label_csv, unique_csv, train_folder, parquet_path, transforms, cache=True, test=True):
self.label_csv = label_csv
self.unique_csv = unique_csv
self.train_folder = train_folder
self.parquet_path = parquet_path
self.label = pd.read_csv(self.label_csv)
 self.label = self.label[self.label['component']=='grapheme_root']
self.label = self.label.reset_index(drop=True)
 unique_df = pd.read_csv(self.unique_csv)
 self.names = self.label['image_id'].values
self.uniques = unique_df.grapheme.unique()
self.transforms = transforms
self.img = [None] * self.label.shape[0]
self.test = test
if cache:
self.cache_images()
def cache_images(self):
count = 0
root = './test_graphemes/'
self.p = p = pd.read_parquet(self.parquet_path ).drop(['image_id'], axis=1)
 def load_image(self, idx):
img = resize(self.p.iloc[[idx]] ).values.reshape(-1 ).reshape(IMG_SIZE, IMG_SIZE ).astype(np.uint8)
 return self.transforms(img)
 img = self.img[idx]
if img is None:
img = resize(p.iloc[[i]] ).values.reshape(-1 ).reshape(IMG_SIZE, IMG_SIZE ).astype(np.uint8)
 return self.transforms(img)
 else:
return self.transforms(img)
 def __getitem__(self, idx):
if not self.test:
img = self.load_image(idx)
 root = self.label.loc[idx]['grapheme_root']
consonant = self.label.loc[idx]['consonant_diacritic']
vowel = self.label.loc[idx]['vowel_diacritic']
unique = np.where(self.uniques == self.label.grapheme[idx])[0][0]
return transforms.ToTensor()(img), root, consonant, vowel, unique
else:
img = self.load_image(idx)
 root = 0
consonant = 0
vowel = 0
unique = 0
return transforms.ToTensor()(img), root, consonant, vowel, unique
def __len__(self):
return self.p.shape[0]
def postprocess(preds, num_classes, EXP = -1.2):
p0 = np.argmax(preds,axis=1)
 s = pd.Series(p0)
 vc = s.value_counts().sort_index()
df = pd.DataFrame({'a':np.arange(num_classes),'b':np.ones(num_classes)})
 df.b = df.a.map(vc)
 df.fillna(df.b.min() ,inplace=True)
 mat1 = np.diag(df.b.astype('float32')**EXP)
 p0 = np.argmax(preds.dot(mat1), axis=1)
 return p0
class Tester:
def __init__(self,
dataset_path='./drive/MyDrive/datasets/car classification/train_data',
batch_size=1,
model_name='tf_efficientnet_b3_ns',
test_csv='./train_labels.csv',
unique_csv='./train_labels.csv',
output_dir='.. /drive/MyDrive/ckpt/grapheme/submission.csv',
ckpt='.. /drive/MyDrive/ckpt/grapheme/20.pth',
multihead_ckpt='.. /'):
self.dataset_path = dataset_path
self.batch_size = batch_size
self.model_name = model_name
self.test_csv = test_csv
self.unique_csv = unique_csv
self.output_dir = output_dir
self.ckpt = ckpt
self.multihead_ckpt = multihead_ckpt
if model_name == 'tf_efficientnet_b0_ns':
self.input_size =(224, 224)
 elif model_name == 'tf_efficientnet_b2_ns':
self.input_size =(260, 260)
 elif model_name == 'tf_efficientnet_b3_ns':
self.input_size =(300, 300)
 elif model_name == 'tf_efficientnet_b4_ns':
self.input_size =(380, 380)
 elif model_name == 'tf_efficientnet_b6_ns':
self.input_size =(528, 528)
 else:
raise Exception('non-valid model name')
 transform = []
transform += [transforms.ToPILImage() ]
transform += [transforms.Resize(self.input_size)]
self.transform = transforms.Compose(transform)
 self.device = torch.device('cuda')
 self.model_multihead = MultiHeadSimpleModel(self.input_size, self.model_name, pretrained=False, dropout=0 ).to(self.device)
 multihead_ckpt = torch.load(self.multihead_ckpt)
 self.model_multihead.load_state_dict(multihead_ckpt['model_multihead_state_dict'])
 def test(self):
output_roots = []
output_consonants = []
output_vowels = []
count = 0
for ii in range(4):
self.test_dataset = BengaliDataset(self.test_csv, self.unique_csv, self.dataset_path, f'/kaggle/input/bengaliai-cv19/test_image_data_{ii}.parquet', self.transform, cache=True)
 self.names = self.test_dataset.names
self.test_dataloader = DataLoader(self.test_dataset, batch_size=self.batch_size, num_workers=0, shuffle=False)
 pbar = tqdm.tqdm(self.test_dataloader)
 pbar.set_description('testing process')
 self.model_multihead.eval()
with torch.no_grad() :
for it, data in enumerate(pbar):
inputs = data[0].to(self.device)
 inputs = inputs.repeat(1, 3, 1, 1)
 roots = data[1].to(self.device ).long()
consonants = data[2].to(self.device ).long()
vowels = data[3].to(self.device ).long()
uniques = data[4].to(self.device ).long()
root, consonant, vowel, unique = self.model_multihead(inputs, uniques)
 root = postprocess(torch.nn.Softmax(1 )(root ).cpu().numpy() , 168, -1.2)
 consonant = postprocess(torch.nn.Softmax(1 )(consonant[:,:8] ).cpu().numpy() , 8, -0.5)
 vowel = postprocess(torch.nn.Softmax(1 )(vowel[:,:11] ).cpu().numpy() , 11, -1.2)
 for index in range(inputs.shape[0]):
output_roots.append(root[index].item())
 output_consonants.append(consonant[index].item())
 output_vowels.append(vowel[index].item())
 del self.test_dataset.p
del self.test_dataset
del self.test_dataloader
row_id, target = [], []
for iid, r, c, v in zip(self.names, output_roots, output_consonants, output_vowels):
row_id.append(iid + '_grapheme_root')
 target.append(int(r))
row_id.append(iid + '_vowel_diacritic')
 target.append(int(v))
row_id.append(iid + '_consonant_diacritic')
 target.append(int(c))
count += 1
sub_fn = self.output_dir
sub = pd.DataFrame({'row_id': row_id, 'target': target})
 sub.to_csv(sub_fn, index=False)
 print(f'Done wrote to {sub_fn}')
 tester = Tester(dataset_path='./test_graphemes',
batch_size=128,
model_name='tf_efficientnet_b2_ns',
test_csv='/kaggle/input/bengaliai-cv19/test.csv',
unique_csv='/kaggle/input/bengaliai-cv19/train.csv',
output_dir='./submission.csv',
ckpt='/kaggle/input/graphemesingle/27.pth',
multihead_ckpt='/kaggle/input/graphemesingle/10.pth' 
)
 tester.test()<install_modules>
target_encode_cols = {
"Condition1",
"Condition2",
"Exterior1st",
"Exterior2nd",
"MSSubClass",
"Neighborhood",
"SaleType",
}
ordinal_encode_categories = ["Ex", "Gd","TA", "Fa", "Po", "Unknown"]
ordinal_encode_cols = {
"BsmtCond",
"BsmtQual",
"ExterCond",
"ExterQual",
"FireplaceQu",
"GarageCond",
"GarageQual",
"HeatingQC",
"KitchenQual",
"PoolQC",
}
feature_transformers = {
"ordinal": OrdinalEncoder(categories=[ordinal_encode_categories] * len(ordinal_encode_cols)) ,
"normal": QuantileTransformer(n_quantiles=500, output_distribution="normal"),
"target": ce.target_encoder.TargetEncoder() ,
"onehot": OneHotEncoder(handle_unknown="ignore"),
}
feature_cleaner = ColumnTransformer(
 transformers=[ 
(
 "num_normal",
clone(feature_transformers["normal"]),
list(numeric_cols)
), 
(
 "cat_ordinal",
clone(feature_transformers["ordinal"]),
list(ordinal_encode_cols)
), 
(
 "cat_target",
clone(feature_transformers["target"]),
list(target_encode_cols)
), 
(
 "cat_onehot",
clone(feature_transformers["onehot"]),
list(categoric_cols - ordinal_encode_cols - target_encode_cols)
),
],
remainder="drop"
)
!pip install.. /input/bengaliutils2/timm-0.1.18-py3-none-any.whl<import_modules>
def transform_regressor(regressor):
return TransformedTargetRegressor(regressor=regressor, func=np.log1p, inverse_func=np.expm1 )
from torch import nn
import timm
from torch.utils.data import DataLoader, Dataset
import pandas as pd
import cv2
import numpy as np
import matplotlib.pyplot as plt
import torch.nn.functional as F
import torch
from timm.models.layers.activations import Swish
from torch.nn import Conv2d, BatchNorm2d, Sequential, Linear
from torch.nn.modules.flatten import Flatten
from albumentations import Compose, Normalize
from albumentations.pytorch import ToTensorV2<feature_engineering>
pipe = Pipeline(steps=[ 
("feature_adder", FeatureAdder()), 
("feature_imputer", feature_imputer), 
("feature_cleaner", feature_cleaner), 
("model", transform_regressor(ElasticNetCV(cv=5)))
 ] )
class MishFunction(torch.autograd.Function):
@staticmethod
def forward(ctx, x):
ctx.save_for_backward(x)
 return x * torch.tanh(F.softplus(x))
@staticmethod
def backward(ctx, grad_output):
x = ctx.saved_variables[0]
sigmoid = torch.sigmoid(x)
 tanh_sp = torch.tanh(F.softplus(x))
return grad_output *(tanh_sp + x * sigmoid *(1 - tanh_sp * tanh_sp))
class Mish(nn.Module):
def forward(self, x):
return MishFunction.apply(x)
 def to_Mish(model):
for child_name, child in model.named_children() :
if isinstance(child, Swish):
setattr(model, child_name, Mish())
 else:
to_Mish(child )<categorify>
feature_param_grid = {
"feature_cleaner__cat_ordinal": [
clone(feature_transformers["ordinal"]),
clone(feature_transformers["onehot"]),
],
"feature_cleaner__cat_target": [
clone(feature_transformers["target"]),
clone(feature_transformers["onehot"])
 ],
}
grid = GridSearchCV(pipe, param_grid=feature_param_grid, cv=5, scoring="neg_mean_squared_log_error", n_jobs=-1)
 grid.fit(X_train, y_train )
class EfficientNew(nn.Module):
def __init__(self, num_classes, encoder):
super().__init__()
n_channels_dict = {'efficientnet_b0': 1280, 'efficientnet_b1': 1280, 'efficientnet_b2': 1408,
'efficientnet_b3': 1536, 'efficientnet_b4': 1792, 'efficientnet_b5': 2048,
'efficientnet_b6': 2304, 'efficientnet_b7': 2560, 'seresnext50_32x4d': 2048,
'tf_efficientnet_b0_ns': 1280, 'tf_efficientnet_b3_ns': 1536,
'tf_efficientnet_b4_ns': 1792}
self.net = timm.create_model(encoder, pretrained=False)
 to_Mish(self.net)
 out_features = n_channels_dict[encoder]
self.head_grapheme_root = AverageHead(num_classes[0], out_features)
 self.head_vowel_diacritic = AverageHead(num_classes[1], out_features)
 self.head_consonant_diacritic = AverageHead(num_classes[2], out_features)
 def forward(self, x):
x = self.net.forward_features(x)
 logit_grapheme_root = self.head_grapheme_root(x)
 logit_vowel_diacritic = self.head_vowel_diacritic(x)
 logit_consonant_diacritic = self.head_consonant_diacritic(x)
 return logit_grapheme_root, logit_vowel_diacritic, logit_consonant_diacritic
class AverageHead(nn.Module):
def __init__(self, num_classes, out_features):
super().__init__()
self.post_layers = Sequential(Flatten() , Linear(out_features, num_classes))
self._init_weight()
def _init_weight(self):
for m in self.modules() :
if isinstance(m, Conv2d):
torch.nn.init.kaiming_normal_(m.weight)
 elif isinstance(m, BatchNorm2d):
m.weight.data.fill_(1.0)
 m.bias.data.zero_()
def forward(self, x):
x = 0.5 *(F.adaptive_avg_pool2d(x, 1)+ F.adaptive_max_pool2d(x, 1))
return self.post_layers(x )<categorify>
grid.best_params_
HEIGHT = 137
WIDTH = 236
def valid_aug(image_size=None):
augs_list = [Normalize() , ToTensorV2() ]
return Compose(augs_list, p=1)
 class GraphemeDatasetTest(Dataset):
def __init__(self, fname):
self.transform = valid_aug()
self.df = pd.read_parquet(fname)
 self.data = self.df.iloc[:, 1:].values.reshape(-1, HEIGHT, WIDTH ).astype(np.uint8)
 def __len__(self):
return len(self.data)
 def __getitem__(self, idx):
name = self.df.iloc[idx, 0]
image = self.data[idx]
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
 if self.transform:
image = self.transform(image=image)['image']
return image, name
class Predictor:
def __init__(self, model):
self.device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
 self.model = model.to(self.device, dtype=torch.float32);
self.model.eval()
print(f'Model prepared.Device is {self.device}')
 def predict(self, inputs, softmax_after=True):
inputs = inputs.to(self.device, dtype=torch.float32)
 with torch.no_grad() :
out_gr, out_vd, out_cd = self.model(inputs)
 if not softmax_after:
out_gr = torch.nn.functional.softmax(out_gr, dim=1)
 out_vd = torch.nn.functional.softmax(out_vd, dim=1)
 out_cd = torch.nn.functional.softmax(out_cd, dim=1)
 return out_gr, out_vd, out_cd
def load(self, path):
checkpoint = torch.load(path, map_location=self.device)
 self.model.load_state_dict(checkpoint['model_state_dict'] )<define_variables>
md(f"Model score on the validation set: `{rmsle(y_test, grid.predict(X_test)) :.3f}`")
 md(f"Model score on the train set: `{rmsle(y_train, grid.predict(X_train)) :.3f}`" )
predictors = []
for i, model_path in enumerate([
'/kaggle/input/bengaliutils2/b3_9863_f0_ft1.pth',
'/kaggle/input/bengaliutils2/b3_9855_f1_ft1.pth',
'/kaggle/input/bengaliutils2/b3_9865_f2_ft1.pth',
'/kaggle/input/bengaliutils2/b3_9854_f3_ft1.pth',
'/kaggle/input/bengaliutils2/b3_9857_f4_ft1.pth'
]):
predictor = Predictor(EfficientNew([168, 11, 7], 'tf_efficientnet_b3_ns'))
predictor.load(model_path)
 predictors.append(predictor)
 predictors_count = len(predictors)
 def predict_to_numpy(predict):
return predict.data.cpu().numpy().argmax(axis=1)
 def predict_to_numpy_softmax(predict):
return torch.nn.functional.softmax(predict, dim=1 ).data.cpu().numpy().argmax(axis=1)
 def make_prediction(images, softmax_after=True):
global was
outputs_gr = 0
outputs_vd = 0
outputs_cd = 0
for predictor in predictors:
gr, vd, cd = predictor.predict(images, softmax_after)
 outputs_gr += gr
outputs_vd += vd
outputs_cd += cd
outputs_gr /= predictors_count
outputs_vd /= predictors_count
outputs_cd /= predictors_count
if not was:
print(outputs_vd)
 was = True
if softmax_after:
print("Averaging raw then softmax!")
 roots = predict_to_numpy_softmax(outputs_gr)
 vowels = predict_to_numpy_softmax(outputs_vd)
 consonants = predict_to_numpy_softmax(outputs_cd)
 else:
print("Averaging softmax!")
 roots = predict_to_numpy(outputs_gr)
 vowels = predict_to_numpy(outputs_vd)
 consonants = predict_to_numpy(outputs_cd)
 return roots, vowels, consonants<create_dataframe>
y_train_trf = np.log1p(y_train)
 y_test_trf = np.log1p(y_test)
 xgb_pipe_trf = Pipeline(grid.best_estimator_.steps[:-1])
 xgb_pipe_trf.fit(X_train, y_train_trf)
 X_train_trf = xgb_pipe_trf.transform(X_train)
 X_test_trf = xgb_pipe_trf.transform(X_test )
%%time
target = []
row_id = []
was = False
for i in range(4):
dataset = GraphemeDatasetTest(f'.. /input/bengaliai-cv19/test_image_data_{i}.parquet')
 data_loader = DataLoader(dataset, batch_size=256, num_workers=4, shuffle=False)
 for images, images_id in data_loader:
p1, p2, p3 = make_prediction(images, True)
 for idx, name in enumerate(images_id):
row_id += [f'{name}_grapheme_root', f'{name}_vowel_diacritic',
f'{name}_consonant_diacritic']
target += [p1[idx].item() , p2[idx].item() , p3[idx].item() ]<save_to_csv>
xgb_fit_params = {
"early_stopping_rounds": 10,
"eval_set" : [(X_test_trf, y_test_trf)],
"verbose": False
}
xgb_model = xgb.XGBRegressor(objective="reg:squaredlogerror" )
df_submission = pd.DataFrame(
 {
'row_id': row_id,
'target': target
},
columns=['row_id','target'] 
)
 df_submission.to_csv('submission.csv', index=False)
 df_submission.head(10 )<define_variables>

 one_to_left = st.beta(10, 1)
 from_zero_positive = st.expon(0, 50)
 xgb_params = {
"n_estimators": st.randint(3, 2000),
"max_depth": st.randint(3, 60),
"learning_rate": st.uniform(0.05, 0.4),
"colsample_bytree": one_to_left,
"subsample": one_to_left,
"gamma": st.uniform(0, 10),
"reg_alpha": from_zero_positive,
"min_child_weight": from_zero_positive,
}
xgb_grid = RandomizedSearchCV(
 xgb_model,
param_distributions=xgb_params,
n_iter=20,
cv=5,
scoring="neg_mean_squared_log_error", 
)
 xgb_grid.fit(X_train_trf, y_train_trf, **xgb_fit_params )
pt_models = ".. /input/pretrained-models/pretrained-models.pytorch-master/"
sys.path.insert(0,pt_models)
<import_modules>
xgb_grid.best_params_
import pandas as pd
import joblib
import glob
from tqdm import tqdm
import pandas as pd
import albumentations
import joblib
import numpy as np
import torch
from PIL import Image
import pretrainedmodels
import torch.nn as nn
from torch.nn import functional as F
import os
import ast
import torch
import torch.nn as nn
import numpy as np
import sklearn.metrics<define_variables>
xgb_pipe = Pipeline([*xgb_pipe_trf.steps,("model", transform_regressor(xgb_grid.best_estimator_)) ])
 xgb_pipe.fit(X_train, y_train, **prepend_keys(xgb_fit_params, "model__"))
pt_models = ".. /input/pretrained-models/pretrained-models.pytorch-master/"
sys.path.insert(0, pt_models)
<import_modules>
md(f"Model score on the validation set: `{rmsle(y_test, xgb_pipe.predict(X_test)) :.3f}`")
 md(f"Model score on the train set: `{rmsle(y_train, xgb_pipe.predict(X_train)) :.3f}`" )
import glob
import torch
import albumentations
import pandas as pd
import numpy as np
from tqdm import tqdm
from PIL import Image
import joblib
import torch.nn as nn
from torch.nn import functional as F<define_search_space>
submission = pd.DataFrame({"SalePrice": grid.predict(test)}, index=test.index)
 submission
<choose_model_class><EOS> 
submission.to_csv("submission.csv" )