Single Layer & Multilayer Perceptron
Single Layer & Multilayer Perceptron
Perceptron
• Single Layer Perceptron:
• A perceptron network is a group of simple logical statements that come together to create
an array of complex logical statements, known as the neural network.
• The perceptron is a linear model used for binary classification.
Perceptron Example
Imagine a perceptron (in your brain).
• The output of a perceptron can only be a binary number (0 or 1) due to the hard limit
transfer function.
• Perceptron can only be used to classify the linearly separable sets of input vectors. If input
vectors are non-linear, it is not easy to classify them properly.
from __future__ import absolute_import
from __future__ import division
from __future__ import
import tensorflow as tf
import numpy as np
# Data sets
IRIS_TRAINING = "iris_training.csv“
IRIS_TEST = "iris_test.csv"
# Load datasets.
training_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TRAINING,
target_dtype=np.int)
test_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TEST, target_dtype=np.int)
# Specify that all features have real-value data
feature_columns = [tf.contrib.layers.real_valued_column("", dimension=4)]
# Build 3 layer DNN with 10, 20, 10 units respectively.
classifier = tf.contrib.learn.DNNClassifier(feature_columns=feature_columns,
hidden_units=[10, 20, 10], n_classes=3)
# Fit model. classifier.fit(x=training_set.data, y=training_set.target,
steps=2000)
# Evaluate accuracy. accuracy_score = classifier.evaluate(x=test_set.data,
y=test_set.target)["accuracy"] print('Accuracy:
{0:f}'.format(accuracy_score))
# Classify two new flower samples.
new_samples = np.array( [[6.4, 3.2, 4.5, 1.5], [5.8, 3.1, 5.0, 1.7]],
dtype=float) y = classifier.predict(new_samples)
print('Predictions: {}'.format(str(y)))