Kaggle competition: House Prices - Advanced Regression Techniques
test_ds = get_test_dataset(ordered=True)
 print('Computing predictions...')
 test_images_ds = test_ds.map(lambda image, idnum: image)
 probabilities = model.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='' )<set_options>
%matplotlib inline
warnings.filterwarnings('ignore' )
!pip install efficientnet --quiet
sns.set()<define_variables>
train = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/train.csv')
 test = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/test.csv' )
flower_categories = [
'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('Number of flower categories:', len(flower_categories)) 
<define_variables>
train['train'] = 1
test['train'] = 0
df = pd.concat([train, test], axis=0,sort=False )
image_size =(224,224)
 data_gcs = KaggleDatasets().get_gcs_path('tpu-getting-started')
 ext_gcs = KaggleDatasets().get_gcs_path('tf-flower-photo-tfrec')
 data_dir_by_size = { 
(512, 512): '/tfrecords-jpeg-512x512', 
(331, 331): '/tfrecords-jpeg-331x331', 
(224, 224): '/tfrecords-jpeg-224x224', 
(192, 192): '/tfrecords-jpeg-192x192'
}
subdir = data_dir_by_size[image_size]
train_file_names = tf.io.gfile.glob(data_gcs + subdir+ '/train'+ '/*tfrec')
 val_file_names = tf.io.gfile.glob(data_gcs + subdir + '/val' + '/*tfrec')
 test_file_names = tf.io.gfile.glob(data_gcs + subdir + '/test' + '/*tfrec')
 imagenet_files = tf.io.gfile.glob(ext_gcs + '/imagenet' + subdir + '/*.tfrec')
 inaturelist_files = tf.io.gfile.glob(ext_gcs + '/inaturalist' + subdir + '/*.tfrec')
 openimage_files = tf.io.gfile.glob(ext_gcs + '/openimage' + subdir + '/*.tfrec')
 oxford_files = tf.io.gfile.glob(ext_gcs + '/oxford_102' + subdir + '/*.tfrec')
 tensorflow_files = tf.io.gfile.glob(ext_gcs + '/tf_flowers' + subdir + '/*.tfrec')
 train_file_names = train_file_names + imagenet_files + inaturelist_files + \
openimage_files + oxford_files + tensorflow_files<categorify>
df.isnull().values.any()
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):

 example = tf.io.parse_single_example(
 serialized = example,
features = {
'image' : tf.io.FixedLenFeature([], tf.string),
'class' : tf.io.FixedLenFeature([], tf.int64)
 } 
)
 image = decode_image(example['image'])
 label = tf.cast(example['class'], tf.int32)
 return image, label
def read_unlabeled_tfrecord(example):

 example = tf.io.parse_single_example(
 serialized=example,
features={
'image': tf.io.FixedLenFeature([], tf.string),
'id': tf.io.FixedLenFeature([], tf.string),
} 
)
 image = decode_image(example['image'])
 idnum = example['id']
return image, idnum
def load_dataset(filenames, labeled = True, ordered= False):

 ignore_order = tf.data.Options()
ignore_order.experimental_deterministic = ordered
dataset = tf.data.TFRecordDataset(
 filenames, num_parallel_reads = tf.data.experimental.AUTOTUNE)
 dataset = dataset.with_options(ignore_order)
 dataset = dataset.map(
 read_labeled_tfrecord if labeled else read_unlabeled_tfrecord,
num_parallel_calls=tf.data.experimental.AUTOTUNE)
 return dataset
def count_data_items(filenames):

 return np.sum([
int(re.compile(r"-([0-9]*)\." ).search(filename ).group(1))
for filename in filenames])
 train_dataset = load_dataset(train_file_names, labeled=True, ordered=False)
 val_dataset = load_dataset(val_file_names, labeled=True, ordered=False)
 test_dataset = load_dataset(test_file_names, labeled=False, ordered=True)
 num_training_samples = count_data_items(train_file_names)
 num_validation_samples = count_data_items(val_file_names)
 num_testing_samples = count_data_items(test_file_names)
<train_model>
df_train_target = df[df['train'] == 1]['SalePrice']
df = df.drop(['SalePrice'],axis=1 )
print('Train samples:', num_training_samples, end=', ')
 print('Val samples:', num_validation_samples, end=', ')
 print('Test samples:', num_testing_samples )<normalization>
