MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# How to find the closest value to a given scalar in a vector?

# How to find the closest value to a given scalar in a vector?

This recipe helps you find the closest value to a given scalar in a vector

So this recipe is a short example on how to find the closest value (to a given scalar) in a vector. 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.

```
x = np.arange(100)
```

We have generated an array having 100 values from 0 to 99.

```
a = np.random.uniform(0,100)
print(a)
```

We have a genrated a random value between 0 to 100.

```
index = (np.abs(x-a)).argmin()
print(x[index])
```

Now using abs and argumin function, we have found the index corresponding to nearest integer. Finally, we have printed the value from the array corresponding to our found index.

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

66.84178287734619 67

Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.

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

In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

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

Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

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

In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

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.

There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.