Image by Egor Kamelev from Pexels

Python quick tip: DICT or IF for getting a value? Performance & memory battle within python standard modules.

Are you afraid of unknowns, and you always stay with only one way of implementation? Or you want to be a better python programmer?

Let me show you on why to use dict instead of if statements in your python program.

Background:

If statements and dicts are present in every modern programming language. Whereas if statements are especially designed to control flow of operations of a program, dicts are a data structures. Nevertheless, dicts may be used to control flow of operations the same as if statements, or even better!

Let’s see an example!

This is an example of if statement


Image by Kuncheek from Pexels

Part 2: Nvidia CUDA tutorial (with code) - how to use GPU computing power to boost speed of options pricing valuation. Black-Scholes-Merton model boosted by CUDA in c++.

Note: Part 1 may be found here — where I run tests of Python vs C++ vs CUDA performance.

There are millions of financial transactions each day globally. The vast majority is conducted on a market for derivatives (options, futures etc., are typical examples). This means that, every day, thousands of financial institutions (like: banks, stock exchanges, etc.) have to value its financial holdings.

Note: here is the link to the latest…


Part 1: Boost python with c/c++ bindings. Beginners’ friendly guide to start embedding c/c++ shared libraries in python.

Python is a very easy, but versatile programming language used almost everywhere. Being an interpreted language it naturally lags behind in terms of speed of execution.

In this tutorial you will learn on how to make your python program faster using c/c++ code. Let’s start.

Note: here are the requirements you need to meet:- Visual Studio 2019 (don’t confuse it with Visual Studio Code)- installed python- pycharm community edition- OS: windows 10

There are 3 things we need…


Photo by Pixabay from Pexels

(Tutorial) Unleashing the power of examples in learning regex. Part 1 with example on email extraction (with python & c++ code)

Let’s start with the basics.

What’s REGEX?

Regex is the tool to find specified matches in string like: e-mails, names, cities, syntax errors, tickers etc …

To put it simply when you want to extract specified words (in our example emails) from the below text — regext is your friend!

This is an example string to show you that this email example@example.com can be easily extracted from such text.

Regex is used everywhere and in general its fundamentals are…


Image by Christina Morillo from Pexels

(Tutorial) List comprehensions in Python with examples and code.

What is a list comprehension?

Simply put, a list comprehension is a pythonic shortcut of a ‘for-loop’. For example, when we want to raise every number to the power of two we can do a simple for loop:

range_100_items = range(100)

squares = []
for x in range_100_items:
squares.append(x**2)

or we can just use a list comprehension:

range_100_items = range(100)squares_list_comprehension = [x**2 for x in range_100_items]

Output from both methods is the same:

print(squares)
print(squares_list_comprehension)
output: [0, 1, 4, 9, 16, 25 …, 9801]

The syntax for a list comprehension…


Image by Anna Tarazevich from Pexels

“Use me well and keep me clean. I’ll never tell what I have seen” — AI model. Part 2 on the dream of democratising ML never seemed closer. (with python code)

Note: In this link you can find part 1 where I introduced snorkel approach for data labelling.

The maxim within a title of this article is an extremely broad topic — but in short it comes to on how hard it is to understand an AI model. This is so important due to the fact that in many areas the current regulation require AI models to be explainable.

This…


Image by Diana Silaraja from Pexels

Part 1: How to tame pandas' memory management. Three quick and easy tricks. (with python code)

Pandas — an unquestionable leader of data analysis toolkit in python. It offers a very easy, flexible and versatile interface. Ideal for both POC (Proof of Concept) and production solution that can scale with proper implementation.

In this tutorial I’ll introduce three tricks that can really help with decreasing memory consumption using big data frames in pandas.

For JAVA and C++ programmers defining data types is just a bread and butter. …


Photo by Maksim Goncharenok from Pexels

5 the most common evaluation metrics used by a machine learning & deep learning scientists that you should know in depth.

Evaluation metrics are the foundations of every ML/AI project. The main goal is to evaluate performance of a particular model. Unfortunately, very often happens that certain metrics are not completely understood — especially with a client side.

In this article I will introduce 5 most common metrics and try to show some potential idiosyncratic* risks they have.

Accuracy

Accuracy metric shows the percentage of good classified predictions in a given dataset versus all predictions. Simply if all classes are categorised…


Image by Pixabay from Pexels

Part1: Python vs C++ vs CUDA: Comparing performance speed part 1 (with code)

It’s obvious that AI needs a lot of computing power. Let’s check if we can fully leverage our PCs and MACs.

Python is programming language considered as a very simple, but slow.

C++ is a programming language known as a complicated, but one of the fastest.

CUDA is a parallel computing platform for general computing on graphical processing units (GPUs). With CUDA, developers are able to dramatically speed up computing applications by harnessing the power of GPUs.

Whereas both python and c++ are nicely optimized on single…


Image from Wendy Wei from Pexels

Music AI: build a neural network that predicts whether a song will be a world-class success. (with python code)

Neural networks proved to be so outstanding due to its ability to find patterns and generalise. In this tutorial I will show you a step-by-step instruction with python code to build a neural network that is able to predict whether a song will be a world-class hit. All that based on the data of 1000 best & worst songs off all times.

Note: you need to download data on your own. In the provided code I showed an example of 14…

Maciej Zalwert

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store