Kaggle competition: House Prices - Advanced Regression Techniques
<SOS> metric: rmsle Kaggle data source: house-prices-advanced-regression-techniques<define_variables>
%matplotlib inline
IMAGE_SIZE = [512, 512]
EPOCHS = 20
BATCH_SIZE = 16 * strategy.num_replicas_in_sync<init_hyperparams>
def load_housing_data(data_name):
csv_path = os.path.join('.. /input/house-prices-advanced-regression-techniques', data_name)
 return pd.read_csv(csv_path )
LR_START = 0.00001
LR_MAX = 0.00005 * strategy.num_replicas_in_sync
LR_MIN = 0.00001
LR_RAMPUP_EPOCHS = 5
LR_SUSTAIN_EPOCHS = 0
LR_EXP_DECAY =.8
def lrfn(epoch):
if epoch < LR_RAMPUP_EPOCHS:
lr =(LR_MAX - LR_START)/ LR_RAMPUP_EPOCHS * epoch + LR_START
elif epoch < LR_RAMPUP_EPOCHS + LR_SUSTAIN_EPOCHS:
lr = LR_MAX
else:
lr =(LR_MAX - LR_MIN)* LR_EXP_DECAY**(epoch - LR_RAMPUP_EPOCHS - LR_SUSTAIN_EPOCHS)+ LR_MIN
return lr
lr_callback = tf.keras.callbacks.LearningRateScheduler(lrfn, verbose=True)
 rng = [i for i in range(EPOCHS)]
y = [lrfn(x)for x in rng]
plt.plot(rng, y)
 print("Learning rate schedule: {:.3g} to {:.3g} to {:.3g}".format(y[0], max(y), y[-1]))<define_variables>
train, test = load_housing_data("train.csv"), load_housing_data("test.csv" )
GCS_PATH_SELECT = {
192: GCS_DS_PATH + '/tfrecords-jpeg-192x192',
224: GCS_DS_PATH + '/tfrecords-jpeg-224x224',
331: GCS_DS_PATH + '/tfrecords-jpeg-331x331',
512: GCS_DS_PATH + '/tfrecords-jpeg-512x512'
}
GCS_PATH = GCS_PATH_SELECT[IMAGE_SIZE[0]]
TRAINING_FILENAMES = tf.io.gfile.glob(GCS_PATH + '/train/*.tfrec')
 VALIDATION_FILENAMES = tf.io.gfile.glob(GCS_PATH + '/val/*.tfrec')
 TEST_FILENAMES = tf.io.gfile.glob(GCS_PATH + '/test/*.tfrec')
 SKIP_VALIDATION = True
if SKIP_VALIDATION:
TRAINING_FILENAMES = TRAINING_FILENAMES + VALIDATION_FILENAMES
VALIDATION_MISMATCHES_IDS = []<define_variables>
train['YrSold'].value_counts()
CLASSES = ['pink primrose', 'hard-leaved pocket orchid', 'canterbury bells', 'sweet pea', 'wild geranium', 'tiger lily', 'moon orchid', 'bird of paradise', 'monkshood', 'globe thistle',
'snapdragon', "colt's foot", 'king protea', 'spear thistle', 'yellow iris', 'globe-flower', 'purple coneflower', 'peruvian lily', 'balloon flower', 'giant white arum lily',
'fire lily', 'pincushion flower', 'fritillary', 'red ginger', 'grape hyacinth', 'corn poppy', 'prince of wales feathers', 'stemless gentian', 'artichoke', 'sweet william',
'carnation', 'garden phlox', 'love in the mist', 'cosmos', 'alpine sea holly', 'ruby-lipped cattleya', 'cape flower', 'great masterwort', 'siam tulip', 'lenten rose',
'barberton daisy', 'daffodil', 'sword lily', 'poinsettia', 'bolero deep blue', 'wallflower', 'marigold', 'buttercup', 'daisy', 'common dandelion',
'petunia', 'wild pansy', 'primula', 'sunflower', 'lilac hibiscus', 'bishop of llandaff', 'gaura', 'geranium', 'orange dahlia', 'pink-yellow dahlia',
'cautleya spicata', 'japanese anemone', 'black-eyed susan', 'silverbush', 'californian poppy', 'osteospermum', 'spring crocus', 'iris', 'windflower', 'tree poppy',
'gazania', 'azalea', 'water lily', 'rose', 'thorn apple', 'morning glory', 'passion flower', 'lotus', 'toad lily', 'anthurium',
'frangipani', 'clematis', 'hibiscus', 'columbine', 'desert-rose', 'tree mallow', 'magnolia', 'cyclamen ', 'watercress', 'canna lily',
'hippeastrum ', 'bee balm', 'pink quill', 'foxglove', 'bougainvillea', 'camellia', 'mallow', 'mexican petunia', 'bromelia', 'blanket flower',
'trumpet creeper', 'blackberry lily', 'common tulip', 'wild rose']<normalization>
def to_str(feature, data=train):
data[feature] = data[feature].astype(str )
def get_mat(rotation, shear, height_zoom, width_zoom, height_shift, width_shift):
rotation = math.pi * rotation / 180.
 shear = math.pi * shear / 180.
 c1 = tf.math.cos(rotation)
 s1 = tf.math.sin(rotation)
 one = tf.constant([1],dtype='float32')
 zero = tf.constant([0],dtype='float32')
 rotation_matrix = tf.reshape(tf.concat([c1,s1,zero, -s1,c1,zero, zero,zero,one],axis=0),[3,3])
 c2 = tf.math.cos(shear)
 s2 = tf.math.sin(shear)
 shear_matrix = tf.reshape(tf.concat([one,s2,zero, zero,c2,zero, zero,zero,one],axis=0),[3,3])
 zoom_matrix = tf.reshape(tf.concat([one/height_zoom,zero,zero, zero,one/width_zoom,zero, zero,zero,one],axis=0),[3,3])
 shift_matrix = tf.reshape(tf.concat([one,zero,height_shift, zero,one,width_shift, zero,zero,one],axis=0),[3,3])
 return K.dot(K.dot(rotation_matrix, shear_matrix), K.dot(zoom_matrix, shift_matrix))
