Skip to content

Instantly share code, notes, and snippets.

View nn.py
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import add, Dense, Dropout
from tensorflow.keras.optimizers import Adam
model = Sequential()
model.add(Dense(64,activation='relu'))
model.add(Dense(32, activation = 'relu'))
model.add(Dropout(0.5))
model.add(Dense(16,activation = 'relu'))
View logreg.py
#Logistic Regression Classifier
logReg = LogisticRegression()
logReg.fit(X_train, y_train)
log_y_pred = logReg.predict(X_test)
log_precision = precision_score(y_test, log_y_pred)
log_recall = recall_score(y_test, log_y_pred)
View randomforest.py
#Random Forest Classifier
rf = RandomForestClassifier(n_estimators = 15,random_state=42)
rf.fit(X_train, y_train)
y_pred = rf.predict(X_test)
View borderlinesmote.py
borderlineSMOTE = BorderlineSMOTE(k_neighbors = 10, random_state = 42)
X_train, y_train = borderlineSMOTE.fit_resample(X_train_Before,y_train_Before)
View normalize.py
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
for i in X_train_Before:
scaler = StandardScaler()
X_train_Before[i] = scaler.fit_transform(X_train_Before[i].values.reshape(-1,1))
X_test[i] = scaler.transform(X_test[i].values.reshape(-1,1))
View train_test_split.py
X = data.drop(["Class","Time"],axis=1).values
y = data["Class"].values
X_train_Before, X_test, y_train_Before, y_test = train_test_split(
X, y, test_size = 0.3,
random_state = 42)
View correl.py
correlation = data.corr()
fig = plt.subplots(figsize=(15,15))
sns.heatmap(correlation, vmax= 1 )
View credit_time_v_class.py
# Adjusting figuresize, and fontsize
plt.rcParams["figure.figsize"] = "8,6"
font = {'size': 12}
plt.rc('font', **font)
# Adding titles to the plots and axes
plt.title("Distribution of Time over Both Classes")
plt.xlabel("Time")
plt.ylabel("Class")
View credit_amount_v_class.py
# Adjusting figuresize, and fontsize
plt.rcParams["figure.figsize"] = "8,6"
font = {'size': 12}
plt.rc('font', **font)
# Adding titles to the plots and axes
plt.title("Distribution of Amount over Both Classes")
plt.xlabel("Amount")
plt.ylabel("Class")
View class_countplot_credit.py
sns.countplot(x=data['Class'])
data["Class"].value_counts()