Implementing logistic regression using TensorFlow
We herein use 90% of the first 300,000 samples for training, the remaining 10% for testing, and assume that X_train_enc, Y_train, X_test_enc, and Y_test contain the correct data:
- First, we import TensorFlow, transform
X_train_encandX_test_encinto anumpyarray, and castX_train_enc,ÂY_train,ÂX_test_enc, andÂY_testtofloat32:>>> import tensorflow as tf >>> X_train_enc = X_train_enc.toarray().astype('float32') >>> X_test_enc = X_test_enc.toarray().astype('float32') >>> Y_train = Y_train.astype('float32') >>> Y_test = Y_test.astype('float32') - We use the
tf.dataAPI to shuffle and batch data:>>> batch_size = 1000 >>> train_data = tf.data.Dataset.from_tensor_slices((X_train_enc, Y_train)) >>> train_data = train_data.repeat().shuffle(5000).batch...