How to resize an image with PyTorch
Command Line Tips
by cmdlinetips
1M ago
In this post, we will learn how to resize an image using PyTorch. PyTorch offers a numerous useful functions to manipulate or transform images. With PyTorch’s reSize() function, we can resize images. We will see a simple example of resizing a single image using Pytorch’s torchvision v2. First, let us load Numpy and Matplotlib. import numpy as np import matplotlib.pyplot as plt Let us load PyTorch specific packages and modules that we will use to manipulate an image. import torch import torchvision from torchvision.io import read_image from torchvision.transforms import v2 Load an image a ..read more
Visit website
Fashion-MNIST data from PyTorch
Command Line Tips
by cmdlinetips
1M ago
In this short tutorial we will learn how to get access to Fashion-MNIST dataset. Fashion-MNIST is one of the image datasets useful for learning and training Deep Learning algorithms in action. PyTorch’s torchvision module makes it easy access Fashion-MNIST dataset. Fashion-MNIST dataset is from Zalando’s article images and it contains a training set of 60,000 examples and a test set of 10,000 examples. Each image is a 28×28 grayscale image with a label from 10 classes, like T-shirt/top, Trouser, and Bag. Fashion-MNIST Data In this post, we will learn how to get Fashion-MNIST data using torchvi ..read more
Visit website
Pandas case_when() with multiple examples
Command Line Tips
by cmdlinetips
1M ago
The newest Pandas release Pandas 2.2.0 has one of the most useful functions case_when() available on a Pandas Series object. Often you might want to create a new variable from an existing variable using multiple conditions. For a simple binary condition we can use Pandas’ where() function. With the new case_when() function we can apply complex conditions to create a new variable. In this post, we will multiple of examples of how to use Pandas case_when() function. Let us load Pandas and Numpy for creating some toy data. import pandas as pd import numpy as np Pandas case_when() is a new addit ..read more
Visit website
An Introduction to Statistical Learning: with Applications in Python Is Here
Command Line Tips
by cmdlinetips
6M ago
An Introduction to Statistical Learning: with Applications in Python An Introduction to Statistical Learning in R ISLR, one of the best books to learn statistical learning, has a cousin now, Statistical Learning in Python. An Introduction to Statistical Learning in Python by Gareth James, Daniela Witten, Trevor Hastie, Robert Tibshirani, and Jonathan Taylor has been out recently. And just like the ISL in R, the new An Introduction to Statistical Learning ISLR is freely available for download at statlearning.com/. Imputing missing data with SVD This post is a result of quick dip on a Sunday aft ..read more
Visit website
10 Tips to customize ggplot2 title text
Command Line Tips
by cmdlinetips
6M ago
In this post, we will see 10 tips to annotate a plot with a title and to customize title text of a plot made with ggplot2. We will start with how to add title to a plot made with ggplot2 using two functions ggtitle() and labs(). And then we will learn how to use ggplot2’s theme() function’s element_text() to change size and add colors to title text. Finally we will learn how to customize title text using ggtext R package. Let us load the packages needed. library(tidyverse) theme_set(theme_bw()) We will use the palmer penguin dataset. penguins %>% head() # A tibble: 6 × 8 species islan ..read more
Visit website
PCA on S&P 500 Stock Return Data
Command Line Tips
by cmdlinetips
7M ago
This post is a fun exercise applying PCA (most in tidyverse framework) to stock data from S&P 500 index companies. With PCA on stock data from S&P 500, we can possibly do many interesting things, but we will focus on really simple things and try to see if PCA captures the general company trends from PCA results. We will use tidyquant R package to get access to stock price data using R and use prcomp() to perform PCA using tidyverse framework with the help of broom package. We will start with getting daily stock price data for about 500 companies in the S&P 500 stock index for the y ..read more
Visit website
Linear Regression with Matrix Decomposition Methods
Command Line Tips
by cmdlinetips
7M ago
Still remember the first time I learned we can perform linear regression using matrix decomposition techniques like QR decomposition. Totally mind blown. Clearly had no clue that was possible. This is a fun post on performing linear regression using QR decomposition, Cholesky decomposition and Singular Value Decomposition (SVD) using #rstats. No theory behind it, just typing some R code using the wonders of linear algebra for matrix decomposition and multiplication. Let us get started by loading the packages needed. In addition to tidyverse, we will load broom for tidying the lm model results ..read more
Visit website
Numpy’s random choice() function
Command Line Tips
by cmdlinetips
7M ago
In this post we will learn how to use Numpy’s choice function. Numpy’s choice() function is a useful tool for selecting random items from a list or array. The basic syntax of choice() function Numpy’s random module is this choice(a, size=None, replace=True, p=None) Here, a is the list or array from which you want to select items, size is the shape of the output array, replace determines whether or not items can be selected multiple times, and p is an array of probabilities for each item in a. As we can see choice() allows you to specify the size of the output, as well as p, the probability o ..read more
Visit website
Difference between Numpy’s Permutation() and Shuffle() functions
Command Line Tips
by cmdlinetips
7M ago
In this post, we will learn about the differences between Numpy’s permutation() function and shuffle() function with examples. Numpy offers a variety of functions to randomize or create random data. Numpy’s permutation() and shuffle() functions are two key functions that help randomize existing 1-D array or 2D-arrays. First, we will start with how to use permutation and shuffle functions in Numpy and understand what they do. Then understand the key difference between permutation and shuffle functions – shuffle() shuffles the matrix in-place while permutation() creates a new array or matrix. Le ..read more
Visit website
How to generate random numbers from Beta distribution in Numpy
Command Line Tips
by cmdlinetips
7M ago
In this tutorial, we will learn how to generate random numbers from Beta distribution in Python using Numpy. We will use Numpy’s Random Generator object with. random module’s beta() function to generate random numbers from beta distribution. We will start with learning the basics of Beta distribution. Then we will learn how to generate a single random number, a 1_D array of random numbers, and 2-D array or matrix of random numbers from Beta distribution using Numpy’s beta() function. What is Beta Distribution The beta distribution is a continuous probability distribution that is defined on the ..read more
Visit website

Follow Command Line Tips on FeedSpot

Continue with Google
Continue with Apple
OR