What is covariance and how to find covariance in python?

This recipe explains what is covariance and how to find covariance in python

Recipe Objective

What is covariance? How to find covariance in python? Covariance It is the measure of the strength of correlation between two variables or set of variables. There are certain possibilities which are:

Cov(xi, xj) = 0 then the variabels are not correlated

Cov(xi, xj) > 0 then the variabels are possitively correlated

Cov(xi, xj) >< 0 then the variabels are negatively correlated.

Step 1 - Import library

import numpy as np

Step 2 - Take Sample data

Sample_data = np.array([[11,20,35],[40,58,64],[71,87,96]]) print("This is Sample array:","\n",Sample_data)
This is Sample array: 
 [[11 20 35]
 [40 58 64]
 [71 87 96]]

Step 3 - Print Results

print("The Covariance of Sample data:","\n",np.cov(Sample_data))
The Covariance of Sample data: 
 [[147.         138.         146.5       ]
 [138.         156.         157.        ]
 [146.5        157.         160.33333333]]

What Users are saying..

profile image

Ameeruddin Mohammed

ETL (Abintio) developer at IBM
linkedin profile url

I come from a background in Marketing and Analytics and when I developed an interest in Machine Learning algorithms, I did multiple in-class courses from reputed institutions though I got good... Read More

Relevant Projects

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

Walmart Sales Forecasting Data Science Project
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.

Build CNN Image Classification Models for Real Time Prediction
Image Classification Project to build a CNN model in Python that can classify images into social security cards, driving licenses, and other key identity information.

Word2Vec and FastText Word Embedding with Gensim in Python
In this NLP Project, you will learn how to use the popular topic modelling library Gensim for implementing two state-of-the-art word embedding methods Word2Vec and FastText models.

MLOps Project to Build Search Relevancy Algorithm with SBERT
In this MLOps SBERT project you will learn to build and deploy an accurate and scalable search algorithm on AWS using SBERT and ANNOY to enhance search relevancy in news articles.

Time Series Project to Build a Multiple Linear Regression Model
Learn to build a Multiple linear regression model in Python on Time Series Data

Natural language processing Chatbot application using NLTK for 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.

Time Series Classification Project for Elevator Failure Prediction
In this Time Series Project, you will predict the failure of elevators using IoT sensor data as a time series classification machine learning problem.

End-to-End Snowflake Healthcare Analytics Project on AWS-2
In this AWS Snowflake project, you will build an end to end retraining pipeline by checking Data and Model Drift and learn how to redeploy the model if needed

Deep Learning Project for Time Series Forecasting in Python
Deep Learning for Time Series Forecasting in Python -A Hands-On Approach to Build Deep Learning Models (MLP, CNN, LSTM, and a Hybrid Model CNN-LSTM) on Time Series Data.