print("Numerical features : " + str(len(numerical_features)))
 print("Categorical features : " + str(len(categorical_features)))
 df_numerical = df[numerical_features]
df_category = df[categorical_features]
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))<categorify>
print("Number of NAs for numerical features in data: " + str(df_numerical.isnull().values.sum()))
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<define_variables>
df_category = pd.get_dummies(df_category)
 print("train category",df_category.shape)
 print("train numerical",df_numerical.shape)
batch_size = 16 * strategy.num_replicas_in_sync
epochs = 25
batched_train_dataset = train_dataset.map(transform)
 batched_train_dataset = batched_train_dataset.repeat()
batched_train_dataset = batched_train_dataset.shuffle(buffer_size = 2048)
 batched_train_dataset = batched_train_dataset.batch(batch_size)
 batched_train_dataset = batched_train_dataset.prefetch(tf.data.experimental.AUTOTUNE)
 batched_val_dataset = val_dataset.batch(batch_size)
 batched_val_dataset = batched_val_dataset.cache()
batched_val_dataset = batched_val_dataset.prefetch(tf.data.experimental.AUTOTUNE)
 batched_test_dataset = test_dataset.batch(batch_size)
 batched_test_dataset = batched_test_dataset.prefetch(tf.data.experimental.AUTOTUNE)
 early_stopping = tf.keras.callbacks.EarlyStopping(monitor ='val_loss', patience= 3)
 save_checkpoints = tf.keras.callbacks.ModelCheckpoint('/kaggle/working/weights.{epoch:02d}-{val_loss:.2f}.hdf5',
save_freq='epoch', period=4)
 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_DECAY =.8
def lr_schedule(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_DECAY**(epoch - LR_RAMPUP_EPOCHS - LR_SUSTAIN_EPOCHS)+ LR_MIN
return lr
lr_callback = tf.keras.callbacks.LearningRateScheduler(lr_schedule, verbose = True )<choose_model_class>
df_new = pd.concat([df_category,df_numerical],axis=1)
 df_new.shape
def get_model() :
with strategy.scope() :
feature_extractor = efficientnet.EfficientNetB7(
 weights = 'noisy-student', include_top = False, input_shape=[*image_size, 3])
 feature_extractor.trainable = True
model = tf.keras.Sequential([
feature_extractor,
tf.keras.layers.GlobalAveragePooling2D() ,
tf.keras.layers.Dense(len(flower_categories), activation='softmax', dtype='float32')
 ])
 model.compile(optimizer='adam',
loss = 'sparse_categorical_crossentropy',
metrics=['sparse_categorical_accuracy'] 
)
 return model<train_model>
df_train = df_new[df_new['train'] == 1]
df_train = df_train.drop(['train',],axis=1)
 df_test = df_new[df_new['train'] == 0]
df_test = df_test.drop(['train',],axis=1 )
history = model.fit(
 batched_train_dataset,
steps_per_epoch=num_training_samples // batch_size,
epochs=epochs,
callbacks=[lr_callback, early_stopping, save_checkpoints],
validation_data=batched_val_dataset,
verbose=2 )<predict_on_test>
y = df_train_target
print("Creating submission")
 test_image_dataset = batched_test_dataset.map(lambda image,idnum: image)
 predictions = np.argmax(model.predict(test_image_dataset), axis = -1)
 test_ids_dataset = batched_test_dataset.map(lambda image, idnum: idnum ).unbatch()
test_ids = next(iter(test_ids_dataset.batch(num_testing_samples)) ).numpy().astype('U')
 np.savetxt('submission.csv', np.rec.fromarrays([test_ids, predictions]), fmt=['%s', '%d'], delimiter=',', header='id,label', comments='')
 print('Done!' )<install_modules>
X_train,X_test,y_train,y_test = train_test_split(df_train,y,test_size = 0.3,random_state= 0 )
!pip install -U git+https://github.com/qubvel/efficientnet >> /dev/null<set_options>
xgb =XGBRegressor(booster='gbtree',colsample_bytree=0.5, learning_rate=0.01, max_delta_step=0,
max_depth=4, min_child_weight=1, n_estimators=1000,
n_jobs=1, nthread=None, objective='reg:linear',
reg_alpha=0.5, reg_lambda=0.5, scale_pos_weight=1,
silent=None, subsample=0.7, verbosity=1)
AUTO = tf.data.experimental.AUTOTUNE<find_best_params>
xgb.fit(X_train, y_train )
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 )<set_options>
predict = xgb.predict(X_test )
MIXED_PRECISION = True
XLA_ACCELERATE = True
if MIXED_PRECISION:
if tpu: policy = tf.keras.mixed_precision.experimental.Policy('mixed_bfloat16')
 else: policy = tf.keras.mixed_precision.experimental.Policy('mixed_float16')
 mixed_precision.set_policy(policy)
 print('Mixed precision enabled')
 if XLA_ACCELERATE:
