This file contains hidden or 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
def fill_proportionally(col, dataset): | |
import random | |
random.seed(0) | |
# getting all unique values (without nan) | |
values = dataset[col].dropna().unique() | |
# getting weights for probability weighting | |
weights = dataset[col].value_counts().values / dataset[col].value_counts().values.sum() | |
print('Before Imputation Probablity Weights\n',weights) |
This file contains hidden or 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 tensorflow as tf | |
from tensorflow.keras.models import Sequential | |
from tensorflow.keras.layers import Dense,Reshape | |
from tensorflow.keras.layers import Dropout | |
def create_model(): | |
# create model | |
model = Sequential() | |
model.add(Dense(60, input_shape=(60,), activation='relu', kernel_regularizer=keras.regularizers.l1(0.01))) | |
model.add(Dropout(0.2)) |
This file contains hidden or 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 tensorflow as tf | |
from tensorflow.keras.models import Sequential | |
from tensorflow.keras.layers import Dense,Reshape | |
from tensorflow.keras.layers import Dropout | |
def create_model(): | |
model = Sequential() | |
model.add(Dense(60, input_shape=(60,), activation='relu')) | |
model.add(Dropout(0.2)) | |
model.add(Dense(30, activation='relu')) |
This file contains hidden or 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 keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img | |
datagen = ImageDataGenerator( | |
rotation_range=40, | |
width_shift_range=0.2, | |
height_shift_range=0.2, | |
brightness_range= [0.5, 1.5], | |
rescale=1./255, | |
shear_range=0.2, | |
zoom_range=0.4, |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
## Base Model | |
logrec = LogisticRegression() | |
## Parameter Grid | |
param_grid = [ | |
{'penalty' : ['l1', 'l2', 'elasticnet', 'none'], | |
'C' : np.logspace(-4, 4, 20), | |
'solver' : ['lbfgs','newton-cg','liblinear','sag','saga'], | |
'max_iter' : [100, 800,1000, 1200] | |
} |
This file contains hidden or 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.cluster import KMeans | |
wcss = [] | |
silhouette_scores = [] | |
calinski_harabasz_scores = [] | |
davies_bouldin_scores = [] | |
for i in range(2, 7): | |
kmeans = KMeans(n_clusters = i, init = 'k-means++', random_state = 42) | |
y_pred = kmeans.fit_predict(X) |
This file contains hidden or 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
mse [] ## Regression Problem | |
accuracy_scores = [] ## Classification Problem | |
""" Train and Test Data Created Using Cross Validation""" | |
for train_index,test_index in kFold.split(X,y): | |
X_train, X_test = X[train_index], X[test_index] | |
y_train, y_test = y[train_index], y[test_index] | |
print("Train Index:", train_index, "|", "Test Index:", test_index) | |
This file contains hidden or 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
################## STRATIFIED K FOLD ########## | |
import numpy as np | |
""" Creating Sample X and y """ | |
X = np.array([[1,2,3], | |
[4,5,6], | |
[7,8,9], | |
[10,11,12], | |
[13,14,15], | |
[16,17,18]]) |
This file contains hidden or 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
############## LEAVE ONE OUT CROSS VALIDATION ########### | |
import numpy as np | |
""" Creating Sample X and y """ | |
X = np.array([[1,2,3], | |
[4,5,6], | |
[7,8,9], | |
[10,11,12], | |
[13,14,15], | |
[16,17,18]]) | |
y = np.array([0,1,1,1,0,1]) |