MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# How to compute averages using a sliding window over an array?

# How to compute averages using a sliding window over an array?

This recipe helps you compute averages using a sliding window over an array

So this recipe is a short example on how to compute moving averages using a sliding window over an array. Let's get started.

```
import numpy as np
```

Let's pause and look at these imports. Numpy is generally helpful in data manipulation while working with arrays. It also helps in performing mathematical operation.

```
def moving_average(a, n) :
test = np.cumsum(a, dtype=float)
test[n:] = test[n:] - test[:-n]
return test[n - 1:] / n
```

We have a defined a function that helps in returning moving average. It uses cumulative sum for calculation of the same.

```
moving_average(np.arange(20),5)
```

We have send a array of size 20 and then calling the moving_average function, defined earlier, simply printing away the output.

Once we run the above code snippet, we will see:

array([ 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17.])

In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

Deep Learning Project to implement an Abstractive Text Summarizer using Google's Transformers-BART Model to generate news article headlines.

Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

Use the Zillow dataset to follow a test-driven approach and build a regression machine learning model to predict the price of the house based on other variables.

In this time series project, you will build a model to predict the stock prices and identify the best time series forecasting model that gives reliable and authentic results for decision making.

In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

In this deep learning project, you will build a convolutional neural network using MNIST dataset for handwritten digit recognition.

In this deep learning project, you will learn how to build your custom OCR (optical character recognition) from scratch by using Google Tesseract and YOLO to read the text from any images.

Use the Mercari Dataset with dynamic pricing to build a price recommendation algorithm using machine learning in Python to automatically suggest the right product prices.