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

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

Multilabel Classification Project for Predicting Shipment Modes
Multilabel Classification Project to build a machine learning model that predicts the appropriate mode of transport for each shipment, using a transport dataset with 2000 unique products. The project explores and compares four different approaches to multilabel classification, including naive independent models, classifier chains, natively multilabel models, and multilabel to multiclass approaches.

LLM Project to Build and Fine Tune a Large Language Model
In this LLM project for beginners, you will learn to build a knowledge-grounded chatbot using LLM's and learn how to fine tune it.

BERT Text Classification using DistilBERT and ALBERT Models
This Project Explains how to perform Text Classification using ALBERT and DistilBERT

Build ARCH and GARCH Models in Time Series using Python
In this Project we will build an ARCH and a GARCH model using Python

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

End-to-End Speech Emotion Recognition Project using ANN
Speech Emotion Recognition using RAVDESS Audio Dataset - Build an Artificial Neural Network Model to Classify Audio Data into various Emotions like Sad, Happy, Angry, and Neutral

Deep Learning Project for Text Detection in Images using Python
CV2 Text Detection Code for Images using Python -Build a CRNN deep learning model to predict the single-line text in a given image.

AWS Project to Build and Deploy LSTM Model with Sagemaker
In this AWS Sagemaker Project, you will learn to build a LSTM model on Sagemaker for sales forecasting while analyzing the impact of weather conditions on Sales.

Build Customer Propensity to Purchase Model in Python
In this machine learning project, you will learn to build a machine learning model to estimate customer propensity to purchase.

End-to-End Snowflake Healthcare Analytics Project on AWS-2
In this AWS Snowflake project, you will build an end to end retraining pipeline by checking Data and Model Drift and learn how to redeploy the model if needed