Skip to content

Instantly share code, notes, and snippets.

View Joelfranklin96's full-sized avatar

S Joel Franklin Joelfranklin96

View GitHub Profile
@Joelfranklin96
Joelfranklin96 / gist:e22a36622a094f0789c29b7f068e447e
Last active November 19, 2019 01:25
Elbow method of K-means clustering algorithm
import numpy as np # Import the necessary packages.
import pandas as pd
epsilon = list(range(4)) # Initialisation of epsilon which would store cost function for each value of 'k' after final iteration.
for k in range(2,6): # Number of clusters
cluster = pd.read_csv('/kaggle/input/clustering/k-means clustering.csv') # Read data file into 'cluster'
rows = cluster.shape[0] # 'rows' contains the total number of rows in cluster data.
@Joelfranklin96
Joelfranklin96 / plot.py
Last active November 19, 2019 01:24
elbow method of K-Means clustering 2
k = list(range(2,6)) # Range of 'k'
plt.figure(figsize=(20,10)) # Size of figure is adjusted.
plt.xticks(fontsize=20) # Size of number labels on x-axis is adjusted.
plt.yticks(fontsize=20) # Size of number labels on y-axis is adjusted.
plt.plot(k,epsilon,'go--', linewidth=1.5, markersize=4) # Graph is plotted.
plt.xlabel('Value of k',fontsize = 25) # x-axis is labelled.
plt.ylabel('Value of Epsilon',fontsize = 25) # y-axis is labelled.
@Joelfranklin96
Joelfranklin96 / K-means clustering.py
Last active November 23, 2019 09:30
K-means clustering
# Necessary packages are imported.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Loading of data set into 'cluster'.
cluster = pd.read_csv('k-means clustering.csv')
k = 3 # Number of clusters
@Joelfranklin96
Joelfranklin96 / Elbow method of K-Means clustering.py
Created November 23, 2019 10:17
Elbow method of K-Means clustering
import numpy as np # Import the necessary packages.
import pandas as pd
epsilon = list(range(4)) # Initialisation of epsilon which would store cost function for each value of 'k' after final iteration.
for k in range(2,6): # Number of clusters
cluster = pd.read_csv('k-means clustering.csv') # Read data file into 'cluster'
rows = cluster.shape[0] # 'rows' contains the total number of rows in cluster data.
from keras.layers import Dropout
# Defining the model
def create_model(learning_rate,dropout_rate):
model = Sequential()
model.add(Dense(8,input_dim = 8,kernel_initializer = 'normal',activation = 'relu'))
model.add(Dropout(dropout_rate))
model.add(Dense(4,input_dim = 8,kernel_initializer = 'normal',activation = 'relu'))
model.add(Dropout(dropout_rate))
@Joelfranklin96
Joelfranklin96 / Activation function and kernel initializer.py
Last active December 10, 2019 20:19
GridSearchCv - Activation function and kernel initializer
# Defining the model
def create_model(activation_function,init):
model = Sequential()
model.add(Dense(8,input_dim = 8,kernel_initializer = init,activation = activation_function))
model.add(Dropout(0.1))
model.add(Dense(4,input_dim = 8,kernel_initializer = init,activation = activation_function))
model.add(Dropout(0.1))
model.add(Dense(1,activation = 'sigmoid'))
@Joelfranklin96
Joelfranklin96 / Number of neurons in activation layer.py
Last active July 31, 2022 17:02
GridSearchCV - Number of neurons
# Defining the model
def create_model(neuron1,neuron2):
model = Sequential()
model.add(Dense(neuron1,input_dim = 8,kernel_initializer = 'uniform',activation = 'tanh'))
model.add(Dropout(0.1))
model.add(Dense(neuron2,input_dim = neuron1,kernel_initializer = 'uniform',activation = 'tanh'))
model.add(Dropout(0.1))
model.add(Dense(1,activation = 'sigmoid'))
@Joelfranklin96
Joelfranklin96 / optimum values of hyperparameters.py
Created December 10, 2019 21:08
Training model using optimum values of hyperparameters
from sklearn.metrics import classification_report, accuracy_score
# Defining the model
def create_model():
model = Sequential()
model.add(Dense(16,input_dim = 8,kernel_initializer = 'uniform',activation = 'tanh'))
model.add(Dropout(0.1))
model.add(Dense(4,input_dim = 16,kernel_initializer = 'uniform',activation = 'tanh'))
model.add(Dropout(0.1))
@Joelfranklin96
Joelfranklin96 / Ultimate hyperparameter optimization.py
Created December 10, 2019 21:23
Ultimate hyperparameter optimization
def create_model(learning_rate,dropout_rate,activation_function,init,neuron1,neuron2):
model = Sequential()
model.add(Dense(neuron1,input_dim = 8,kernel_initializer = init,activation = activation_function))
model.add(Dropout(dropout_rate))
model.add(Dense(neuron2,input_dim = neuron1,kernel_initializer = init,activation = activation_function))
model.add(Dropout(dropout_rate))
model.add(Dense(1,activation = 'sigmoid'))
adam = Adam(lr = learning_rate)
model.compile(loss = 'binary_crossentropy',optimizer = adam,metrics = ['accuracy'])
@Joelfranklin96
Joelfranklin96 / get_dummies.py
Created December 12, 2019 23:40
get_dummies
# Initialize the dataframe 'numerical_nucleotide' of shape (106,(57*4))
numerical_nucleotide = pd.DataFrame(np.random.randn(106,(57*4)))
# Define the dictionary 'key1'
key1 = {'a' : '1000','c' : '0100','g' : '0010','t' : '0001'}
# Assign values to 'numerical_nucleotide'
for i in range(nucleotide_sequence.shape[0]):