This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np # linear algebra | |
import cv2 # opencv | |
import matplotlib.pyplot as plt # image plotting | |
# keras | |
from keras import Sequential | |
from keras.layers import Flatten, Dense | |
from keras.applications.vgg19 import VGG19 | |
from keras.applications.vgg19 import preprocess_input | |
from keras.preprocessing.image import ImageDataGenerator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Save the trained model | |
model.save('saved_model.h5') | |
# Load the model | |
model = keras.models.load_model('saved_model.h5') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# summarize the result and plot the training and test loss | |
plt.plot(result.history['loss']) | |
plt.plot(result.history['val_loss']) | |
# Set the parameters | |
plt.title('Deep learning model loss') | |
plt.ylabel('Loss') | |
plt.xlabel('Epochs') | |
plt.legend(['train', 'test'], loc='upper right') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the loss and accuracy of the model by evaluation | |
loss, acc = model.evaluate(X_test, y_test) | |
# Print the loss and accuracy score for the model | |
print("%s: %.2f%%" % (model.metrics_names[0], loss*100)) | |
print("%s: %.2f%%" % (model.metrics_names[1], acc*100)) | |
# Predicting the output predictions | |
y_pred = model.predict(X_test).round() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Input | |
model = Sequential() | |
# Hidden layer | |
model.add(Dense(64, kernel_initializer='uniform', input_dim=24, activation='relu')) | |
# Output layer | |
model.add(Dense(1, kernel_initializer='uniform', activation='sigmoid')) | |
# Compiling the model with 'adam' optimizer and loss function as 'binary_crossentropy' | |
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import StandardScaler | |
# Initialization of the class | |
scaler = StandardScaler() | |
# Applying the scaler on test and train data | |
X_train = scaler.fit_transform(X_train) | |
X_test = scaler.transform(X_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.model_selection import train_test_split | |
# Split the data | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Features | |
X = dataset.drop('target', axis = 1) # selecting all columns except the target | |
# Target variable | |
y = dataset['target'] | |
# Print the shape | |
print(X.shape, y.shape) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Replacing null values by mean | |
dataset['Age'].fillna(dataset['Age'].mean(), inplace = True) | |
dataset['T4U'].fillna(dataset['T4U'].mean(), inplace = True) | |
# Replacing null values by median | |
dataset['TSH'].fillna(dataset['TSH'].mean(), inplace = True) | |
dataset['T3'].fillna(dataset['T3'].median(), inplace = True) | |
dataset['TT4'].fillna(dataset['TT4'].median(), inplace = True) | |
dataset['FTI'].fillna(dataset['FTI'].median(), inplace = True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Plot the histogram of different features | |
dataset.hist(figsize = (20,20)); |
NewerOlder