SARSA in the Wind

We will use SARSA algorithm to find the optimal policy so that our agent can navigate in windy world. SARSA State–action–reward–state–action (SARSA) is an algorithm for learning a Markov decision process policy, used in the reinforcement learning area of machine learning. SARSA focuses on state-action values. It updates the Q-function based on the following equation: Q(s,a) = Q(s,a) + α (r + γ Q(s’,a’) – Q(s,a)) Here s’ […]

Balancing pole with Policy Gradient

The policy gradient algorithm trains an agent by taking small steps and updating the weight based on the rewards associated with those steps at the end of an episode. The technique of having the agent run through an entire episode and then updating the policy based on the rewards obtained is called Monte Carlo policy gradient. The action is selected […]

Cross Tabulation in Pandas

The data Importing the Library and loading the data Crosstab Basic Selection with .loc and .iloc Using basic function with cross tab Margins are for total Normalizing Results Aggregate function Sorting Unique values Visualization Plotting

Logistic Regression in PyTorch

Load the Data Converting each column data to numpy array From numpy array to pytorch tensor Plotting the data Using the GPU Defining the neural network Putting neural network on GPU Loss function Setting ADAM as an optimizer Defining accuracy The main loop Plotting Loss Plotting accuracy After one epoch Plots to show performance of neural network over epochs

Basic Neural Network in PyTorch

Making a simple neural network with a single hidden layer and four neurons in hidden layer. Schema of our Neural Network Import necessary libraries Inputs and outputs Converting basic python array to PyTorch tensors Code to use GPU if available Putting our variable to GPU Defining neural network instantiate neural network Weights of different layers Loss function Only one forward […]

PyTorch Tensors

This blog post contains following topics related to tensors: Import Version Declarations item() Zero, identity and linspace Random generator Datatypes Operation with constant Element wise operations Matrix multiplication Matrix inversion Transpose of matrix Determinant of matrix Indexing and slicing Broadcasting Reshape Squeeze and unsqueeze Concatenate and stack Reorganize the data element numpy and pytorch tensor Operations on complex numbers Import […]

2 in One Neural Network

Here we present a 2 in one network. A neural network which does regression and classification at same time. Iris data set has been used in this example Loading the dataset Shuffle the dataframe Inputs and Outputs We take sepal.length, sepal.width and petal.length as an input parameter. We take petal.width as first output parameter and variety as second parameter. The […]

Multi class Classification

We have three classes of images : 7, 8 and 9. The following codes uses VGG16 and CNN to build a model which classifies the images of 7, 8 and 9. Import necessary libraries as usual Load Data: Source of data 7_8_9 Class to load data and make targets Load data and display Vgg16 model Summary of model Function to […]

Ants and Bees using VGG16

Importing Libraries Loading Data Make Class to load data for model Load data and display image Output VGG16 Model Summarize Function to train model Function to calculate Accuracy and validation loss Defining batch and function that load files batch-wise Get model and get data Train model for 5 epochs Plotting accuracy and loss Save model Confusion Matrix Open a new […]

Ants and Bees using CNN

We are trying to build a model using CNN with the help of PyTorch library that can differentiate between images of Ants and Bees. Data used in this task is available at : https://www.kaggle.com/watanabe2362/hymenoptera This process is divided into two parts: Part I : Building the model and saving it. Part II: Loading the model and using it. Part I: […]

Interactive Map in Python

Task: To plot all hydros of district with max hydro in province 6, Nepal Installing library Importing library Reading data of hydro powers Libraries for visualization Basic map Map with layers Map with hydros in Jajarkot with markers

Plotting map in Python

https://www.nationalgeoportal.gov.np/#/metadata/98 installing required libraries Importing libraries Read The province data Plotting map Boundaries Centroid of all province Area wise colormap plot of all province

DataFrame in Pandas

A data frame is a two-dimensional tabular labeled data structure with columns of potentially different types. A data frame can be created from numerous data collections such as the following: A 1D ndarray, list, dict, or series 2D Numpy ndarray Structured or record ndarray A series Another data frame A data frame has arguments, which are an index (row labels) […]

Python

Python is an interpreted high-level general-purpose programming language. Its design philosophy emphasizes code readability with its use of significant indentation. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects. Python is dynamically-typed and garbage-collected. It supports multiple programming paradigms, including structured (particularly, procedural), object-oriented and functional programming. It is often described as a “batteries included” language due to its comprehensive standard library. import python