Skip to content

Instantly share code, notes, and snippets.

View sgsg704's full-sized avatar
🎯
Focusing

Hrithik Gupta sgsg704

🎯
Focusing
View GitHub Profile
df_card = pd.read_csv("https://cainvas-static.s3.amazonaws.com/media/user_data/hrithikgupta/creditcard.csv")
df_card.head(10)
@sgsg704
sgsg704 / code
Created September 2, 2021 02:52
print(df_card.shape)
print(df_card.size)
@sgsg704
sgsg704 / code
Created September 2, 2021 02:53
df_card.info()
@sgsg704
sgsg704 / code
Created September 2, 2021 02:54
df_card.drop(columns = ['Time'], inplace= True)
# Standardizing the amount column
from sklearn import preprocessing
scaler = preprocessing.StandardScaler()
#standard scaling
df_card['Stand_Amount'] = scaler.fit_transform(df_card['Amount'].values.reshape (-1,1))
#removing Amount
df = df_card.drop("Amount", axis=1)
@sgsg704
sgsg704 / code
Created September 2, 2021 02:54
sns.countplot(x="Class", data=df_card)
@sgsg704
sgsg704 / code
Created September 2, 2021 02:55
import imblearn
from imblearn.under_sampling import RandomUnderSampler
undersample = RandomUnderSampler(sampling_strategy=0.5)
cols = df.columns.tolist()
cols = [c for c in cols if c not in ["Class"]]
target = "Class"
@sgsg704
sgsg704 / code
Created September 2, 2021 02:56
# Define X and Y
X = df[cols]
Y = df[target]
# Undersampling
X_sample, Y_sample = undersample.fit_resample(X, Y)
test = pd.DataFrame(Y_sample, columns = ['Class'])
@sgsg704
sgsg704 / code
Created September 2, 2021 02:57
#visualizing undersampling results
fig, axs = plt.subplots(ncols=2, figsize=(13,4.5))
sns.countplot(x="Class", data=df, ax=axs[0])
sns.countplot(x="Class", data=test, ax=axs[1])
fig.suptitle("Class repartition before and after undersampling")
a1=fig.axes[0]
a1.set_title("Before")
a2=fig.axes[1]
a2.set_title("After")
@sgsg704
sgsg704 / code
Created September 2, 2021 02:57
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X_sample, Y_sample, test_size=0.3, random_state=1)
print(len(X_train))
print(len(y_train))
print(len(X_test))
print(len(y_test))
@sgsg704
sgsg704 / code
Created September 2, 2021 02:58
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dropout
from tensorflow.keras.layers import Dense
from tensorflow.keras import layers
from tensorflow.keras import regularizers
from sklearn import metrics
model = Sequential()