Utilizing logistic regression in TensorFlow

For us to utilize logistic regression in TensorFlow, we first need to import whatever libraries we are going to use. To do so, you can run this code cell:

import tensorflow as tf

import pandas as pd

import numpy as np
import time
from sklearn.datasets import load_iris
from sklearn.cross_validation import train_test_split
import matplotlib.pyplot as plt

Next, we will load the dataset we are going to use. In this case, we are utilizing the iris dataset, which is inbuilt. So, there's no need to do any preprocessing and we can jump right into manipulating it. We separate the dataset into x's and y's, and then into training x's and y's and testing x's and y's, (pseudo) randomly:

iris_dataset = load_iris()
iris_input_values, iris_output_values = iris_dataset.data[:-1,:], iris_dataset.target[:-1]
iris_output_values= pd.get_dummies(iris_output_values).values
train_input_values, test_input_values, train_target_values, test_target_values = train_test_split(iris_input_values, iris_output_values, test_size=0.33, random_state=42)

Now, we define x and y. These placeholders will hold our iris data (both the features and label matrices) and help pass them along to different parts of the algorithm. You can consider placeholders as empty shells into which we insert our data. We also need to give them shapes that correspond to the shape of our data. Later, we will insert data into these placeholders by feeding the placeholders the data via a feed_dict (feed dictionary):

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset