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

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

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 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, you will use the credit card fraud detection dataset to apply Anomaly Detection with Autoencoders to detect fraud.

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.

Recommender System Machine Learning Project for Beginners Part 2- Learn how to build a recommender system for market basket analysis using association rule mining.

In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.

In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.

We all at some point in time wished to create our own language as a child! But what if certain words always cooccur with another in a corpus? Thus you can make your own model which will understand which word goes with which one, which words are often coming together etc. This all can be done by building a custom embeddings model which we create in this project

The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

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.