Skip to content

Instantly share code, notes, and snippets.

View Abhayparashar31's full-sized avatar
:octocat:
Learning New Things

Abhay Parashar Abhayparashar31

:octocat:
Learning New Things
View GitHub Profile
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)
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))
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'))
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.
## 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]
}
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)
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)
################## 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]])
############## 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])