MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# Find the nearest value from a given value in an array?

# Find the nearest value from a given value in an array?

Find the nearest value from a given value in an array

So this recipe is a short example on how to find the nearest value from a given value in 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 find_nearest(array, value):
idx = (np.abs(array - value)).argmin()
return array[idx]
```

We have a defined find_nearest function. It first subtracts the given value from all the elements of array. Then, finds the argument of closest value by taking the absolute value of all elements.

```
array = np.random.random(10)
print(array)
value = 0.5
print(find_nearest(array, value))
```

Here we define a random array and thereby find the closest value to 0.5

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

[0.91099284 0.4100222 0.26885347 0.0256024 0.10999511 0.11454188 0.79332232 0.71090965 0.3848031 0.82222392] 0.4100222047688208

Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.

Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.