Question

0.5 Question 4 [3.5 marks]

This question will use the card_data.csv dataset. This data has been loaded for you in the

df_card_data variable. The data contains transactions from 2023-04-08 till 2023-04-15 (in-

clusive). You should use all data till 2023-04-14 (inclusive) for training, and transactions that

happened on 2023-04-15 for testing.

[ ]:"""Use the preloaded data in your workings below;

This is a Read-Only cell. Remember to execute this cell once""N

df_card_data = pd. read_csv ("./card_data.csv", index_col="TRANSACTION_ID",

>parse_dates=["TX_DATETIME"])

df_card_data.head()

Q4 (i) [ 0.5 marks ] Train a logistic regression model using the relevant features from the training

portion of the card data. You should use the given variable to store the fitted logistic regression

model. You should also use the statsmodels package for logistic regression.

[ ]:"""Predefined Variables - Do Not Change their Name;

This is a Read-Only cell. Remember to execute this cell once***

logit_2= None

[ ]:"""Populate the variables shown above with appropriate values here""w

# BEGIN - YOUR CODE GOES HERE

pass

# END - YOUR CODE GOES HERE

[]:"""This is a Read-Only cell. Remember to execute this cell once"""

logit 2.summary() if logit_2 is not None and hasattr(logit_2, 'summary') and

callable (logit 2. summary) else None

Q4 (ii) [1 marks] You will find that a number of features that model information related to the

previous week are statistically insignificant at 5%. Explain possible reasons behind this finding in

the context of fraud detection. [Word limit < 150 words]

Note Write your justification in the Markdown cell below

0.5.1 WRITE YOUR ANSWER(S) HERE IN THIS CELL

You can use Markdown syntax here.

Q4 (iii) [ 0.5 marks] Complete the build_nn_model() function that takes six arguments: 1.

input features: The input features to be used to train the neural network 2. output_features:

The feature to predict 3. num_layers: The number of hidden layers in the neural network 4.

num_units: The number of units per layer 5. data: The pandas dataframe containing input and

output features 6. split_date: The date to split the given data into training and test sets. All

the data before the given date will be used for training, and the data from the given date onwards

will be used for testing.

The function should return the trained neural network (nn) and the auc for training data

(train_auc), auc for testing data (test_auc). You should use sklearn metrics to compute AUC

8/nscores.

[ ]: def build_nn_model (input_features, output_feature, num_layers, num_units, data,u

→split_date):

# clear any previous tensor flow sessions

clear_session() # do not duplicate this line

set_seeds (112) # do not change this line

train_auc = None

test_auc

None

nn = None

# complete the code.

# BEGIN - YOUR CODE GOES HERE

pass

# END - YOUR CODE GOES HERE

return nn, train_auc, test_auc

Q4 (iv) [ 0.5 marks] Build two network network models with 2 layers and 16 units, one with a

split date of 2023-4-15, and another with a split date of 2023-4-9. You should restrict the input

features to those that were significant at 5% level in logistic regression. You should use the function

build_nn_model() from the previous question.

[]:"""Populate the variables shown above with appropriate values here"""

# BEGIN - YOUR CODE GOES HERE

pass

# END - YOUR CODE GOES HERE

Q4 (v) [1 marks] Compare and contrast the results from the logistic regression and the neural

networks. [Word limit < 150 words]

Note Write your answer in the Markdown cell below

Question image 1Question image 2