tf.config.optimizer.set_jit(True)
 print('Accelerated Linear Algebra enabled' )<define_variables>
print('Root Mean Square Error test = ' + str(math.sqrt(metrics.mean_squared_error(y_test, predict))))
IMAGE_SIZES = [[512, 512], [331, 331], [224, 224], [192, 192]]
IMAGE_SIZE = IMAGE_SIZES[2]
BATCH_SIZE = 32 * strategy.num_replicas_in_sync
print('Using IMAGE_SIZE', IMAGE_SIZE, 'and BATCH_SIZE', BATCH_SIZE )<define_variables>
xgb.fit(df_train, df_train_target )
use_external = True
BASE_PATH = KaggleDatasets().get_gcs_path('tpu-getting-started')
 EXT_PATH = KaggleDatasets().get_gcs_path('tf-flower-photo-tfrec')
 def get_path(image_size=IMAGE_SIZE):
return f'{BASE_PATH}/tfrecords-jpeg-{image_size[0]}x{image_size[1]}'
def get_ext_path(folder, image_size=IMAGE_SIZE):
return f'{EXT_PATH}/{folder}/tfrecords-jpeg-{image_size[0]}x{image_size[1]}'
TRAINING_FILES = tf.io.gfile.glob(get_path() + '/train/*.tfrec')
 VALIDATION_FILES = tf.io.gfile.glob(get_path() + '/val/*.tfrec')
 TEST_FILES = tf.io.gfile.glob(get_path() + '/test/*.tfrec')
 if use_external:
INATURALIST = tf.io.gfile.glob(get_ext_path('inaturalist_no_test')+ '/*.tfrec')
 TRAINING_FILES += INATURALIST
OXFORD = tf.io.gfile.glob(get_ext_path('oxford_102_no_test')+ '/*.tfrec')
 TRAINING_FILES += OXFORD
TFFLOWERS = tf.io.gfile.glob(get_ext_path('tf_flowers_no_test')+ '/*.tfrec')
 TRAINING_FILES += TFFLOWERS
print('Loaded Training:', len(TRAINING_FILES), 'files, Validation:', len(VALIDATION_FILES), 'files, Test:', len(TEST_FILES), 'files' )<define_variables>
predict2 = xgb.predict(df_test)
 predict_y =(predict2 )
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(len(CLASSES))<create_dataframe>
lr = LinearRegression()
lr.fit(X_train,y_train)
 y_pred = lr.predict(X_test)
class DS() :
def __init__(self, files, training=True, shuffle=False, augment=False, batch_size=16, repeat=False):
self.files = files
self.augment = augment
self.ds = tf.data.TFRecordDataset(files, num_parallel_reads = AUTO)
 self.ds = self.ds.map(self.read_with_label if training else self.read_without_label)
 if self.augment:
self.ds = self.ds.map(self.augment_image)
 if shuffle:
options = tf.data.Options()
options.experimental_deterministic = False
self.ds = self.ds.with_options(options)
 self.ds = self.ds.shuffle(2048)
 if repeat:
self.ds = self.ds.repeat()
self.ds = self.ds.batch(batch_size)
 self.ds = self.ds.prefetch(AUTO)
 def data(self):
return self.ds
def read_with_label(self, example):
example = tf.io.parse_single_example(example, {
'image': tf.io.FixedLenFeature([], tf.string),
'class': tf.io.FixedLenFeature([], tf.int64),
})
 return self.decode_image(example['image']), tf.cast(example['class'], tf.int32)
 def read_without_label(self, example):
example = tf.io.parse_single_example(example, {
'image': tf.io.FixedLenFeature([], tf.string),
'id': tf.io.FixedLenFeature([], tf.string),
})
 return self.decode_image(example['image']), example['id']