def transform(image,label):
DIM = IMAGE_SIZE[0]
XDIM = DIM%2
rot = 15.* tf.random.normal([1],dtype='float32')
 shr = 5.* tf.random.normal([1],dtype='float32')
 h_zoom = 1.0 + tf.random.normal([1],dtype='float32')/10.
 w_zoom = 1.0 + tf.random.normal([1],dtype='float32')/10.
 h_shift = 16.* tf.random.normal([1],dtype='float32')
 w_shift = 16.* tf.random.normal([1],dtype='float32')
 m = get_mat(rot,shr,h_zoom,w_zoom,h_shift,w_shift)
 x = tf.repeat(tf.range(DIM//2,-DIM//2,-1), DIM)
 y = tf.tile(tf.range(-DIM//2,DIM//2),[DIM])
 z = tf.ones([DIM*DIM],dtype='int32')
 idx = tf.stack([x,y,z])
 idx2 = K.dot(m,tf.cast(idx,dtype='float32'))
idx2 = K.cast(idx2,dtype='int32')
 idx2 = K.clip(idx2,-DIM//2+XDIM+1,DIM//2)
 idx3 = tf.stack([DIM//2-idx2[0,], DIM//2-1+idx2[1,]])
 d = tf.gather_nd(image,tf.transpose(idx3))
return tf.reshape(d,[DIM,DIM,3]),label 
<categorify>
to_str('YrSold')
 to_str('MoSold')
 to_str('MSSubClass')
 to_str('YrSold',test)
 to_str('MoSold',test)
 to_str('MSSubClass',test )
def decode_image(image_data):
image = tf.image.decode_jpeg(image_data, channels=3)
 image = tf.cast(image, tf.float32)/ 255.0
image = tf.reshape(image, [*IMAGE_SIZE, 3])
 return image
def read_labeled_tfrecord(example):
LABELED_TFREC_FORMAT = {
"image": tf.io.FixedLenFeature([], tf.string),
"class": tf.io.FixedLenFeature([], tf.int64),
}
example = tf.io.parse_single_example(example, LABELED_TFREC_FORMAT)
 image = decode_image(example['image'])
 label = tf.cast(example['class'], tf.int32)
 return image, label
def read_unlabeled_tfrecord(example):
UNLABELED_TFREC_FORMAT = {
"image": tf.io.FixedLenFeature([], tf.string),
"id": tf.io.FixedLenFeature([], tf.string),
}
example = tf.io.parse_single_example(example, UNLABELED_TFREC_FORMAT)
 image = decode_image(example['image'])
 idnum = example['id']
return image, idnum
def read_labeled_id_tfrecord(example):
LABELED_ID_TFREC_FORMAT = {
"image": tf.io.FixedLenFeature([], tf.string),
"class": tf.io.FixedLenFeature([], tf.int64),
"id": tf.io.FixedLenFeature([], tf.string),
}
example = tf.io.parse_single_example(example, LABELED_ID_TFREC_FORMAT)
 image = decode_image(example['image'])
 label = tf.cast(example['class'], tf.int32)
 idnum = example['id']
return image, label, idnum
def load_dataset(filenames, labeled=True, ordered=False):
ignore_order = tf.data.Options()
if not ordered:
ignore_order.experimental_deterministic = False
dataset = tf.data.TFRecordDataset(filenames, num_parallel_reads=AUTO)
 dataset = dataset.with_options(ignore_order)
 dataset = dataset.map(read_labeled_id_tfrecord if labeled else read_unlabeled_tfrecord, num_parallel_calls=AUTO)
 return dataset
def load_dataset_with_id(filenames, ordered=False):
ignore_order = tf.data.Options()
if not ordered:
ignore_order.experimental_deterministic = False
dataset = tf.data.TFRecordDataset(filenames, num_parallel_reads=AUTO)
 dataset = dataset.with_options(ignore_order)
 dataset = dataset.map(read_labeled_id_tfrecord, num_parallel_calls=AUTO)
 return dataset
def data_augment(image, label):
image = tf.image.random_flip_left_right(image)
 return image, label
def get_training_dataset() :
dataset = load_dataset(TRAINING_FILENAMES, labeled=True)
 dataset = dataset.filter(lambda image, label, idnum: tf.reduce_sum(tf.cast(idnum == VALIDATION_MISMATCHES_IDS, tf.int32)) ==0)
 dataset = dataset.map(lambda image, label, idnum: [image, label])
 dataset = dataset.map(transform, num_parallel_calls=AUTO)
 dataset = dataset.map(data_augment, num_parallel_calls=AUTO)
 dataset = dataset.repeat()
dataset = dataset.shuffle(2048)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.prefetch(AUTO)
 return dataset
def get_validation_dataset(ordered=False):
dataset = load_dataset(VALIDATION_FILENAMES, labeled=True, ordered=ordered)
 dataset = dataset.filter(lambda image, label, idnum: tf.reduce_sum(tf.cast(idnum == VALIDATION_MISMATCHES_IDS, tf.int32)) ==0)
 dataset = dataset.map(lambda image, label, idnum: [image, label])
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.cache()
dataset = dataset.prefetch(AUTO)
 return dataset
def get_validation_dataset_with_id(ordered=False):
dataset = load_dataset_with_id(VALIDATION_FILENAMES, ordered=ordered)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.cache()
dataset = dataset.prefetch(AUTO)
 return dataset
def get_test_dataset(ordered=False):
dataset = load_dataset(TEST_FILENAMES, labeled=False, ordered=ordered)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.prefetch(AUTO)
 return dataset
def count_data_items(filenames):
dataset = load_dataset(filenames,labeled = False)
 dataset = dataset.map(lambda image, idnum: idnum)
 dataset = dataset.filter(lambda idnum: tf.reduce_sum(tf.cast(idnum == VALIDATION_MISMATCHES_IDS, tf.int32)) ==0)
 uids = next(iter(dataset.batch(21000)) ).numpy().astype('U')
 return len(np.unique(uids))
NUM_TRAINING_IMAGES = count_data_items(TRAINING_FILENAMES)
 NUM_VALIDATION_IMAGES =(1 - SKIP_VALIDATION)* count_data_items(VALIDATION_FILENAMES)
 NUM_TEST_IMAGES = count_data_items(TEST_FILENAMES)
 STEPS_PER_EPOCH = NUM_TRAINING_IMAGES // BATCH_SIZE
print('Dataset: {} training images, {} validation images, {} unlabeled test images'.format(NUM_TRAINING_IMAGES, NUM_VALIDATION_IMAGES, NUM_TEST_IMAGES))<choose_model_class>
train.dtypes.value_counts()
with strategy.scope() :
enet = efn.EfficientNetB7(
 input_shape=(512, 512, 3),
weights='noisy-student',
include_top=False 
)
 model = tf.keras.Sequential([
enet,
tf.keras.layers.GlobalAveragePooling2D() ,
tf.keras.layers.Dense(len(CLASSES), activation='softmax')
 ])
 model.compile(
 optimizer=tf.keras.optimizers.Adam(lr=0.0001),
loss = 'sparse_categorical_crossentropy',
metrics=['sparse_categorical_accuracy'] 
)
 model.summary()<train_model>
sns.set_style("darkgrid" )
history = model.fit(
 get_training_dataset() ,
steps_per_epoch=STEPS_PER_EPOCH,
epochs=EPOCHS,
callbacks=[lr_callback],
validation_data=None if SKIP_VALIDATION else get_validation_dataset()
)<choose_model_class>
train.sort_values('GrLivArea', ascending=False ).head(2)['GrLivArea']
with strategy.scope() :
rnet = DenseNet201(
 input_shape=(512, 512, 3),
weights='imagenet',
include_top=False 
)
 model2 = tf.keras.Sequential([
rnet,
tf.keras.layers.GlobalAveragePooling2D() ,
tf.keras.layers.Dense(len(CLASSES), activation='softmax')
 ])
 model2.compile(
 optimizer=tf.keras.optimizers.Adam(lr=0.0001),
loss = 'sparse_categorical_crossentropy',
metrics=['sparse_categorical_accuracy'] 
)
 model2.summary()<train_model>
train = train[train['GrLivArea'] < 4676]
history2 = model2.fit(
 get_training_dataset() ,
steps_per_epoch=STEPS_PER_EPOCH,
epochs=EPOCHS,
callbacks=[lr_callback],
validation_data=None if SKIP_VALIDATION else get_validation_dataset()
)<save_to_csv>
train.sort_values('GrLivArea', ascending=False ).head(2)['GrLivArea']
test_ds = get_test_dataset(ordered=True)
 print('Computing predictions...')
 test_images_ds = test_ds.map(lambda image, idnum: image)
 probabilities = best_alpha*model.predict(test_images_ds)+(1-best_alpha)*model2.predict(test_images_ds)
 predictions = np.argmax(probabilities, axis=-1)
 print(predictions)
 print('Generating submission.csv file...')
 test_ids_ds = test_ds.map(lambda image, idnum: idnum ).unbatch()
test_ids = next(iter(test_ids_ds.batch(NUM_TEST_IMAGES)) ).numpy().astype('U')
 np.savetxt('submission.csv', np.rec.fromarrays([test_ids, predictions]), fmt=['%s', '%d'], delimiter=',', header='id,label', comments='' )<find_best_params>
train['SalePrice'] = np.log1p(train['SalePrice'] )
try:
tpu = tf.distribute.cluster_resolver.TPUClusterResolver()
print("Running on tpu", tpu.master())
 except ValueError:
tpu = None
if tpu:
tf.config.experimental_connect_to_cluster(tpu)
 tf.tpu.experimental.initialize_tpu_system(tpu)
 strategy = tf.distribute.experimental.TPUStrategy(tpu)
 else:
strategy = tf.distribute.get_strategy()
print("Replicas", strategy.num_replicas_in_sync )<define_variables>
test_dummy = test.copy()
test_dummy['SalePrice'] = np.zeros(len(test))
combined = pd.concat([train,test_dummy] )
GCS_DS_PATH = KaggleDatasets().get_gcs_path('tpu-getting-started')
 GCS_PATH = GCS_DS_PATH + '/tfrecords-jpeg-512x512'<define_variables>
def missing_percent(data, n=35):
num_of_nulls = data.isnull().sum().sort_values(ascending=False)
 percent =(data.isnull().sum() /data.isnull().count() ).sort_values(ascending=False)
 result = pd.concat([num_of_nulls, percent], axis=1, keys=['Number', 'Percent'])
 return result.head(n )
AUTO = tf.data.experimental.AUTOTUNE
IMAGE_SIZE = [512,512]
EPOCHS = 12
BATCH_SIZE = 16*strategy.num_replicas_in_sync
TRAINING_FILENAMES = tf.io.gfile.glob(GCS_PATH + '/train/*.tfrec')
 VALIDATION_FILENAMES = tf.io.gfile.glob(GCS_PATH + '/val/*.tfrec')
 TEST_FILENAMES = tf.io.gfile.glob(GCS_PATH + '/test/*.tfrec' )<groupby>
missing_percent(test )
def count_data_items(filenames):
n = [int(re.compile(r"-([0-9]*)\." ).search(filename ).group(1)) for filename in filenames]
return np.sum(n)
<count_values>
warnings.filterwarnings("ignore" )
NUM_TRAINING_IMAGES = count_data_items(TRAINING_FILENAMES)
 NUM_VALIDATION_IMAGES = count_data_items(VALIDATION_FILENAMES)
 NUM_TEST_IMAGES = count_data_items(TEST_FILENAMES)
 print('Dataset: {} training images, {} validation images, {} unlabeled test images'.format(NUM_TRAINING_IMAGES, NUM_VALIDATION_IMAGES, NUM_TEST_IMAGES))<categorify>
def fill_missing(df):
df['Functional'] = df['Functional'].fillna('Typ')
 cats = ['Electrical','SaleType','Exterior2nd','KitchenQual','Exterior1st','MSZoning']
for cat in cats:
df[cat] = df[cat].fillna(df[cat].mode() [0])
 df['LotFrontage'] = df['LotFrontage'].fillna(
 df.groupby('Neighborhood')['LotFrontage'].transform('median'))
df_cat = df[list(df.select_dtypes(include='object' ).columns)]
df.update(df_cat.fillna('None'))
df_num = df[list(df.select_dtypes(include='number' ).columns)]
df.update(df_num.fillna(0))
return df
def decode_image(image_data):
image = tf.image.decode_jpeg(image_data, channels = 3)
 image = tf.cast(image, tf.float32)/255.0
image = tf.reshape(image, [*IMAGE_SIZE, 3])
 return image
def read_labeled_tfrecord(example):
LABELED_TFREC_FORMAT = {
"image": tf.io.FixedLenFeature([], tf.string),
"class": tf.io.FixedLenFeature([], tf.int64)
 }
example = tf.io.parse_single_example(example, LABELED_TFREC_FORMAT)
 image = decode_image(example['image'])
 label = tf.cast(example['class'], tf.int32)
 return image,label
def read_unlabeled_tfrecord(example):
UNLABELED_TFREC_FORMAT = {
"image": tf.io.FixedLenFeature([], tf.string),
"id": tf.io.FixedLenFeature([], tf.string)
 }
example = tf.io.parse_single_example(example, UNLABELED_TFREC_FORMAT)
 image = decode_image(example['image'])
 idnum = example['id']
return image,idnum 
<create_dataframe>
fill_missing(train ).isnull().sum().sum()
def load_dataset(filenames, labeled = True, ordered = False):
ignore_order = tf.data.Options()
if not ordered:
ignore_order.experimental_deterministic = False
dataset = tf.data.TFRecordDataset(filenames, num_parallel_reads = AUTO)
 dataset = dataset.with_options(ignore_order)
 dataset = dataset.map(read_labeled_tfrecord if labeled else read_unlabeled_tfrecord, num_parallel_calls = AUTO)
 return dataset
def data_augment(image,label):
image = tf.image.random_flip_left_right(image)
 image = tf.image.random_saturation(image, 0, 2)
 return image,label
def get_training_dataset() :
dataset = load_dataset(TRAINING_FILENAMES, labeled = True)
 dataset = dataset.map(data_augment, num_parallel_calls = AUTO)
 dataset = dataset.repeat()
dataset = dataset.shuffle(2048)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.prefetch(AUTO)
 return dataset
def get_validation_dataset(ordered= False):
dataset = load_dataset(VALIDATION_FILENAMES, labeled = True, ordered = ordered)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.cache()
dataset = dataset.prefetch(AUTO)
 return dataset
def get_test_dataset(ordered = False):
dataset = load_dataset(TEST_FILENAMES, labeled = False, ordered= ordered)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.prefetch(AUTO)
 return dataset 
<train_model>
fill_missing(test ).isnull().sum().sum()
ds_train = get_training_dataset()
ds_val = get_validation_dataset()
ds_test = get_test_dataset()
print("Training", ds_train)
 print("Validation", ds_val)
 print("Test", ds_test)
<define_variables>
test_dummy = test.copy()
test_dummy['SalePrice'] = np.zeros(len(test))
combined = pd.concat([train,test_dummy] )
CLASSES = ['pink primrose', 'hard-leaved pocket orchid', 'canterbury bells', 'sweet pea', 'wild geranium', 'tiger lily', 'moon orchid', 'bird of paradise', 'monkshood', 'globe thistle',
'snapdragon', "colt's foot", 'king protea', 'spear thistle', 'yellow iris', 'globe-flower', 'purple coneflower', 'peruvian lily', 'balloon flower', 'giant white arum lily',
'fire lily', 'pincushion flower', 'fritillary', 'red ginger', 'grape hyacinth', 'corn poppy', 'prince of wales feathers', 'stemless gentian', 'artichoke', 'sweet william',
'carnation', 'garden phlox', 'love in the mist', 'cosmos', 'alpine sea holly', 'ruby-lipped cattleya', 'cape flower', 'great masterwort', 'siam tulip', 'lenten rose',
'barberton daisy', 'daffodil', 'sword lily', 'poinsettia', 'bolero deep blue', 'wallflower', 'marigold', 'buttercup', 'daisy', 'common dandelion',
'petunia', 'wild pansy', 'primula', 'sunflower', 'lilac hibiscus', 'bishop of llandaff', 'gaura', 'geranium', 'orange dahlia', 'pink-yellow dahlia',
'cautleya spicata', 'japanese anemone', 'black-eyed susan', 'silverbush', 'californian poppy', 'osteospermum', 'spring crocus', 'iris', 'windflower', 'tree poppy',
'gazania', 'azalea', 'water lily', 'rose', 'thorn apple', 'morning glory', 'passion flower', 'lotus', 'toad lily', 'anthurium',
'frangipani', 'clematis', 'hibiscus', 'columbine', 'desert-rose', 'tree mallow', 'magnolia', 'cyclamen ', 'watercress', 'canna lily',
'hippeastrum ', 'bee balm', 'pink quill', 'foxglove', 'bougainvillea', 'camellia', 'mallow', 'mexican petunia', 'bromelia', 'blanket flower',
'trumpet creeper', 'blackberry lily', 'common tulip', 'wild rose']<train_model>
missing_percent(combined,1 )
print("Number of classes: {}".format(len(CLASSES)))
 print("First five classes, sorted alphabetically:")
 for name in sorted(CLASSES)[:5]:
print(name)
 print("number of training images: {}".format(NUM_TRAINING_IMAGES))<train_model>
def fix_skew(df):
skew_index = []
def show_skew(df):
df_num = df[list(df.select_dtypes(include='number' ).columns)]
skew_features = df_num.apply(lambda x: x.skew() ).sort_values(ascending=False)
 high_skew = skew_features[skew_features > 0.6]
nonlocal skew_index
skew_index = high_skew.index
print("{} features have skew > 0.6 :".format(high_skew.shape[0]))
skewness = pd.DataFrame({'Skew' :high_skew})
 print(skew_features.head(10))
show_skew(df)
 for i in skew_index:
df[i] = boxcox1p(df[i], boxcox_normmax(df[i] + 1))
show_skew(df )
print("Training data shapes")
 for image,label in ds_train.take(3):
print(image.numpy().shape, label.numpy().shape)
 print("training data label examples:", label.numpy() )<data_type_conversions>
combined['Has2ndFlr'] = combined['2ndFlrSF'].apply(lambda x : 1 if x > 0 else 0)
 combined['HasWoodDeck'] = combined['WoodDeckSF'].apply(lambda x : 1 if x > 0 else 0)
 combined['HasOpenPorch'] = combined['OpenPorchSF'].apply(lambda x : 1 if x > 0 else 0)
 combined['HasEnclosedPorch'] = combined['EnclosedPorch'].apply(lambda x : 1 if x > 0 else 0)
 combined['Has3SsnPorch'] = combined['3SsnPorch'].apply(lambda x : 1 if x > 0 else 0)
 combined['HasScreenPorch'] = combined['ScreenPorch'].apply(lambda x : 1 if x > 0 else 0 )
print("Test data shapes")
 for image,idnum in ds_test.take(3):
print(image.numpy().shape, idnum.numpy().shape)
 print("test data IDs", idnum.numpy().astype('U'))<define_variables>
def binarize(column, data=combined):
print(combined[column].value_counts())
 combined[column] = combined[column].apply(lambda x : 0 if x == 'None' else 1)
 print(combined[column].value_counts() )
one_batch = next(iter(ds_train.unbatch().batch(20)))
 display_batch_of_images(one_batch )<init_hyperparams>
combined['HouseQualAdd'] = combined['OverallQual'] + combined['OverallCond']
combined['HouseQualProd'] = combined['OverallQual'] * combined['OverallCond']
LR_START = 0.00001
LR_MAX = 0.00005 * strategy.num_replicas_in_sync
LR_MIN = LR_START
LR_RAMPUP_EPOCHS = 5
LR_SUSTAIN_EPOCHS = 0
LR_EXP_DECAY = 0.80
def lrfn(epoch):
if epoch < LR_RAMPUP_EPOCHS:
lr = LR_START +(epoch *(LR_MAX - LR_START)/ LR_RAMPUP_EPOCHS)
 elif epoch <(LR_RAMPUP_EPOCHS + LR_SUSTAIN_EPOCHS):
lr = LR_MAX
else:
lr = LR_MIN +(LR_MAX - LR_MIN)* LR_EXP_DECAY **(epoch - LR_RAMPUP_EPOCHS - LR_SUSTAIN_EPOCHS)
 return lr
lr_callback = tf.keras.callbacks.LearningRateScheduler(lrfn, verbose = True)
 rng = [i for i in range(30)]
y = [lrfn(x)for x in rng]
plt.plot(rng, y )<choose_model_class>
combined['TotalSqrFt'] =(combined['BsmtFinSF1'] + combined['BsmtFinSF2']
+ combined['1stFlrSF'] + combined['2ndFlrSF'])
 combined['TotalSF'] =(combined['TotalBsmtSF'] + combined['1stFlrSF'] + combined['2ndFlrSF'])
 combined['TotalPorchSF'] =(combined['WoodDeckSF'] + combined['OpenPorchSF']
+ combined['EnclosedPorch'] + combined['3SsnPorch']
+ combined['ScreenPorch'])
 combined['TotalBath'] =(combined['FullBath']
+(0.5 * combined['HalfBath'])
 + combined['BsmtFullBath']
+(0.5 * combined['BsmtHalfBath']))
early_stop = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=20, restore_best_weights = True )<install_modules>
combined.drop(['Street', 'Utilities'], axis=1, inplace=True )
!pip install -q efficientnet<choose_model_class>
combined_encoded = pd.get_dummies(combined ).reset_index(drop=True )
with strategy.scope() :
pretrained_model = efficientnet.EfficientNetB7(
 weights = 'noisy-student',
include_top = False,
input_shape = [*IMAGE_SIZE, 3] 
)
 pretrained_model.trainable = True
model = tf.keras.Sequential([
pretrained_model,
tf.keras.layers.GlobalAveragePooling2D() ,
tf.keras.layers.Dense(len(CLASSES),activation = 'softmax')
 ])
 model.compile(
 optimizer = 'adam',
loss = 'sparse_categorical_crossentropy',
metrics = ['sparse_categorical_accuracy'], 
)
 model.summary()<train_model>
combined_encoded = combined_encoded.loc[:,~combined_encoded.columns.duplicated() ]
BATCH_SIZE = 16*strategy.num_replicas_in_sync
EPOCHS = 11
STEPS_PER_EPOCH = NUM_TRAINING_IMAGES//BATCH_SIZE
history = model.fit(
 ds_train,
validation_data = ds_val,
epochs = EPOCHS,
steps_per_epoch = STEPS_PER_EPOCH,
callbacks = [lr_callback, early_stop] 
)
<predict_on_test>
y_test, X_test =(combined_encoded[len(train):]["SalePrice"],
combined_encoded.drop(["SalePrice"], axis=1)[len(train):] )
cmdataset = get_validation_dataset(ordered = True)
 images_ds = cmdataset.map(lambda image,label:image)
 labels_ds = cmdataset.map(lambda image,label:label ).unbatch()
cm_correct_labels = next(iter(labels_ds.batch(NUM_VALIDATION_IMAGES)) ).numpy()
cm_probabilites = model.predict(images_ds)
 cm_predictions = np.argmax(cm_probabilites, axis = -1)
 labels = range(len(CLASSES))
cmat = confusion_matrix(
 cm_correct_labels,
cm_predictions,
labels = labels, 
)
 cmat =(cmat.T/cmat.sum(axis=1)).T<compute_train_metric>
y_train_full, X_train_full =(combined_encoded[:len(train)]["SalePrice"],
combined_encoded.drop(["SalePrice"], axis=1)[:len(train)] )
score = f1_score(
 cm_correct_labels,
cm_predictions,
labels = labels,
average= 'macro', 
)
 precision = precision_score(
 	cm_correct_labels,
cm_predictions,
labels = labels,
average = 'macro', 
)
 recall = recall_score(
 	cm_correct_labels,
cm_predictions,
labels = labels,
average = 'macro', 
)
 display_confusion_matrix(cmat,score,precision,recall )<define_variables>
X_train, X_valid, y_train, y_valid = train_test_split(
 X_train_full, y_train_full, test_size=0.20, random_state=42 )
dataset = get_validation_dataset()
dataset = dataset.unbatch().batch(20)
 batch = iter(dataset)
<predict_on_test>
from sklearn.ensemble import RandomForestRegressor
from xgboost import XGBRegressor
from lightgbm import LGBMRegressor
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.svm import SVR
from sklearn.linear_model import RidgeCV, LassoCV, ElasticNetCV
from mlxtend.regressor import StackingCVRegressor
from sklearn.model_selection import KFold, cross_val_score
from sklearn.pipeline import make_pipeline
from sklearn.metrics import mean_squared_error
import hyperopt
from hyperopt import hp
from hyperopt import fmin, tpe, hp, anneal, Trials
from sklearn.preprocessing import RobustScaler
images,labels = next(batch)
 probabilites = model.predict(images)
 predictions = np.argmax(probabilites, axis = -1)
 display_batch_of_images(( images,labels), predictions )<predict_on_test>
def rmsle(y, y_pred):
return np.sqrt(mean_squared_error(y, y_pred))
test_ds = get_test_dataset(ordered = True)
 print("Computing predictions for test set")
 test_images_ds = test_ds.map(lambda image,idnum: image)
 probabilities = model.predict(test_images_ds)
 predictions = np.argmax(probabilities, axis = -1)
 print(predictions)
<save_to_csv>
kfolds = KFold(n_splits=10, random_state=42, shuffle=True)
 def cv_rmse(model, X=X_train_full):
rmse = np.sqrt(-cross_val_score(model, X, y_train_full,
scoring='neg_mean_squared_error', cv=kfolds))
return(rmse )
print('Generating submision file')
 test_ids_ds = test_ds.map(lambda image,idnum: idnum ).unbatch()
test_ids = next(iter(test_ids_ds.batch(NUM_TEST_IMAGES)) ).numpy().astype('U')
 np.savetxt(
 "submission.csv",
np.rec.fromarrays([test_ids, predictions]),
fmt = ['%s', '%d'],
delimiter = ',',
header = 'id,label',
comments = '', 
)
 !head submission.csv<import_modules>
def mse_cv(params, cv=kfolds, X=X_train_full, y=y_train_full):
params = {'max_depth': int(params['max_depth']),
'learning_rate': params['learning_rate'],
'gamma': params['gamma'],
'colsample_bytree': params['colsample_bytree'],
'subsample': params['subsample']
}
model = XGBRegressor(objective='reg:linear', n_estimators=200,
random_state=42,
**params)
 score = np.sqrt(-cross_val_score(model, X, y, cv=cv, scoring="neg_mean_squared_error", n_jobs=-1 ).mean())
 return score
!pip install efficientnet
print("Tensorflow version " + tf.__version__)
<set_options>
space={'max_depth' : hp.quniform('max_depth', 2, 10, 1),
'learning_rate': hp.loguniform('learning_rate', -5, 0),
'gamma': hp.loguniform('gamma', -1, 0),
'colsample_bytree': hp.loguniform('colsample_bytree', -1, 0),
'subsample': hp.loguniform('subsample', -1, 0)
 }
trials = Trials()
best=fmin(fn=mse_cv,
space=space,
algo=tpe.suggest,
max_evals=200,
trials=trials,
rstate=np.random.RandomState(42)
 )
AUTO = tf.data.experimental.AUTOTUNE
AUTO<choose_model_class>
xgb_reg = XGBRegressor(random_state=42, n_estimators=5000,
max_depth=int(best['max_depth']),learning_rate=best['learning_rate'],
gamma=best['gamma'], colsample_bytree=best['colsample_bytree'],
subsample=best['subsample'], objective='reg:linear',
nthread=-1, scale_pos_weight=1)
 print(np.mean(cv_rmse(xgb_reg)))
 print("Best MSE {:.3f} params {}".format(mse_cv(best), best))
tpu = tf.distribute.cluster_resolver.TPUClusterResolver()
tf.config.experimental_connect_to_cluster(tpu)
 tf.tpu.experimental.initialize_tpu_system(tpu)
 strategy = tf.distribute.experimental.TPUStrategy(tpu)
<define_variables>
xgb_reg = XGBRegressor(random_state=42,
n_estimators=7000,
max_depth=2,
learning_rate=0.138170657,
gamma=0.38498075,
colsample_bytree=0.599437614,
objective='reg:linear',
nthread=-1,
scale_pos_weight=1,
subsample=0.534382267 )
IMAGE_SIZE = [512, 512]
EPOCHS = 30
BATCH_SIZE = 32 * strategy.num_replicas_in_sync
LEARNING_RATE = 1e-3
TTA_NUM = 5 
<define_variables>
lgbm_reg = LGBMRegressor(random_state=42,
n_estimators=7000,
num_leaves=3,
learning_rate=0.099384860,
bagging_seed=5,
feature_fraction_seed=5,
bagging_fraction=0.407679661,
feature_fraction=0.563479974,
min_sum_hessian_in_leaf=20 )
GCS_DS_PATH = KaggleDatasets().get_gcs_path('tpu-getting-started' )<define_variables>
svr_reg = make_pipeline(RobustScaler() , SVR(C=11,
gamma=0.006742321288,
epsilon=0.010861719298))
GCS_PATH_SELECT = {
192: GCS_DS_PATH + '/tfrecords-jpeg-192x192',
224: GCS_DS_PATH + '/tfrecords-jpeg-224x224',
331: GCS_DS_PATH + '/tfrecords-jpeg-331x331',
512: GCS_DS_PATH + '/tfrecords-jpeg-512x512'
}
GCS_PATH = GCS_PATH_SELECT[IMAGE_SIZE[0]]
TRAINING_FILENAMES = tf.io.gfile.glob(GCS_PATH + '/train/*.tfrec')
 VALIDATION_FILENAMES = tf.io.gfile.glob(GCS_PATH + '/val/*.tfrec')
 TEST_FILENAMES = tf.io.gfile.glob(GCS_PATH + '/test/*.tfrec' )<define_variables>
gb_reg = GradientBoostingRegressor(max_depth=21,
min_samples_leaf=11,
min_samples_split=8,
learning_rate=0.038954801112873964,
loss='huber', max_features='sqrt',
n_estimators=7000, random_state=42 )
SKIP_VALIDATION = True
if SKIP_VALIDATION:
TRAINING_FILENAMES = TRAINING_FILENAMES + VALIDATION_FILENAMES 
<define_variables>
ridge_alphas = [1e-10, 1e-8, 1e-5, 9e-4, 7e-4, 5e-4, 3e-4, 1e-4, 1e-3, 5e-2, 1e-2,
0.1, 0.3, 1, 3, 5, 10, 15, 18, 20, 30, 50, 75, 100]
lasso_alphas = [5e-5, 0.0001, 0.0002, 0.0003, 0.0004, 0.0005, 0.0006, 0.0007, 0.0008]
elastic_alphas = [0.0001, 0.0002, 0.0003, 0.0004, 0.0005, 0.0006, 0.0007, 0.0008, 0.0009, 0.001]
elastic_l1ratio = [0.5, 0.6, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.97, 0.99, 1]
CLASSES = ['pink primrose', 'hard-leaved pocket orchid', 'canterbury bells', 'sweet pea', 'wild geranium', 'tiger lily', 'moon orchid', 'bird of paradise', 'monkshood', 'globe thistle',
'snapdragon', "colt's foot", 'king protea', 'spear thistle', 'yellow iris', 'globe-flower', 'purple coneflower', 'peruvian lily', 'balloon flower', 'giant white arum lily',
'fire lily', 'pincushion flower', 'fritillary', 'red ginger', 'grape hyacinth', 'corn poppy', 'prince of wales feathers', 'stemless gentian', 'artichoke', 'sweet william',
'carnation', 'garden phlox', 'love in the mist', 'cosmos', 'alpine sea holly', 'ruby-lipped cattleya', 'cape flower', 'great masterwort', 'siam tulip', 'lenten rose',
'barberton daisy', 'daffodil', 'sword lily', 'poinsettia', 'bolero deep blue', 'wallflower', 'marigold', 'buttercup', 'daisy', 'common dandelion',
'petunia', 'wild pansy', 'primula', 'sunflower', 'lilac hibiscus', 'bishop of llandaff', 'gaura', 'geranium', 'orange dahlia', 'pink-yellow dahlia',
'cautleya spicata', 'japanese anemone', 'black-eyed susan', 'silverbush', 'californian poppy', 'osteospermum', 'spring crocus', 'iris', 'windflower', 'tree poppy',
'gazania', 'azalea', 'water lily', 'rose', 'thorn apple', 'morning glory', 'passion flower', 'lotus', 'toad lily', 'anthurium',
'frangipani', 'clematis', 'hibiscus', 'columbine', 'desert-rose', 'tree mallow', 'magnolia', 'cyclamen ', 'watercress', 'canna lily',
'hippeastrum ', 'bee balm', 'pink quill', 'foxglove', 'bougainvillea', 'camellia', 'mallow', 'mexican petunia', 'bromelia', 'blanket flower',
'trumpet creeper', 'blackberry lily', 'common tulip', 'wild rose']
print(f"No of Flower classes in dataset: {len(CLASSES)}" )<choose_model_class>
ridge_reg = make_pipeline(RobustScaler() , RidgeCV(alphas=ridge_alphas, cv=kfolds))
lasso_reg = make_pipeline(RobustScaler() , LassoCV(max_iter=1e7, alphas=lasso_alphas,
random_state=42, cv=kfolds))
elasticnet_reg = make_pipeline(RobustScaler() , ElasticNetCV(max_iter=1e7,
alphas=elastic_alphas,
cv=kfolds,
l1_ratio=elastic_l1ratio))
LR_START = 0.00001
LR_MAX = 0.00005 * strategy.num_replicas_in_sync
LR_MIN = 0.00001
LR_RAMPUP_EPOCHS = 5
LR_SUSTAIN_EPOCHS = 0
LR_EXP_DECAY =.7
def lrfn(epoch):
if epoch < LR_RAMPUP_EPOCHS:
lr =(LR_MAX - LR_START)/ LR_RAMPUP_EPOCHS * epoch + LR_START
elif epoch < LR_RAMPUP_EPOCHS + LR_SUSTAIN_EPOCHS:
lr = LR_MAX
else:
lr =(LR_MAX - LR_MIN)* LR_EXP_DECAY**(epoch - LR_RAMPUP_EPOCHS - LR_SUSTAIN_EPOCHS)+ LR_MIN
return lr
lr_callback = tf.keras.callbacks.LearningRateScheduler(lrfn, verbose=True)
 rng = [i for i in range(EPOCHS)]
y = [lrfn(x)for x in rng]
plt.plot(rng, y)
 print("Learning rate schedule: {:.3g} to {:.3g} to {:.3g}".format(y[0], max(y), y[-1]))<categorify>
stack_gen = StackingCVRegressor(regressors=(ridge_reg, lasso_reg, elasticnet_reg, xgb_reg, lgbm_reg, gb_reg, svr_reg),
meta_regressor=xgb_reg,
use_features_in_secondary=True )
def decode_image(image_data):
image = tf.image.decode_jpeg(image_data, channels=3)
 image = tf.cast(image, tf.float32)/ 255.0
image = tf.reshape(image, [*IMAGE_SIZE, 3])
 return image
def read_labeled_tfrecord(example):
LABELED_TFREC_FORMAT = {
"image": tf.io.FixedLenFeature([], tf.string),
"class": tf.io.FixedLenFeature([], tf.int64),
}
example = tf.io.parse_single_example(example, LABELED_TFREC_FORMAT)
 image = decode_image(example['image'])
 label = tf.cast(example['class'], tf.int32)
 return image, label
def read_unlabeled_tfrecord(example):
UNLABELED_TFREC_FORMAT = {
"image": tf.io.FixedLenFeature([], tf.string),
"id": tf.io.FixedLenFeature([], tf.string),
}
example = tf.io.parse_single_example(example, UNLABELED_TFREC_FORMAT)
 image = decode_image(example['image'])
 idnum = example['id']
return image, idnum
def data_augment(image, label, seed=2020):
image = tf.image.random_flip_left_right(image, seed=seed)
 return image, label
def get_training_dataset() :
dataset = load_dataset(TRAINING_FILENAMES, labeled=True)
 dataset = dataset.map(data_augment, num_parallel_calls=AUTO)
 dataset = dataset.repeat()
dataset = dataset.shuffle(2048)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.prefetch(AUTO)
 return dataset
def get_validation_dataset(ordered=False):
dataset = load_dataset(VALIDATION_FILENAMES, labeled=True, ordered=ordered)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.cache()
dataset = dataset.prefetch(AUTO)
 return dataset
def get_train_valid_datasets() :
dataset = load_dataset(TRAINING_FILENAMES + VALIDATION_FILENAMES, labeled=True)
 dataset = dataset.map(data_augment, num_parallel_calls=AUTO)
 dataset = dataset.repeat()
dataset = dataset.shuffle(2048)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.prefetch(AUTO)
 return dataset
def get_test_dataset(ordered=False):
dataset = load_dataset(TEST_FILENAMES, labeled=False, ordered=ordered)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.prefetch(AUTO)
 return dataset
def count_data_items(filenames):
n = [int(re.compile(r"-([0-9]*)\." ).search(filename ).group(1)) for filename in filenames]
return np.sum(n )<define_variables>
scores = {}
score = cv_rmse(lgbm_reg)
 print("lgbm_reg: {:.4f}({:.4f})".format(score.mean() , score.std()))
scores['lgbm'] =(score.mean() , score.std())
 score = cv_rmse(xgb_reg)
 print("xgb_reg: {:.4f}({:.4f})".format(score.mean() , score.std()))
scores['xgb'] =(score.mean() , score.std())
 score = cv_rmse(svr_reg)
 print("SVR: {:.4f}({:.4f})".format(score.mean() , score.std()))
scores['svr'] =(score.mean() , score.std())
 score = cv_rmse(ridge_reg)
 print("ridge_reg: {:.4f}({:.4f})".format(score.mean() , score.std()))
scores['ridge'] =(score.mean() , score.std())
 score = cv_rmse(lasso_reg)
 print("lasso_reg: {:.4f}({:.4f})".format(score.mean() , score.std()))
scores['lasso'] =(score.mean() , score.std())
 score = cv_rmse(elasticnet_reg)
 print("elasticnet_reg: {:.4f}({:.4f})".format(score.mean() , score.std()))
scores['elasticnet'] =(score.mean() , score.std())
 score = cv_rmse(gb_reg)
 print("gb_reg: {:.4f}({:.4f})".format(score.mean() , score.std()))
scores['gb'] =(score.mean() , score.std() )
models = []
histories = [] 
<define_variables>
%%time
print('START Fit')
 print('stack_gen')
 stack_gen_model = stack_gen.fit(np.array(X_train_full), np.array(y_train_full))
print('elasticnet')
 elastic_reg_model = elasticnet_reg.fit(X_train_full, y_train_full)
 print('Lasso')
 lasso_reg_model = lasso_reg.fit(X_train_full, y_train_full)
 print('Ridge')
 ridge_reg_model = ridge_reg.fit(X_train_full, y_train_full)
 print('Svr')
 svr_reg_model = svr_reg.fit(X_train_full, y_train_full)
 print('GradientBoosting')
 gb_reg_model = gb_reg.fit(X_train_full, y_train_full)
 print('xgboost')
 xgb_reg_model = xgb_reg.fit(X_train_full, y_train_full)
 print('lightgbm')
 lgbm_reg_model = lgbm_reg.fit(X_train_full, y_train_full)
 print('END FIT' )
NUM_TRAINING_IMAGES = count_data_items(TRAINING_FILENAMES)
 NUM_VALIDATION_IMAGES = count_data_items(VALIDATION_FILENAMES)
 NUM_TEST_IMAGES = count_data_items(TEST_FILENAMES)
 STEPS_PER_EPOCH =(NUM_TRAINING_IMAGES + NUM_VALIDATION_IMAGES)// BATCH_SIZE
print('Dataset: {} training images, {} unlabeled test images'.format(NUM_TRAINING_IMAGES+NUM_VALIDATION_IMAGES, NUM_TEST_IMAGES))<create_dataframe>
def blender(X):
return(( 0.1 * elastic_reg_model.predict(X)) + \ 
(0.1 * lasso_reg_model.predict(X)) + \ 
(0.1 * ridge_reg_model.predict(X)) + \ 
(0.1 * svr_reg_model.predict(X)) + \ 
(0.1 * gb_reg_model.predict(X)) + \ 
(0.1 * xgb_reg_model.predict(X)) + \ 
(0.1 * lgbm_reg_model.predict(X)) + \ 
(0.3 * stack_gen_model.predict(np.array(X))))
def load_dataset(filenames, labeled=True, ordered=False):
ignore_order = tf.data.Options()
if not ordered:
ignore_order.experimental_deterministic = False
dataset = tf.data.TFRecordDataset(filenames, num_parallel_reads=AUTO)
 dataset = dataset.with_options(ignore_order)
 dataset = dataset.map(read_labeled_tfrecord if labeled else read_unlabeled_tfrecord, num_parallel_calls=AUTO)
 return dataset
def get_training_dataset_preview(ordered=True):
dataset = load_dataset(TRAINING_FILENAMES, labeled=True, ordered=ordered)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.cache()
dataset = dataset.prefetch(AUTO)
 return dataset
np.set_printoptions(threshold=15, linewidth=80)
 def batch_to_numpy_images_and_labels(data):
images, labels = data
numpy_images = images.numpy()
numpy_labels = labels.numpy()
if numpy_labels.dtype == object:
numpy_labels = [None for _ in enumerate(numpy_images)]
return numpy_images, numpy_labels
def title_from_label_and_target(label, correct_label):
if correct_label is None:
return CLASSES[label], True
correct =(label == correct_label)
 return "{} [{}{}{}]".format(CLASSES[label], 'OK' if correct else 'NO', u"\u2192" if not correct else '',
CLASSES[correct_label] if not correct else ''), correct
def dataset_to_numpy_util(dataset, N):
dataset = dataset.unbatch().batch(N)
 for images, labels in dataset:
numpy_images = images.numpy()
numpy_labels = labels.numpy()
break;
return numpy_images, numpy_labels<prepare_x_and_y>
print('RMSLE score on train data:')
 print(rmsle(y_train_full, blender(X_train_full)) )
train_dataset = get_training_dataset_preview(ordered=True)
 y_train = next(iter(train_dataset.unbatch().map(lambda image, label: label ).batch(NUM_TRAINING_IMAGES)) ).numpy()
print('Number of training images %d' % NUM_TRAINING_IMAGES)
<define_variables>
print('Predict submission')
 submission = pd.read_csv(".. /input/house-prices-advanced-regression-techniques/sample_submission.csv")
 submission.iloc[:,1] = np.floor(np.expm1(blender(X_test)) )
display_batch_of_images(next(iter(train_dataset.unbatch().batch(20))))<define_variables>
submission.to_csv("submission.csv", index=False )
test_dataset = get_test_dataset()
test_dataset = test_dataset.unbatch().batch(20)
 test_batch = iter(test_dataset)
<choose_model_class>
submission.to_csv("submission.csv", index=False )