Sitemap
TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Training a Neural Network With a Few, Clean Lines of Code

Reusable, maintainable and easy to understand machine learning code

7 min readJun 14, 2022

--

Press enter or click to view image in full size
Photo by Milad Fakurian on Unsplash — edited by author

Less code usually results in readable code that is easy to understand and easy to maintain. The Python programming language, that has become very popular in the machine learning community, allows you to achieve great results with less code compared to other programming languages.

PyTorch is a popular deep learning framework for Python that has a clean API and allows you to write code that really feels like Python. Due to that it’s really fun to create models and perform machine learning experiments with PyTorch in Python.

In this article I’m going to show you the basic steps that you need to train a simple classifier that recognizes handwritten digits. You will see how to

  • load the MNIST dataset (the ‘Hello World’ dataset for machine learning) with PyTorch’s data loader
  • declare the architecture of our model
  • select an optimizer
  • implement the training loop
  • determine the accuracy of the trained model

I want to keep everything as simple as possible. Therefore, I don’t cover things like overfitting, data preprocessing or different metrics…

--

--

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Daniel
Daniel

Written by Daniel

Software engineering, security, machine learning

No responses yet