Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Loan-default model with images in SNS
# "Defaults of loans" is predicted with "customer data + images in SNS"
# 1.import library
import keras
from keras.layers import Input, Embedding, LSTM, Dense,Conv2D,MaxPooling2D,Flatten
from keras.models import Model, Sequential
# 2.Create image analysis model by convnet
vision_model = Sequential()
vision_model.add(Conv2D(64, (3, 3), activation='relu', padding='same', input_shape=(224, 224,3)))
vision_model.add(Conv2D(64, (3, 3), activation='relu'))
vision_model.add(MaxPooling2D((2, 2)))
vision_model.add(Conv2D(128, (3, 3), activation='relu', padding='same'))
vision_model.add(Conv2D(128, (3, 3), activation='relu'))
vision_model.add(MaxPooling2D((2, 2)))
vision_model.add(Conv2D(256, (3, 3), activation='relu', padding='same'))
vision_model.add(Conv2D(256, (3, 3), activation='relu'))
vision_model.add(MaxPooling2D((2, 2)))
image_input = Input(shape=(224, 224,3))
encoded_image = vision_model(image_input)
# 3.Create training dataset by combining images and customer data
Customer_data = Input(shape=(10,), name='Customer_data')
x = keras.layers.concatenate([encoded_image, Customer_data])
# 4.Create Default prediction model by neural network
x = Dense(64, activation='relu')(x)
x = Dense(64, activation='relu')(x)
x = Dense(64, activation='relu')(x)
Default = Dense(1, activation='sigmoid', name='main_output')(x)
model = Model(inputs=[image_input, Customer_data], outputs=[Default])
model.compile(optimizer='rmsprop', loss='binary_crossentropy')
# The idea of these code is inspired by this awesome work
# "Getting started with the Keras functional API" (by Mr.François Chollet)
# TOSHI STATS SDN. BHD. and I do not accept any responsibility or liability for loss or damage occasioned to any person or property through using materials, instructions, methods, algorithm or ideas contained herein, or acting or refraining from acting as a result of such use. TOSHI STATS SDN. BHD. and I expressly disclaim all implied warranties, including merchantability or fitness for any particular purpose. There will be no duty on TOSHI STATS SDN. BHD. and me to correct any errors or defects in the codes and the software.

This comment has been minimized.

Copy link
Owner Author

TOSHISTATS commented May 14, 2017

default model 20170514

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.