DNN model showed loss nan at the very beginning

My aim is to predict the result of ‘should we make a claim for this user’. I use entityembedding to deal with the categorical feature and apply them into neural network. But it showed nan loss at the very beginning. I dropped a few features that are mixed with blank, str and float. Also I tried to lower the learning rate even to 0 and still show nan for the loss. The following is the code and the data.`import os
import matplotlib.pylab as plt
import pandas as pd

import datetime, warnings, scipy
import pandas as pd
import numpy as np
import seaborn as sns
import keras as ka
from sklearn import metrics, linear_model
from sklearn.model_selection import train_test_split, cross_val_score, cross_val_predict
from sklearn.preprocessing import StandardScaler
from keras import optimizers
from keras.models import Sequential,Model
from keras.models import Model as KerasModel
from keras.layers import Input, Dense, Activation, Reshape
from keras.layers import Concatenate, Dropout
from keras.layers.embeddings import Embedding
from keras.callbacks import ModelCheckpoint
from keras.utils import plot_model

plt.rcParams[“patch.force_edgecolor”] = True
plt.style.use(‘fivethirtyeight’)
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = “last_expr”
pd.options.display.max_columns = 50
warnings.filterwarnings(“ignore”)
%matplotlib inline
data_df = pd.read_csv(‘training_data.csv’)
print(‘DataFrame size:’, data_df.shape)
features = [‘pol_coverage’,‘pol_pay_freq’,‘pol_payd’,‘pol_usage’,‘pol_insee_code’,‘drv_drv2’,‘drv_sex1’,‘vh_fuel’,‘vh_make’,‘vh_model’,‘vh_type’]
target = [‘made_claim’]
#data_df=data_df[features + target]
#data_df[‘pol_insee_code’]= data_df[‘pol_insee_code’].astype(‘object’)
data_df[‘commune_code’]= data_df[‘commune_code’].astype(‘object’)
data_df[‘canton_code’]= data_df[‘canton_code’].astype(‘object’)
data_df[‘regional_department_code’]= data_df[‘regional_department_code’].astype(‘object’)
data_df = data_df.drop(columns = [‘id_policy’,‘drv_sex2’,‘regional_department_code’,‘commune_code’,‘canton_code’])
X_train, y_train = data_df.iloc[:50000], data_df.iloc[:50000][target]
X_val, y_val = data_df.iloc[50000:75000], data_df.iloc[50000:75000][target]
X_test = data_df.iloc[75000:]
embed_cols=[i for i in X_train.select_dtypes(include=[‘object’])] #挑选类型为obj的列,妙!

for i in embed_cols:
print(i,data_df[i].nunique())
embed_cols=[i for i in X_train.select_dtypes(include=[‘object’])]
print(embed_cols)

#converting data to list format to match the network structure 这个函数将每一列类别特征手动labelencoder了,然后转成了list
def preproc(X_train, X_val, X_test):

input_list_train = []
input_list_val = []
input_list_test = []

#the cols to be embedded: rescaling to range [0, # values)
for c in embed_cols:
    raw_vals = np.unique(X_train[c])
    val_map = {}
    for i in range(len(raw_vals)):
        val_map[raw_vals[i]] = i    #这一步最终把创建了一个,类别特征为键,值为第几个类别特征  

    input_list_train.append(X_train[c].map(val_map).values) 
    input_list_val.append(X_val[c].map(val_map).fillna(0).values)
    input_list_test.append(X_test[c].map(val_map).fillna(0).values)

#the rest of the columns
other_cols = [c for c in X_train.columns if (not c in embed_cols)]
input_list_train.append(X_train[other_cols].values)
input_list_val.append(X_val[other_cols].values)
input_list_test.append(X_test[other_cols].values)

return input_list_train, input_list_val, input_list_test input_models=[]

output_embeddings=
numerics = [‘int16’, ‘int32’, ‘int64’, ‘float16’, ‘float32’, ‘float64’]

for categorical_var in X_train.select_dtypes(include=[‘object’]):

#Name of the categorical variable that will be used in the Keras Embedding layer
cat_emb_name= categorical_var.replace(" ", "")+'_Embedding'

# Define the embedding_size
no_of_unique_cat  = X_train[categorical_var].nunique()
embedding_size = int(min(np.ceil((no_of_unique_cat)/2), 50 ))

#One Embedding Layer for each categorical variable
input_model = Input(shape=(1,))
output_model = Embedding(no_of_unique_cat, embedding_size, name=cat_emb_name)(input_model)
output_model = Reshape(target_shape=(embedding_size,))(output_model)    

#Appending all the categorical inputs
input_models.append(input_model)

#Appending all the embeddings
output_embeddings.append(output_model)

#Other non-categorical data columns (numerical).
#I define single another network for the other columns and add them to our models list.
input_numeric = Input(shape=(len(X_train.select_dtypes(include=numerics).columns.tolist()),))
embedding_numeric = Dense(128)(input_numeric)
input_models.append(input_numeric)
output_embeddings.append(embedding_numeric)

#At the end we concatenate altogther and add other Dense layers
output = Concatenate()(output_embeddings)
output = Dense(1000, kernel_initializer=“uniform”)(output)
output = Activation(‘sigmoid’)(output)
output= Dropout(0.4)(output)
output = Dense(512, kernel_initializer=“uniform”)(output)
output = Activation(‘sigmoid’)(output)
output= Dropout(0.3)(output)
output = Dense(1, activation=‘sigmoid’)(output)

model = Model(inputs=input_models, outputs=output)
model.compile(loss=‘mean_squared_error’, optimizer=ka.optimizers.Adadelta(lr=0.00001),metrics=[‘mse’,‘mape’])
import pydot_ng as pydot
plot_model(model, show_shapes=True, show_layer_names=True, to_file=‘model.png’)
from IPython.display import Image
Image(retina=True, filename=‘model.png’)
X_train_list,X_val_list,X_test_list = preproc(X_train,X_val, X_test)
history = model.fit(X_train_list,y_train,validation_data=(X_val_list,y_val) , epochs = 10000 )`

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

sorry, such a mess in the major post. please see the link below for the dataset and the ipy file
dataset
IPY FILE
thank you!