How to build a single layer neural network model using theano?

This recipe helps you to build a single layer neural network model using theano.

Recipe Objective - How to build a single-layer neural network model using theano?

Let's try to build a single layer neural network model, where x1 and x2 are input neurons, b is bias and o is output neuron.

For more related projects -

/projects/data-science-projects/keras-deep-learning-projects
/projects/data-science-projects/neural-network-projects

Example -

# Importing libraries
import theano
from theano import tensor
from theano.ifelse import ifelse

# Creating variables
# Input neuron
x = tensor.vector('x')

# Weight
w = tensor.vector('w')

# Bias
b = tensor.scalar('b')

# Creating expression:
z = tensor.dot(x,w)+b

# Output neuron
o = ifelse(tensor.lt(z,0),0,1)

fun_neural_network = theano.function([x,w,b],o)

# Defining Inputs, Weights and bias
inputs = [ [0, 0], [0, 1], [1, 0], [1, 1] ]
weights = [ 1, 1]
bias = 0

# Iterate through all inputs and find outputs:
for ip in range(len(inputs)):
 m = inputs[ip]
 out = fun_neural_network(m,weights,bias)
 print('The output for x1 = {} & x2 = {} is {}'.format(m[0],m[1],out))

Output -
The output for x1 = 0 & x2 = 0 is 1
The output for x1 = 0 & x2 = 1 is 1
The output for x1 = 1 & x2 = 0 is 1
The output for x1 = 1 & x2 = 1 is 1

In this way, we can build a single-layer neural network model using theano.

What Users are saying..

profile image

Savvy Sahai

Data Science Intern, Capgemini
linkedin profile url

As a student looking to break into the field of data engineering and data science, one can get really confused as to which path to take. Very few ways to do it are Google, YouTube, etc. I was one of... Read More

Relevant Projects

Isolation Forest Model and LOF for Anomaly Detection in Python
Credit Card Fraud Detection Project - Build an Isolation Forest Model and Local Outlier Factor (LOF) in Python to identify fraudulent credit card transactions.

Build a Credit Default Risk Prediction Model with LightGBM
In this Machine Learning Project, you will build a classification model for default prediction with LightGBM.

Recommender System Machine Learning Project for Beginners-1
Recommender System Machine Learning Project for Beginners - Learn how to design, implement and train a rule-based recommender system in Python

Azure Deep Learning-Deploy RNN CNN models for TimeSeries
In this Azure MLOps Project, you will learn to perform docker-based deployment of RNN and CNN Models for Time Series Forecasting on Azure Cloud.

Build a Churn Prediction Model using Ensemble Learning
Learn how to build ensemble machine learning models like Random Forest, Adaboost, and Gradient Boosting for Customer Churn Prediction using Python

Learn to Build Generative Models Using PyTorch Autoencoders
In this deep learning project, you will learn how to build a Generative Model using Autoencoders in PyTorch

Build a Multi-Class Classification Model in Python on Saturn Cloud
In this machine learning classification project, you will build a multi-class classification model in Python on Saturn Cloud to predict the license status of a business.

AWS MLOps Project for ARCH and GARCH Time Series Models
Build and deploy ARCH and GARCH time series forecasting models in Python on AWS .

AWS MLOps Project for Gaussian Process Time Series Modeling
MLOps Project to Build and Deploy a Gaussian Process Time Series Model in Python on AWS

Deep Learning Project for Beginners with Source Code Part 1
Learn to implement deep neural networks in Python .