Category Archives: PyTorch

Computing and Displaying a Confusion Matrix for a PyTorch Neural Network Multi-Class Classifier

After training a PyTorch multi-class classifier, it’s important to evaluate the accuracy of the trained model. Simple classification accuracy is OK but in many scenarios you want a so-called confusion matrix that gives details of the number of correct and … Continue reading

Posted in PyTorch | Leave a comment

The House Voting Dataset Problem Using PyTorch

A somewhat unusual machine learning problem scenario is one where the predictor variables are all Boolean. This is sometimes called Bernoulli classification. The most well-known example (to me anyway) of this type of problem is the House Voting dataset. I … Continue reading

Posted in PyTorch | Leave a comment

The House Voting Dataset Example Using PyTorch

A relatively well-known machine learning dataset is the House Voting data, also called the Congressional Voting Records Dataset. The raw data looks like: republican,n,y,n,y,y,y,n,n,n,y,?,y,y,y,n,y democrat,n,y,y,n,y,y,n,n,n,n,n,n,y,y,y,y democrat,n,y,n,y,y,y,n,n,n,n,n,n,?,y,y,y republican,n,y,n,y,y,y,n,n,n,n,n,y,y,y,n,y . . . There are 435 data items, corresponding to each of the … Continue reading

Posted in PyTorch | Leave a comment

A PyTorch Dataset Using the Pandas read_csv() Function

To train a PyTorch neural network, the most common approach is to read training data into a Dataset object, and then use a DataLoader object to serve the training data up in batches. When I implement a Dataset, I almost … Continue reading

Posted in PyTorch | Leave a comment

Training a PyTorch Neural Network Using an Evolutionary Algorithm

I’ve been interested in evolutionary algorithms for a long time. In the back of my mind, I had the idea of experimenting with using a evolutionary algorithm to train a PyTorch neural network. So I did. I got a demo … Continue reading

Posted in PyTorch | Leave a comment

Understanding the PyTorch Linear Layer Default Weight and Bias Initialization

When a PyTorch neural network is instantiated, it’s common practice to use implicit weight and bias initialization. In the case of a Linear layer, the PyTorch documentation is not clear, and the source code is surprisingly complicated. I spent several … Continue reading

Posted in PyTorch | 1 Comment

Getting Ready for the PyTorch 2.0 Neural Network Library

The PyTorch web site announced that PyTorch 2.0 is scheduled to be released sometime in March 2023. This is a big deal because major versions (1.0, 2.0, 3.0, etc.) only appear once every few years. I figured I’d investigate version … Continue reading

Posted in PyTorch | Leave a comment

“Multi-Class Classification Accuracy by Class Using PyTorch” in Microsoft Visual Studio Magazine

I wrote an article titled “Multi-Class Classification Accuracy by Class Using PyTorch” in the January 2023 edition of Microsoft Visual Studio Magazine. See https://visualstudiomagazine.com/articles/2023/01/03/accuracy-by-class.aspx. A multi-class classification problem is one where the goal is to predict a discrete value where … Continue reading

Posted in PyTorch | Leave a comment

The Titanic Survival Example Using PyTorch

A well-known example of a binary classification problem is the Titanic survival dataset. The raw data has 1309 rows and 14 columns: pclass, survived, name, sex, age, sibsp, parch, ticket, fare, cabin, embarked, boat, body, dest. To predict if someone … Continue reading

Posted in PyTorch | Leave a comment

Loading Custom Weight Values Into a PyTorch Network

I’ve been exploring the idea of training a PyTorch neural network using an evolutionary algorithm. The basic idea is to create a population of solutions (here, a set of neural weights and biases) and then repeatedly combine two solutions to … Continue reading

Posted in PyTorch | Leave a comment