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
# Declare an optimizer: here i use gradient descent | |
my_opt = tf.train.GradientDescentOptimizer(learning_rate=0.02) | |
#Create the train step | |
train_step = my_opt.minimize(loss) | |
n_iterations = 100 | |
loss_stochastic = [] |
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
#Load our libraries | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import tensorflow as tf | |
sess = tf.Session() | |
# declare batch size | |
batch_size = 20 | |
x_vals = np.random.normal(1, 0.1, 100) |
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
loss = tf.reduce_mean(tf.square(Y_pred - Y_target)) | |
# Declare the optimizer (G.D) | |
my_opt = tf.train.GradientDescentOptimizer(0.02) | |
train_step = my_opt.minimize(loss) | |
loss_batch = [] | |
for i in range(100): | |
#pick a random 20 data points |
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
plt.plot(range(0, 100, 5), loss_batch, 'r--', label='Batch Loss') | |
plt.plot(range(0, 100, 5), loss_stochastic, 'b-', label='Stochastic Loss') | |
plt.legend(loc='upper right') | |
plt.title('Batch training vs Stochastic training') | |
plt.show() |
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
import pandas as pd | |
import numpy as np | |
from statistics import mode | |
german_cred = pd.read_csv('credit_preped.csv') | |
german_cred.head() |
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 single models | |
from sklearn.linear_model import LinearRegression, LogisticRegression | |
from sklearn.svm import SVR, SVC | |
from sklearn.neighbors import KNeighborsRegressor,KNeighborsClassifier | |
#Classification models | |
log_cf = LogisticRegression(solver='lbfgs', random_state=rand_seed) | |
svc_cf = SVC(gamma='scale', random_state=rand_seed) | |
knn_cf = KNeighborsClassifier() |
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
#Classification | |
for model in classification_models: | |
model_train(model, features=german_cred, target_name='bad_credit') | |
#Regression | |
for model in regression_models: | |
model_train(model, features=german_cred, target_name='age_yrs', task='reg') |
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
#get the data sets | |
X_train, X_val, y_train, y_val = get_split_data(german_cred, target_name='age_yrs') | |
#fit base models | |
linear_reg.fit(X_train, y_train) | |
knn_reg.fit(X_train, y_train) | |
svr_reg.fit(X_train, y_train) | |
#make predictions with trained models | |
pred1 = linear_reg.predict(X_val) |
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
print("Linear Regression Model") | |
print(get_mae(pred1, y_val)) | |
print("KNN Regression Model") | |
print(get_mae(pred2, y_val)) | |
print("SVR Regression Model") | |
print(get_mae(pred3, y_val)) | |
print("Average Model") | |
print(get_mae(avgpred, y_val)) |