I am interested in developing a logit-based choice model using Tensorflow.
I am fairly new to this tool, so I was wondering if there is a way to get the statistics (i.e., the p-value) of the weights obtained from Tensorflow , just like someone would get from Stata or SPSS.
The code does run, but cannot be sure if the model is valid unless I can compare the p-values of the variables from the estimation result from STATA.
The data structure is simple; it's a form of a survey, where a respondent chooses an alternative out of 4 options, each with different feature levels (a.k.a. a conjoint analysis).
(I am trying something new; that's why I am not using pylogit of xlogit packages.)
Below is the code I wrote:
mport numpy as np
import tensorflow as tf
import pandas as pd
from sklearn.model_selection import train_test_split
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
np.random.seed(0)
tf.random.set_seed(0)
variables = pd.read_excel('file.xls')
target_vars = ['A','B','C','D','E']
X = pd.DataFrame()
for i in target_vars:
X[i]=variables[i]
y = variables['choice']
X_tn, X_te, y_tn, y_te = train_test_split(X, y, random_state=0)
n_feat = X_tn.shape[1]
epo = 100
model = Sequential()
model.add(Dense(1, input_dim=n_feat, activation='sigmoid'))
model.add(Dense(1))
model.compile(loss = 'mean_squared_error',
optimizer = 'adam',
metrics = ['mean_squared_error'])
hist = model.fit(X_tn, y_tn, epochs=epo, batch_size=4)
model.summary()
model.get_weights()
some other optional questions only if you are familiar with discrete choice models...
i) the original dataset is a conjoint survey with 4 alternatives at each choice situation - that's why I put batch_size=4. Am I doing it right?
ii) have I set the epoch too large?