ler

.pdf

School

University of North Texas *

*We aren’t endorsed by this school

Course

123

Subject

Industrial Engineering

Date

Feb 20, 2024

Type

pdf

Pages

4

Uploaded by BailiffFlowerIbex39

Report
File - C:\Users\srima\PycharmProjects\Logistic_Regression_Diagnostics\main.py 1 # Import Statements 2 import numpy as np 3 from sklearn.preprocessing import StandardScaler 4 from sklearn.model_selection import train_test_split 5 import tensorflow as tf 6 import matplotlib.pyplot as plt 7 import matplotlib.lines as mlines 8 from keras.models import Sequential 9 from keras.layers import Dense 10 from keras.optimizers import Adam 11 from keras.losses import BinaryCrossentropy 12 13 14 class Classification_ANN_Diagnoser: 15 def __init__(self): 16 self.data = np.loadtxt('data_w3_ex2.csv', delimiter=',"' ) 17 self.x, self.y = self.divide_x_y() 18 self.x_train, self.y_train, \ 19 self.x_cv, self.y_cv, \ 20 self.x_test, self.y_test = self.split_data() 21 self.x_train_scaled, self.x_cv_scaled, self. X_test_scaled = self.feature_scaling() 22 self.threshold = 0.5 23 self.models = self.build_models() 24 self.nn_train_error = [] 25 self.nn_cv_error = [] 26 27 def divide_x_y(self): 28 # Dividing features and targets 29 X = self.datal:, :-1] 30 y = self.datal[:, 2:3] 31 return X, Yy 32 33 def split_data(self): 34 # Splitting data into 3 sets 35 x_train, x_, y_train, y_ = train_test_split(self.x, self.y, test_size=0.40, random_state=1) 36 X_cv, X_test, y_cv, y_test = train_test_split(x_, y_, test_size=0.50, random_state=1) 37 # Delete x_, y_ 38 del x_, y_ 39 40 return x_train, y_train, x_cv, y_cv, x_test, y_test 41 42 def feature_scaling(self): 43 scaler_linear = StandardScaler() 44 X_train_scaled = scaler_linear.fit_transform(self. Page 1 of 4
File - C:\Users\srima\PycharmProjects\Logistic_Regression_Diagnostics\main.py 44 x_train) 45 Xx_cv_scaled = scaler_linear.transform(self.x_cv) 46 x_test_scaled = scaler_linear.transform(self.x_test) 47 return x_train_scaled, x_cv_scaled, x_test_scaled 48 49 def plot_dataset(self, title): 50 for i in range(len(self.y)): 51 marker = 'x' if self.y[i] == 1 else 'o' 52 c = 'r' if self.y[i] == 1 else 'b' 53 plt.scatter(self.x[i, 0], self.x[i, 1], marker= marker, c=c) 54 plt.title("x1 vs x2") 55 plt.xlabel("x1") 56 plt.ylabel("x2") 57 y_0 = mlines.Line2D([], []1, color='r', marker='x', markersize=12, linestyle='None', label='y=1"') 58 y_1 = mlines.Line2D([], [], color='b', marker='o', markersize=12, linestyle='None', label='y=0') 59 plt.title(title) 60 plt.legend(handles=[y_0, y_11) 61 plt.show() 62 63 @staticmethod 64 def build_models(): 65 tf.random.set_seed(20) 66 model_1 = Sequential( 67 [ 68 Dense(25, activation='relu'), 69 Dense(15, activation='relu'), 70 Dense(1, activation='sigmoid"') 71 1, 72 name="model_1' 73 ) 74 75 model_2 = Sequential( 76 [ 77 Dense(20, activation='relu'), 78 Dense(12, activation='relu'), 79 Dense(12, activation='relu'), 80 Dense(20, activation='relu'), 81 Dense(1, activation='sigmoid"') 82 1, 83 name="'model_2' 84 ) 85 86 model_3 = Sequential( 87 [ 88 Dense(32, activation='relu'), Page 2 of 4
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help