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

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

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.

Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

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 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.

Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

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

In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.