MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# What is cosine similarity and how to calculate it?

# What is cosine similarity and how to calculate it?

This recipe explains what is cosine similarity and how to calculate it

Cosine similarity gives us the sense of cos angle between vectors. When vector are in same direction, cosine similarity is 1 while in case of perpendicular, it is 0. It is given by (1- cosine distance).

So this recipe is a short example on what cosine similarity is and how to calculate it. Let's get started.

```
from scipy import spatial
```

Let's pause and look at these imports. We have imported spatial library from scipy class Scipy contains bunch of scientific routies like solving differential equations.

```
x=[1,2,3]
y=[-1,-2,-3]
```

Let us create two vectors list.

```
z=1-spatial.distance.cosine(x,y)
```

We have first calucated cosine distance and the subtracting it from 1 has given us cosine similarity

```
print(z)
```

Simply use print function to print new appended list.

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

-1.0

In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

In this deep learning project, you will build a classification system where to precisely identify human fitness activities.

In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

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 project, we are going to work on Deep Learning using H2O to predict Census income.

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.

This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

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 project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.