def decode_image(self, img):
img = tf.io.decode_jpeg(img, channels=3)
 img = tf.cast(img, tf.float32)/ 255.0
return tf.reshape(img, [*IMAGE_SIZE, 3])
 def augment_image(self, img, label):
return Augmentor.process(img, IMAGE_SIZE[0]), label
def count(self):
n = [int(re.compile(r"-([0-9]*)\." ).search(filename ).group(1)) for filename in self.files]
return np.sum(n)
<define_variables>
coeff_df = pd.DataFrame(lr.coef_,df_train.columns,columns=['Coefficient'])
 coeff_df
items = 0
batches = 0
times = {
'batches': list() ,
'items': list() ,
'batch_speed': list() ,
'item_speed': list() ,
}
def loop(items, batches, times):
train_ds = DS(TRAINING_FILES, augment=True, batch_size=128 ).data()
start = time.time()
for element in train_ds:
so_far = time.time() - start
batches += 1
items += len(element[0])
 times['batches'].append(batches)
 times['items'].append(items)
 times['batch_speed'].append(( batches+1)/so_far)
 times['item_speed'].append(( items+1)/so_far)
 print(items, so_far,(items)/so_far)
 print(batches, items, so_far,(batches)/so_far,(items)/so_far)
 gc.collect()
def show_graph(size):
plt.figure(figsize=(12,6))
plt.plot(times['batches'], times['batch_speed'], color='red')
 plt.plot(times['items'], times['item_speed'], color='blue', linestyle='--')
 plt.legend()
plt.title('Batch size' + str(size))
plt.show() 
<train_model>
lr.score(X_test,y_test)
def test_dataset() :
print('Training images')
 show_images(DS(TRAINING_FILES, augment=True, batch_size=128 ).data())
 print('Validation image')
 show_images(DS(VALIDATION_FILES, batch_size=128 ).data())
 print('Testing images')
 show_images(DS(TEST_FILES, training=False, batch_size=128 ).data())
 print('Testing Augmented images')
 show_images(DS(TEST_FILES, training=False, augment=True, batch_size=128 ).data())
 def show_images(ds, rows=3, columns=6):
plt.figure(figsize=(12, 6))
count = 0
for i, examples in enumerate(ds.take(1)) :
images = examples[0]
labels = examples[1]
for j, image in enumerate(images):
if count == rows * columns:
break
plt.subplot(rows, columns, count+1, xticks=[], yticks=[])
 plt.imshow(image)
 if labels[0].dtype == tf.string:
plt.xlabel(labels[j].numpy().decode("utf-8"))
else:
plt.xlabel(CLASSES[labels[j]])
 count += 1
plt.tight_layout()
plt.show()
gc.collect()<choose_model_class>
print('RMSE: {}'.format(np.sqrt(metrics.mean_squared_error(y_test, y_pred))))
EFNS = [
efn.EfficientNetB0,
efn.EfficientNetB1,
efn.EfficientNetB2,
efn.EfficientNetB3,
efn.EfficientNetB4,
efn.EfficientNetB5,
efn.EfficientNetB6,
efn.EfficientNetB7,
]
def create_efficientnet(index, weight='imagenet'):
pretrained_model = EFNS[index](
 weights = weight,
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(1024, activation='relu', kernel_regularizer=tf.keras.regularizers.l2(0.01)) ,
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(len(CLASSES), activation='softmax'),
], name='efn' + str(index))
return model
def create_densenet() :
pretrained_model = tf.keras.applications.DenseNet201(
 weights = 'imagenet',
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(1024, activation='relu', kernel_regularizer=tf.keras.regularizers.l2(0.01)) ,
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(len(CLASSES), activation='softmax'),
], name='densenet')
 return model
def create_cnn() :
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(16, kernel_size=3, strides=2, padding='same', activation='relu', input_shape=[*IMAGE_SIZE, 3]),
tf.keras.layers.GlobalAveragePooling2D() ,
tf.keras.layers.Dense(len(CLASSES), activation='softmax')
 ], name='simple')
 return model<choose_model_class>
submission = pd.DataFrame({
"Id": test["Id"],
"SalePrice": predict_y
})
 submission.to_csv('submission.csv', index=False )