Skip to content

Instantly share code, notes, and snippets.

Avatar

Merishna S. Suwal merishnaSuwal

View GitHub Profile
View save_model.py
# Save the trained model
model.save('saved_model.h5')
# Load the model
model = keras.models.load_model('saved_model.h5')
View plot_hypothyroid_loss.py
# 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')
View evaluate_hypothyroid.py
# 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()
View model_data_4.py
# 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'])
View model_data_3.py
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)
View model_data_2.py
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)
View model_data_1.py
# 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)
View fill_missing_values_hypothyroid.py
# 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)
View visualize_hypothyroid.py
# Plot the histogram of different features
dataset.hist(figsize = (20,20));
View clean_hypothyroid_data_6.py
# Selecting columns with data type as 'object'
columns = dataset.columns[dataset.dtypes.eq('object')]
# Convert to numeric values
dataset[columns] = dataset[columns].apply(pd.to_numeric, errors='coerce')
# Viewing the details
dataset.info()