text_plain_output_1.png
from sklearn.compose import make_column_transformer

from sklearn.impute import SimpleImputer

from sklearn.model_selection import train_test_split

from sklearn.model_selection import train_test_split

from sklearn.pipeline import make_pipeline, Pipeline

from sklearn.preprocessing import OneHotEncoder

from sklearn.preprocessing import PowerTransformer, StandardScaler,Normalizer,RobustScaler,MaxAbsScaler,MinMaxScaler,QuantileTransformer

from tensorflow.keras import layers

from tensorflow.keras.callbacks import EarlyStopping

from tensorflow.keras.callbacks import LearningRateScheduler

import  tensorflow as tf

import pandas as pd #To work with dataset

train = pd.read_csv('../input/30-days-of-ml/train.csv')
test = pd.read_csv('../input/30-days-of-ml/test.csv')

cat_columns = train.drop(['id', 'target'], axis=1).select_dtypes(exclude=['int64', 'float64']).columns
num_columns = train.drop(['id', 'target'], axis=1).select_dtypes(include=['int64', 'float64']).columns
train[train.select_dtypes(['float64']).columns] = train[train.select_dtypes(['float64']).columns].apply(pd.to_numeric)
train[train.select_dtypes(['object']).columns] = train.select_dtypes(['object']).apply(lambda x: x.astype('category'))

num_columns = ['cont0', 'cont1', 'cont2', 'cont3', 'cont4', 'cont5', 'cont6', 'cont7', 'cont8', 'cont9', 'cont10', 'cont11', 'cont12', 'cont13']
cat_columns = ['cat0', 'cat1', 'cat2', 'cat3', 'cat4', 'cat5', 'cat6', 'cat7', 'cat8', 'cat9']
all_columns = num_columns + cat_columns

Robustscaler = make_pipeline(SimpleImputer(strategy='median', add_indicator=True), RobustScaler())
OneHotencoder = make_pipeline(SimpleImputer(strategy='most_frequent', add_indicator=True), OneHotEncoder())
OneHot_RobustScaler = make_column_transformer((OneHotencoder, cat_columns), (Robustscaler, num_columns))

y = train['target']
X = train.drop(['id', 'target'], axis=1)
OneHot_RobustScaler.fit(X)
Xpre = OneHot_RobustScaler.transform(X)
test_final = test.drop(['id'], axis=1)
test_finalpre = OneHot_RobustScaler.transform(test_final)

X_train, X_test, y_train, y_test = train_test_split(Xpre, y, test_size=0.1)

def lr_schedul(epoch):
    x = 0.01
    if epoch >= 5:
        x = 0.005
    if epoch >= 10:
        x = 0.001
    if epoch >= 15:
        x = 0.0008
    if epoch >= 20:
        x = 0.0005
    if epoch >= 30:
        x = 0.0001
    if epoch >= 60:
        x = 1e-05
    return x
lr_decay = LearningRateScheduler(lr_schedul, verbose=1)

from pandas import read_csv
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense
n_features = X_train.shape[1]
model = tf.keras.Sequential()
model.add(layers.Dense(20, kernel_initializer='he_normal', input_shape=(n_features,), activation='relu'))
model.add(layers.Dense(10, activation='relu'))
model.add(layers.Dense(1, activation='linear'))
optimizer = tf.keras.optimizers.Adam(learning_rate=2e-05)
model.compile(loss='mean_squared_error', optimizer=optimizer, metrics=[tf.keras.metrics.RootMeanSquaredError(name='rmse')])
model.summary()

EPOCHS = 1000
es = EarlyStopping(monitor='val_loss', min_delta=1e-13, restore_best_weights=True, patience=10)
with tf.device('/gpu:0'):
    history = model.fit(Xpre, y, batch_size=256, epochs=EPOCHS, validation_split=0.1, verbose=0, callbacks=[lr_decay, es], shuffle=True)