<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Yusra Liaqat</title>
    <description>The latest articles on Forem by Yusra Liaqat (@liaqat_yusra).</description>
    <link>https://forem.com/liaqat_yusra</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F921722%2F2e7f04a6-bc83-4d76-a1f2-8cafcfbcf041.jpg</url>
      <title>Forem: Yusra Liaqat</title>
      <link>https://forem.com/liaqat_yusra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/liaqat_yusra"/>
    <language>en</language>
    <item>
      <title>churn prediction in telecom industry using python</title>
      <dc:creator>Yusra Liaqat</dc:creator>
      <pubDate>Thu, 15 Jun 2023 07:54:10 +0000</pubDate>
      <link>https://forem.com/liaqat_yusra/churn-prediction-in-telecom-industry-using-python-1359</link>
      <guid>https://forem.com/liaqat_yusra/churn-prediction-in-telecom-industry-using-python-1359</guid>
      <description>&lt;p&gt;I’m going to create a program that can predict customer churn&lt;br&gt;
Customer churn occurs when subscribers or customers stop doing business with the company within a specific amount of time and retaining customer is more important for companies because it boost company’s revenue and Help Company to build meaningful relationship with the company.&lt;br&gt;
In actual, customer retention is more valuable than customer acquisition.&lt;/p&gt;
&lt;h2&gt;
  
  
  Python Program to Predict Customer Churn
&lt;/h2&gt;
&lt;h2&gt;
  
  
  Import Libraries
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd
import numpy as np
import sklearn
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import classification_report
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Load the Dataset In Python
&lt;/h2&gt;

&lt;p&gt;Now, I’m going to load my dataset so I’ve to use Google’s library to do this&lt;br&gt;
Following are the commands to import data in colaboratory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from google.colab import files
uploaded = files.upload()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running this cell click on choose file and upload the file that you wanted to upload from your customer churn data&lt;/p&gt;

&lt;h2&gt;
  
  
  Load the Data Into A Data Frame
&lt;/h2&gt;

&lt;p&gt;Here, I’ve created a variable called DF which will be short for data frame. Here I want to look at the data specifically and the first five rows of data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df = pd.read_csv('WA_Fn-UseC_-Telco-Customer-Churn.csv')
df.head(7)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QG6ebMtD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w4y30zkkbfd56lod26uj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QG6ebMtD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w4y30zkkbfd56lod26uj.png" alt="Image description" width="800" height="174"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now we are able to take a look at the data frame. As we can see we have all of our columns on the top and also up to the bottom we can see our target column which is called “churn”. And we can see the values in this column appears to be yes and no. so no would mean that customer did not churn and off course yes would mean that customer did churn and each row is a costumer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Show the Number Of Rows And Columns
&lt;/h2&gt;

&lt;p&gt;So just type,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df.shape
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(7043, 21)&lt;/p&gt;

&lt;p&gt;And we can see that there is seven thousand forty-three rows or customers in this data set and there are twenty one columns or data points on each customer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Show All of The Columns
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df.columns.values
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;array(['customerID', 'gender', 'SeniorCitizen', 'Partner', 'Dependents', 'tenure', 'PhoneService', 'MultipleLines', 'InternetService', 'OnlineSecurity', 'OnlineBackup', 'DeviceProtection', 'TechSupport', 'StreamingTV', 'StreamingMovies', 'Contract', 'PaperlessBilling', 'PaymentMethod', 'MonthlyCharges', 'TotalCharges', 'Churn'], dtype=object)&lt;/p&gt;

&lt;p&gt;So, here we can see all of the columns name and immediately I can see some interesting columns like customer Id, gender, phone service, internet service, contract, monthly charges, tenure and obviously churn&lt;/p&gt;

&lt;h2&gt;
  
  
  Check For Missing Data or NA Values
&lt;/h2&gt;

&lt;p&gt;So in order to do this just type,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df. isna(). sum()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gABCZSDu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lwut2b2p3oyaika009lc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gABCZSDu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lwut2b2p3oyaika009lc.png" alt="Image description" width="344" height="559"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After running the cell I can see the columns name in the left and number for missing values for each column on the right and right every single value is zero so this tells me that this data has no missing values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Show Some Statistics
&lt;/h2&gt;

&lt;p&gt;So, to show some statistics just type here,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df.describe()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--otD5p3q5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iap1ssh9zqbqdnxz9eg5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--otD5p3q5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iap1ssh9zqbqdnxz9eg5.png" alt="Image description" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here we get some statistics on the data set. So immediately we can see that the maximum tenure was 72 months which is about six years and the minimum tenure was zero months and the mean tenure was 32 points months. Now the maximum monthly charges was 118 dollars with some points for a customer and minimum monthly charge  was 18 dollars 250000 cents for a customer  and the mean was 64.761692 dollars for the customers&lt;/p&gt;

&lt;h2&gt;
  
  
  Get Customer Churn Count
&lt;/h2&gt;

&lt;p&gt;My first question is, how many people are churning and how many people are not churning or being retained and stained. So, in order to get that count I just have to type,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df['Churn'] . value_counts()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xvDbPyxV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7tjf1cssxwn2ql3d3hg9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xvDbPyxV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7tjf1cssxwn2ql3d3hg9.png" alt="Image description" width="433" height="113"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we can see that five thousand one hundred and seventy four customers for this company did not churn and one thousand eight hundred sixty nine customers of this company will churn&lt;/p&gt;

&lt;h2&gt;
  
  
  Visualize he Count of Customer Churn
&lt;/h2&gt;

&lt;p&gt;So in order to this just type,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sns.countplot(df['Churn'])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RT6yL0X6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0iiu9wlqdxa7wwvts407.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RT6yL0X6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0iiu9wlqdxa7wwvts407.png" alt="Image description" width="763" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we can visually see those same counts as bar chart here so it make it little bit more obvious that there are customers that are staying with the company then there are the customer that will left the company.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is The Percentage Of The Customers That Are Leaving?
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;num_retained = df[df.Churn == 'No']. shape[0]
num_Churned = df[df.Churn == 'yes']. shape[0]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#print the percentages of customer that stayed
print( num_retained / (num_retained + num_Churned) * 100, '% of customers stayed with the company.')

#print the percentages of customer that left
print( num_Churned / (num_retained + num_Churned) * 100, '% of customers left with the company.')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;73.0 % of customers stayed with the company.&lt;br&gt;
26.0 % of customers left with the company.&lt;/p&gt;

&lt;p&gt;As we can see that seventy three percent of the customers stayed with the company and 26 percent people left the company. So, this is important because this tells me that if randomly a customer from this data set and if I had to make a guess that if the customer churn or did not churn usually you would have 50/50 chance but based of this data is very unbalanced. So, I would have a better chance of making a guess that customer stayed with the company for every customer that i randomly choose and by the time I’m done going through the whole data set I would get 73 percent of the customers. So, the model that I built must be better than 73 percent.&lt;/p&gt;
&lt;h2&gt;
  
  
  Visualize the Churn Count For Both Male And Female
&lt;/h2&gt;

&lt;p&gt;Now I want to visualize the churn count for both male and female. So just type,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sns.countplot(x='gender', hue= 'Churn', data = df)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a9BaPsqx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zbfs6j2na1rz3wu0xlm8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a9BaPsqx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zbfs6j2na1rz3wu0xlm8.png" alt="Image description" width="667" height="347"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see there’s doesn’t seem to be a much difference here so it doesn’t look like more males or more females left this company or stay with the company, they seem about even based of this chart. So maybe we don’t want to take a look at the gender to figure out why these customers are the company. I don’t think so gender has anything to do with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Visualize the Churn Count For Internet Service
&lt;/h2&gt;

&lt;p&gt;Now we are going to visualize the churn count for internet service. So just type,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sns.countplot( x='InternetService', hue='Churn', data = df)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RXMFXTUx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6os4brla1lpvex87hwo7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RXMFXTUx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6os4brla1lpvex87hwo7.png" alt="Image description" width="591" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we are getting back something useful so as immediately we can see that the highest number of customer that didn’t churn have dsl internet service and the highest count for the customer that did churn have fiber optic internet service.&lt;br&gt;
Let’s take a look at some of the other columns. So, for this I’m gonna create,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;numerical_features = ['tenure', 'MonthlyCharges']
fig, ax = plt.subplots(1, 2, figsize=(28,8))
df[df.Churn =='No'][numerical_features].hist(bins=20, color='blue', alpha=0.5, ax = ax)
df[df.Churn =='Yes'][numerical_features].hist(bins=20, color='orange', alpha=0.5, ax = ax)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UNFF6Lmq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6rv8uq4ohop6wdcjwvuu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UNFF6Lmq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6rv8uq4ohop6wdcjwvuu.png" alt="Image description" width="800" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, here I’m gonna look at the two columns which are tenure and monthly charges because they are pretty interesting from the beginning and this time I’ve used histogram instead of bar chart. As we can see that most of the customers that are staying have monthly charges somewhere between 20 and about 30 dollars and that’s very obvious by this big amount on the top graph and what we can also see is that the churn count is a lot higher somewhere between 70 and about 100 dollars for monthly charges. So, that’s seems fairly obvious.&lt;br&gt;
And then we’ll look at the tenure and we can see that most of the customer that churn somewhere between zero and about ten months and for the customers that didn’t churn they seem to basically have a higher tenure so it seems to be somewhere between 65 and 72 months. So, the ones that left have a lower tenure and the ones that stayed have a higher tenure.&lt;/p&gt;
&lt;h2&gt;
  
  
  Remove Unnecessary Columns
&lt;/h2&gt;

&lt;p&gt;As I can see that customer ID column will be useless for the model so, let’s get rid of this column from our data set. So, I’ve created some variable as follows;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cleaned_df =df.drop('customerID', axis =1)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Look At the Numbers Of Rows And Columns In Data Set
&lt;/h2&gt;

&lt;p&gt;We can look at the numbers of rows and columns in the data set by running following command;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cleaned_df.shape
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, now I can see that there are seven thousand and forty-three rows still but now there’s only 20 rows where before it was 21 columns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Convert All Of The Non-Numeric Columns To Numeric
&lt;/h2&gt;

&lt;p&gt;Following are the commands to convert non numeric to numeric values;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from sklearn.preprocessing import LabelEncoder

# select only columns with object data types (categorical variables)
cat_cols = cleaned_df.select_dtypes(include=['object']).columns

# convert object data types to categorical codes
for col in cat_cols:
    cleaned_df[col] = cleaned_df[col].astype('category').cat.codes

# convert the remaining numeric columns to float
num_cols = cleaned_df.select_dtypes(include=['float', 'int']).columns
cleaned_df[num_cols] = cleaned_df[num_cols].astype('float')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Show the New Dataset Data Types
&lt;/h2&gt;

&lt;p&gt;Now let’s take a look at the new data set and data types. So, just type;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cleaned_df.dtypes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y5hGhrB2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vv32cvw4nuybqwkimgws.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y5hGhrB2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vv32cvw4nuybqwkimgws.png" alt="Image description" width="330" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So now we can see that all the data types for our dataset are numbers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Show The First Five Rows Of The New Data Set
&lt;/h2&gt;

&lt;p&gt;In this cell I want to show the first five rows our new dataset. So, just type;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cleaned_df.head()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WUfGEaXr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x830em2isugn2eipq2ne.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WUfGEaXr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x830em2isugn2eipq2ne.png" alt="Image description" width="800" height="126"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ni46uEGj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gs9wvs6l7yy0yjfsxhz5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ni46uEGj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gs9wvs6l7yy0yjfsxhz5.png" alt="Image description" width="800" height="234"&gt;&lt;/a&gt;&lt;br&gt;
Now we can see, a sample of the data are all numbers as expected.&lt;/p&gt;
&lt;h2&gt;
  
  
  Scaled the Data
&lt;/h2&gt;

&lt;p&gt;So, I’m gonna create the feature dataset which will be called X and it will be contained all of the columns from DF data except the column churn which is our target.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;X = cleaned_df.drop('Churn', axis= 1) #Feature data set
y = cleaned_df['Churn'] #target data set

X = StandardScaler().fit_transform(X)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Split the Data Into 80% Training And 20% Testing
&lt;/h2&gt;

&lt;p&gt;Here, I’m going to split the data into eighty percent training and twenty percent testing, so let’s create variables as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state = 42)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create the Model
&lt;/h2&gt;

&lt;p&gt;Now let’s create a variable called model and set it equal to logistic regression as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# create the model
model = LogisticRegression()
#train the model
model.fit(x_train, y_train)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;after running these commands, we’ve got following results;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vtjx5wch--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pahn48ob11e7377ogpvm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vtjx5wch--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pahn48ob11e7377ogpvm.png" alt="Image description" width="375" height="92"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the Prediction on the Test Data
&lt;/h2&gt;

&lt;p&gt;In order to make some predictions, let’s create a model and set it equals to as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;predictions = model.predict(x_test)

#print the predictions
print(predictions)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lFCLxPX6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e3kub3naj11qq0zx5c8v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lFCLxPX6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e3kub3naj11qq0zx5c8v.png" alt="Image description" width="472" height="64"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After running the commands and getting above results, obviously we can’t see all of the data from printing it but if you want then you can go one by one and look at each prediction for the test data and compare it with the target test data&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the Precision, Recall, F1-Score
&lt;/h2&gt;

&lt;p&gt;Here I’m going to check the precision, recall and f1-score for our model;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(classification_report(y_test, predictions))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s run this and see how well the model did?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hXeEhW5_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fhxwd9ac9zplbxx5izpi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hXeEhW5_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fhxwd9ac9zplbxx5izpi.png" alt="Image description" width="683" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, now we can see that our model has about 91% recall which is really good and it has 85% precision which is not bad and as an f1-score of 88% which is pretty good because maximum f1-score can be one hundred percent. And it has accuracy of about 82% which is better than the 73% from just guessing. So, this model will be very useful because it’s better than guessing.&lt;/p&gt;

</description>
      <category>churnprediction</category>
      <category>python</category>
      <category>code</category>
      <category>datascience</category>
    </item>
    <item>
      <title>Basic Concepts of Data Analytics</title>
      <dc:creator>Yusra Liaqat</dc:creator>
      <pubDate>Fri, 04 Nov 2022 16:21:59 +0000</pubDate>
      <link>https://forem.com/liaqat_yusra/basic-concepts-of-data-analytics-5ej3</link>
      <guid>https://forem.com/liaqat_yusra/basic-concepts-of-data-analytics-5ej3</guid>
      <description>&lt;h3&gt;
  
  
  Introduction:
&lt;/h3&gt;

&lt;p&gt;In this article we'll be looking at the different concept behind data analytics. It will provide you with the clearer understanding of what data analytics and how it allow you to collect, store, review and analyze data to help derive business decisions through &lt;strong&gt;insights that have been identified.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Who should read this article?&lt;/strong&gt;&lt;br&gt;
This article is written to provide you the foundation to data analytics and is ideal for those looking to become data analyst or data scientist&lt;/p&gt;

&lt;h3&gt;
  
  
  Objectives:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The objectives of this course is to provide you with the understanding of different analytics concepts.&lt;/li&gt;
&lt;li&gt;Data types: including structured, semi structured and unstructured data &lt;/li&gt;
&lt;li&gt;When you should use data analytics within your business&lt;/li&gt;
&lt;li&gt;The process behind running analytics against data&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Introduction to Data Analytics:
&lt;/h3&gt;

&lt;p&gt;In this article, I'll provide you with a basic understanding of different concepts to help you understand the concept behind many of the AWS services and architectures used to implement data analysis.&lt;/p&gt;

&lt;p&gt;Simply speaking, analytics or data analytics is the science of data transformation, transforming data into meaningful information and insights. &lt;br&gt;
Here we refer data as any input you have like a spreadsheet, a CSV file, historic sales information, a database, raw research data, essentially any data that you may have.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqnm1jbi8puakt3wtjhtu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqnm1jbi8puakt3wtjhtu.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With this basic concepts I mind let’s explore a bit more about data analytics concepts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Starts with a question:&lt;/strong&gt;&lt;br&gt;
Everything start with the question to the problem we have, using analytics we want to solve these problems by selecting the right tools to collect or clean the data in an appropriate fashion.&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of data:
&lt;/h3&gt;

&lt;p&gt;As an input for our analytics, we may have data which can be organized into different categories. For example,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Qualitative data&lt;/li&gt;
&lt;li&gt;Quantitative data&lt;/li&gt;
&lt;li&gt;Structured data&lt;/li&gt;
&lt;li&gt;Semi structured data&lt;/li&gt;
&lt;li&gt;Un structured data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are new to these concepts and you don’t hear these terms before then don’t worry ill be explaining next in my article.&lt;br&gt;
In this article we will understand which AWS services can be used in the analytics process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data types:
&lt;/h3&gt;

&lt;p&gt;Here let’s take a little bit about the input. We have two basics data types where the data is organized&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quantitative Data:&lt;/strong&gt;&lt;br&gt;
Quantitative refers to numbers, the amount of certain values, like the number of citizen in a given geographical area.&lt;br&gt;
&lt;em&gt;Example:&lt;/em&gt; no. of students in class = 16&lt;br&gt;
Boys= 8&lt;br&gt;
Girls= 8&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Qualitative data:&lt;/strong&gt;&lt;br&gt;
Qualitative data refers to attributes of the population not expressed in direct numbers but to qualify their attributes like,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Eye color&lt;/li&gt;
&lt;li&gt;Satisfaction level&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Main data types:
&lt;/h3&gt;

&lt;p&gt;We also have three main classifications for the data formats which are following&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structured data:&lt;/strong&gt;&lt;br&gt;
Structured data referred to data with a defined data model like SQL databases, where tables have a fixed DB model and schema. On AWS for example, the RDS or Rational databases services is a complete example of a structured store.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufsdmvzy77ph15ikxu57.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufsdmvzy77ph15ikxu57.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Semi- structured data:&lt;/strong&gt;&lt;br&gt;
In semi structured data we basically have a flexible data model or tagging mechanism that allows a semantic organization and some kind of hierarchy discovery from the data without having the fixed and rigid rules from SQL database. Non- SQL databases can also be structured but usually they are used in flexible way to complement the limitations from Amazon S3 to SQL databases. Amazon DynamoDB allows each record to have a different numbers of columns but gives fixed indexes for searching. This provides a very flexible schema &lt;br&gt;
Eg. Non-sql, XML, JSON and CSV files are good examples of semi-structured data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frmaspl6rtn8zttg30w89.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frmaspl6rtn8zttg30w89.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Unstructured data:&lt;/strong&gt;&lt;br&gt;
And lastly, we have the un structured data where all kind of text information without a data model is classified. Here we have all kind of documents without a proper data model or a schema like;&lt;br&gt;
Books, natural language processing and all sorts of text processing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjx7yl6rfr374d84zf5pk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjx7yl6rfr374d84zf5pk.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Data generation has exploded exponentially in the past decade. We generate data from the moment we wake up to the moment we go to bed or even while sleeping, sensors can be collecting data from our body and environment to improve a series of apps and services. It could be suggested that we are generating too much data much more than we can probably analyze.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff66kvq3qhxnjgxy15h3r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff66kvq3qhxnjgxy15h3r.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;When to use data analytics:&lt;/strong&gt;&lt;br&gt;
To help us define if we need to use data analytics services to find the answers of our problems that are locked within our data. We can look at the different factors&lt;br&gt;
&lt;strong&gt;Volume:&lt;/strong&gt; the first is the volume which refers to the size of the data set or as we usually call it the data size. And size matters in order to decide the right tool to analyze it. Usually, a big data problem will go into scale from gigabits to petabytes of data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fypu2jbew7kpugyor96pj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fypu2jbew7kpugyor96pj.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Velocity:&lt;/strong&gt; There is also what we call the velocity of the data, which indicates how quickly you need to get your answers and is also related to the age of the data. For example, historical records from previous years or real-time alerting and information. This has a great impact on the tools used to analyze the data because, depending on the response time you need, are you comfortable with real-time responses or waiting? By knowing this, we can choose the right tool and technique.&lt;br&gt;
&lt;strong&gt;Variety:&lt;/strong&gt; this refers to the variety of the source data classification; if its structured or unstructured. As often analytic problems will have sources from several types like.&lt;/p&gt;

&lt;p&gt;Business intelligence platform data, blogs, CSV data, texts and any sorts of structured or unstructured data. &lt;/p&gt;

&lt;h3&gt;
  
  
  ANALYTICS TYPES:
&lt;/h3&gt;

&lt;p&gt;The power of analytics grows when we move from batch analytics to real-time   analytics and then to predictive analytics, but as always the problem you are trying to resolve will always dictate the best method. &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Batch analytics: *&lt;/em&gt;  In reporting or BI analysis, data is processed to a job and the results are presented after a period of time. We have years of data in your data warehouse or in log files, in spreadsheets, and we want to find interesting patterns in this data such as potential sales, potential profits, or potential insights from research data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-time analytics:&lt;/strong&gt; When it comes to real-time analytics, we need to get the answers as soon as possible. If you lose time, there can be serious consequences like fast response to security alerts from intrusion detection systems or responses to advertising campaigns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Predictive analytics:&lt;/strong&gt; The last type of data analytics is predictive analytics, which take historical data as an input, it then learn from the history and then leaves us predictions for future behaviors. This is a common case for machine learning like spam detection where based on past behavior we identify malicious messages, predicting and avoiding spam messages. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvryu0ea1gw5ypz1t4p4r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvryu0ea1gw5ypz1t4p4r.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Data analytic process:
&lt;/h3&gt;

&lt;p&gt;First of all, when you have a problem you usually define it as a question to start your journey into the analytics field. With your question ready, you need the source data which is effectively your starting point. This can be a data warehouse database, rational database tables or a NoSQL store, a csv file, books, text files. In short, every readable format can be used as an input. Selecting the input will depend on the answers you are trying to return from your problem or question.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For example:&lt;/strong&gt;&lt;br&gt;
The problem might be to count words in book from Shakespeare or on the other end of the scale, the problem might be to analyze DNA to find patterns.  So the type of problem will dictate the data and also the processing algorithm.&lt;/p&gt;

&lt;p&gt;With your input ready, you need to store it in an accessible place for the tools to then process it, analyze and return the results. The separation using process and analysis is based on the fact that some analytics solutions from AWS will require a previous cleaning or pre-processing from the data for better results and accuracy.&lt;/p&gt;

&lt;p&gt;AWS has structured its portfolio around the collect, store, analyze and visualize the methodology for each step which integrated services to perform each function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9dxnyns07a3orcpfixc9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9dxnyns07a3orcpfixc9.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Collect/ingest:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first step in your analytics process is to collect the data that you want to use as an input. The data collection is also called ingestion which is the act of acquiring data and storing it for later usage. In the data collection, we have different type of ingested data. We can have transactional data which is represented by traditional rational databases, reads and writes. We can  also have file ingestion reading data from file sources such as like logs, texts, CSV files, book contents and so on and you can have also stream data represented by any kind of  streamed content like a clickstream and events on a website, internet of things devices and so on.&lt;br&gt;
The toolset AWS currently offers can ingest data from many different sources. For example; with kinesis streams or firehose we can work easily with streamed data on any source even if they are on-premises.&lt;br&gt;
&lt;strong&gt;Store:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After the data is generated or acquired, we need to store it in an accessible place for AWS. This is usually called a data lake. The big pool where your services go to get the source and to deliver back the results. Amazon S3 is one of the core storage services from AWS. As a highly durable object store integrated seamlessly with all other AWS analytic services for data loading ad store. You can also have data on Amazon RDS if the data has structured format or a Redshift. If it has no fixed data model but a basic structure, we can use DynamoDB, the NoSQL solution from AWS TO STORE IT. And if your data has very infrequent access we can use glacier, the archive service from AWS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analyze/process:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Batch&lt;/li&gt;
&lt;li&gt;Real-time&lt;/li&gt;
&lt;li&gt;Predictive
Remember the right service or tool depends on the type of problem you have and the velocity of your replies. If you can wait for a while or if you need real-time answers to the problems and if you want to predict future behaviors.
&lt;strong&gt;Amazon EMR&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your goal is to provide reports based on &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Batch processing,&lt;/li&gt;
&lt;li&gt; Historical data Analysis&lt;/li&gt;
&lt;li&gt; Identifying patterns on large data sets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you need real-time replies for questions or the results must be displayed on live dashboards, then you might take advantage of stream-based processing with amazon Kinesis, AWS Lambda or Amazon OpenSearch. Kinesis provides streams to load, store and easily consume live stream data and AWS Lambda can protect to theses streams events, executing functions you define.&lt;/p&gt;

&lt;p&gt;For predictive analytics where you need to forecast an event based on historical cases, you might take advantage of Amazon Machine Learning services to build highly available predicting applications. Not forgetting data pipeline which can be used orchestrate all these services. As a frame work for data-driven workflows, data pipeline can be used to automate your database loads and for the visualization aspect to get a nice overview or dashboard from you replies you can use Amazon QuickSight which allows you to create rich visualization from your data.&lt;/p&gt;

&lt;h3&gt;
  
  
  conclusion:
&lt;/h3&gt;

&lt;p&gt;That brings end to this introductory article and now you should have a greater understanding of the Basic concepts behind Data Analytics.&lt;br&gt;
We have covered all the basic concepts of Data Analytics in this article. Thanks for taking the time to read this article. I hope you found it interesting and informative. I hope you understand what is Data Analytics, Analytics types, When you should use data analytics within your business? and The process behind running analytics against data. I hope you enjoy reading this article.&lt;/p&gt;

&lt;p&gt;Please share your feedback with us as well.&lt;br&gt;
Thank YOU!!&lt;/p&gt;

</description>
      <category>dataanalyticconcept</category>
      <category>aws</category>
      <category>bigdataservices</category>
      <category>beginners</category>
    </item>
    <item>
      <title>MySQL Queries: Basics of MySQL</title>
      <dc:creator>Yusra Liaqat</dc:creator>
      <pubDate>Fri, 09 Sep 2022 06:30:22 +0000</pubDate>
      <link>https://forem.com/liaqat_yusra/mysql-queries-basics-of-mysql-6bb</link>
      <guid>https://forem.com/liaqat_yusra/mysql-queries-basics-of-mysql-6bb</guid>
      <description>&lt;h3&gt;
  
  
  In this article, We will explore the basics of MySQL query language for beginners to gain a better understanding of MySQL.
&lt;/h3&gt;

&lt;h2&gt;
  
  
  content:
&lt;/h2&gt;

&lt;p&gt;• Introduction to SQL&lt;br&gt;
• Data and Database&lt;br&gt;
• Table&lt;br&gt;
• SQL basic queries&lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction to MySQL:
&lt;/h2&gt;

&lt;p&gt;Modern society is extremely dependent on data, but in order to manage it effectively, one must be able to master data management. A database and data can only be manipulated if we know the language that this database understands, which SQL is.&lt;br&gt;
As the core of relational databases, SQL is used by most companies around the world because of its enormous popularity.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is SQL?
&lt;/h2&gt;

&lt;p&gt;It is abbreviated as “structured query language”&lt;br&gt;
It is the language used to perform actions as update, retreat, manipulate and store data on rational database.&lt;/p&gt;
&lt;h2&gt;
  
  
  History of SQL:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;SQL was developed at IBM by Donald D. Chamberline and Raymond F. Boyce in the early 1970s.&lt;/li&gt;
&lt;li&gt;It was initially called SEQUEL(Structured English Query Language)&lt;/li&gt;
&lt;li&gt;SQL is a powerful language that uses simple English sentences&lt;/li&gt;
&lt;li&gt;It uses common English words such as select, insert, update and many more to perform&lt;/li&gt;
&lt;li&gt;SQL is declarative language( when you write a query you have to tell what needs to be done&lt;/li&gt;
&lt;li&gt; And you don’t have to worry regarding the flow of query. It will be handled internally by DBMS using.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Features of SQL:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;SQL has well defined standards&lt;/li&gt;
&lt;li&gt;SQL is easy to learn&lt;/li&gt;
&lt;li&gt;With the help of SQL, one can create multiple views&lt;/li&gt;
&lt;li&gt;Probability of code in SQL is a prominent feature&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  What is Data and Database?
&lt;/h1&gt;
&lt;h2&gt;
  
  
  Data:
&lt;/h2&gt;

&lt;p&gt;Data is a collection of facts, figures and values from different sources like as;&lt;br&gt;
Transport, geographical, cultural, scientific, financial, statistical, natural etc.&lt;/p&gt;
&lt;h2&gt;
  
  
  Database:
&lt;/h2&gt;

&lt;p&gt;"Database is allocation where data is stored in certain n formats".&lt;/p&gt;
&lt;h2&gt;
  
  
  Example:
&lt;/h2&gt;

&lt;p&gt;An example is a library that contains a large number of books. Now imagine that the library is a database and these books are the data in it&lt;br&gt;
Like as; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;firstly, data from user is processed&lt;/li&gt;
&lt;li&gt;Next, we converted into meaningful format&lt;/li&gt;
&lt;li&gt;Then stored it as schema &amp;amp; raw data&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Types of Databases in MySQL:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Distributed database&lt;/li&gt;
&lt;li&gt;Object oriented database&lt;/li&gt;
&lt;li&gt;Centralized database&lt;/li&gt;
&lt;li&gt;Operational database&lt;/li&gt;
&lt;li&gt;Graph database&lt;/li&gt;
&lt;li&gt;NoSQL Database&lt;/li&gt;
&lt;li&gt;Cloud database&lt;/li&gt;
&lt;li&gt;Rational database&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  MySQL Popular databases:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Mongo DB&lt;/li&gt;
&lt;li&gt;Words press&lt;/li&gt;
&lt;li&gt;Microsoft axes&lt;/li&gt;
&lt;li&gt;Microsoft SQL Server&lt;/li&gt;
&lt;li&gt;MySQL&lt;/li&gt;
&lt;li&gt;ORACLE&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  How to create a database in MySQL?
&lt;/h1&gt;
&lt;h2&gt;
  
  
  MySQL:
&lt;/h2&gt;

&lt;p&gt;Currently, SQL queries are executed against the MySQL database.&lt;br&gt;
It might be a mystery to you why I use MySQL, but let me explain. It's a workbench database management system, whereas SQL is a language for communicating with databases. In other words, MySQL allows us to communicate with the database by using SQL queries.&lt;br&gt;
Let me explain the first topic to you, which is how to create a database, in the following syntax:&lt;br&gt;
&lt;code&gt;create database edureka;&lt;/code&gt;   (keywords for database creation)&lt;/p&gt;

&lt;p&gt;I am using edureka as the name of my database management system. Click on the lightning icon after selecting this entire statement in MySQL. You can see at the bottom that the database with the name edureka has been created. &lt;/p&gt;
&lt;h2&gt;
  
  
  How to delete a database?
&lt;/h2&gt;

&lt;p&gt;Following that, we will discuss how to delete a database with the following syntax;&lt;/p&gt;
&lt;h3&gt;
  
  
  Drop database edureka; (keywords for database creation)
&lt;/h3&gt;

&lt;p&gt;Select this entire query and click on the lightning icon. So, we can see that database with name edureka has been deleted&lt;/p&gt;
&lt;h2&gt;
  
  
  Table:
&lt;/h2&gt;

&lt;p&gt;Next we are going to discuss table. Well, &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“table is a collection of data in a tabular form”&lt;br&gt;
Table -----&amp;gt; class&lt;br&gt;
Name&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PC_ArSgw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dpbcrtdz8mh6rmezi9t5.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PC_ArSgw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dpbcrtdz8mh6rmezi9t5.PNG" alt="Image description" width="429" height="209"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;"Person" is the name of the table here. Tables must have names when they are created.&lt;/p&gt;
&lt;h2&gt;
  
  
  What are tuples?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Single row of table which contain a single record”, for that relation here we have five tuples in our table.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  What are attributes?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Features of an entity is called attributes.&lt;br&gt;
 And attribute has a name and a data type. Here are four attributes in this table.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Table constraints in MySQL:
&lt;/h2&gt;

&lt;p&gt;Despite the fact that the table stores the data, the data needs to be of a certain format to ensure data integrity. The format of the data needs to be decided at the time of table creation. The constraint must be changed if we want to change it, and we have to delete the table and create a new one with the new constraints.&lt;/p&gt;

&lt;p&gt;So, few of the constraints are following while creating a table in MySQL;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1. Check default&lt;/li&gt;
&lt;li&gt;2. Foreign key&lt;/li&gt;
&lt;li&gt;3. Index&lt;/li&gt;
&lt;li&gt;4. Unique&lt;/li&gt;
&lt;li&gt;5. Primary key&lt;/li&gt;
&lt;li&gt;6. Not null&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  MySQL commands:
&lt;/h1&gt;

&lt;p&gt;MySQL queries with examples are following:&lt;/p&gt;

&lt;p&gt;create a table command in MySQL Workbench?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create table class(
classID int not null auto_increment,
fname varchar(20),
lname varchar(20),
address varchar(30),
city varchar(15),
marks int,
primary key(classID)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(keywords for the creation of table in MySQL)&lt;/p&gt;

&lt;p&gt;So the syntax for select statement is;&lt;br&gt;
&lt;code&gt;Select * from student;&lt;/code&gt;  (key words to display the whole table)&lt;/p&gt;

&lt;p&gt;It is important to ensure that the table name is unique. In a database, there cannot be two tables with the same name. Within the table, we have declared the columns along with their data types. The query must be ended with a semicolon. By clicking the lightning icon, you can now execute this query. As a result, we can see that a table named class has been created.&lt;/p&gt;

&lt;p&gt;And by executing this we can see the table on MySQL console as follows;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Whjxn6S4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n13qwxrv005b385p5weq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Whjxn6S4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n13qwxrv005b385p5weq.png" alt="Image description" width="367" height="179"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Where command in MySQL:
&lt;/h2&gt;

&lt;p&gt;Filtering records is done with it. By using this clause, we can extract only records that meet the specified criteria.&lt;br&gt;
Let's assume the following scenario to demonstrate the where clause.  For example, if I want to display the names of students who are from Sargodha, then my "where" clause query will look like this;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select fname
from class
where city='sargodha';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(key words for where query clause)&lt;br&gt;
Now, select this query and execute it by clicking on the lightning icon. So, this is now our out put.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ct2VwEUP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ged7kbsafmrqilyavmy9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ct2VwEUP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ged7kbsafmrqilyavmy9.png" alt="Image description" width="499" height="251"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  AND Command in MySQL:
&lt;/h2&gt;

&lt;p&gt;This operator displays a record if all the conditions separated by AND Are TRUE.&lt;br&gt;
Now, let’s look at the syntax. &lt;br&gt;
Select column from table where condition1 and condition 2 is true.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select * from student
where fname='yusra' and lname='liaqat';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(key words for AND statement)&lt;br&gt;
And by executing this, I can get the output for the student name yusra liaqat.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1kF7_VT---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6s2ba7pvxgzlmjn38bzm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1kF7_VT---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6s2ba7pvxgzlmjn38bzm.png" alt="Image description" width="450" height="229"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  OR Command in MySQL:
&lt;/h2&gt;

&lt;p&gt;OR operator usually displays a record if any of the condition separated by OR is TRUE.&lt;br&gt;
And the syntax for this is follow;&lt;br&gt;
Select column from table where condition1 or condition 2 is true.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select * from student
where fname='yusra' or lname='liaqat';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(key words for OR statement)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3MfR293G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5x117hnfnp9s2ftxundl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3MfR293G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5x117hnfnp9s2ftxundl.png" alt="Image description" width="497" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  NOT Command in MySQL:
&lt;/h2&gt;

&lt;p&gt;This operator displays a record if the condition/conditions are NOT TRUE.&lt;br&gt;
Like, I want to display the details of student who does not have the first name as zeeshan. To achieve this I am using  OR operator;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Select * from class
Where not fname= ‘zeeeshan’; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(key words for NOT statement)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RbWlV0oe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4i5eaqqgd6k9fq4wnqr5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RbWlV0oe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4i5eaqqgd6k9fq4wnqr5.png" alt="Image description" width="404" height="248"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  INSERT INTO Command in MySQL:
&lt;/h2&gt;

&lt;p&gt;In order to insert any new data into a table, we can use the INSERTY query.&lt;br&gt;
The table name and columns must be specified for that. After that, we need to specify the values. &lt;br&gt;
The syntax for this is as follows;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO  class(fname, lname, address, city, marks)
VALUES(‘ jia’,’nawaz’,#08 mg road’,’multan’,’389); 
Select * from class;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(key words for INSERT INTO statement)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AsNc3KTy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u1q5lj4xc04x70mr53qf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AsNc3KTy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u1q5lj4xc04x70mr53qf.png" alt="Image description" width="421" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  MySQL Data Aggregation functions:
&lt;/h1&gt;

&lt;p&gt;It is a function that groups the values of multiple rows based on certain criteria and writes a single value. We often use aggregate functions with group by and having clauses of the select statement so, we will be discussing them later part of the article.&lt;br&gt;
Aggregate functions are following, so let’s discuss them one by one.&lt;/p&gt;
&lt;h2&gt;
  
  
  MySQL COUNT Command:
&lt;/h2&gt;

&lt;p&gt;This function returns the number of rows that match by specified criteria. So the syntax is as follows;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select count (classID)
from class
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;;  (key words count statement)&lt;/p&gt;

&lt;p&gt;In the output we can see that the count of the student ID is 5&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A3XvIFmr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qpjvnjklpjvw197ru15q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A3XvIFmr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qpjvnjklpjvw197ru15q.png" alt="Image description" width="294" height="186"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  MySQL AVG Command:
&lt;/h1&gt;

&lt;p&gt;This function returns the average value of a numeric column. So the syntax for this is as follows;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select avg (marks)
from class;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(key words for AVG statement)&lt;/p&gt;

&lt;p&gt;LET’S EXECUTE THIS STATEMENT BECAUSE I am trying to find the average marks of students. So average marks of the student is following;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6Ek4HhkX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nb56svuqdklh4xqqsmgn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6Ek4HhkX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nb56svuqdklh4xqqsmgn.png" alt="Image description" width="306" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  MySQL SUM Command:
&lt;/h2&gt;

&lt;p&gt;This function returns the total sum of a numeric column.&lt;br&gt;
And the syntax for it is;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select sum(marks)
from class;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(key words for SUM statement)&lt;/p&gt;

&lt;p&gt;And here, in this example I am trying to the total sum of total marks code by all the students. So, select this query and execute it by clicking on the lightning icon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1hFxH76c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/snjzs6jhslgsp90yidrq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1hFxH76c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/snjzs6jhslgsp90yidrq.png" alt="Image description" width="369" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  MySQL MIN Command:
&lt;/h2&gt;

&lt;p&gt;This function returns the minimum value of the selected column.&lt;br&gt;
And the syntax for this is follows;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select fname, lname, min(marks)
from class; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(key words for SUM statement)&lt;/p&gt;

&lt;p&gt;And here, in this example we are trying to calculate the minimum marks code by all the students. So, select this query and execute it by clicking on the lightning icon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nkNjVA-i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m7081ti1bn0nylzsdier.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nkNjVA-i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m7081ti1bn0nylzsdier.png" alt="Image description" width="251" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  MySQL MAX Command:
&lt;/h2&gt;

&lt;p&gt;This function returns the maximum value of the selected column.&lt;br&gt;
And the syntax for it is as follows;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select fname, lname, max(marks)
from class;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(key words for SUM statement)&lt;/p&gt;

&lt;p&gt;And here, in this example we are trying to calculate the maximum marks code by all the students. So, select this query and execute it by clicking on the lightning icon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bCtJgfwE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1asutsaw9v49hs0mtszh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bCtJgfwE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1asutsaw9v49hs0mtszh.png" alt="Image description" width="352" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  MySQL GROUP BY Command:
&lt;/h2&gt;

&lt;p&gt;It is used in SQL to arrange identical data into groups with the help of some functions.&lt;br&gt;
For instance, if the column in a table consists of similar data or values in different rows then we can use group by function to group the data and the syntax for this is as follows;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select count(classID), city
from class
group by city;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(key words for GROUP BY statement)&lt;/p&gt;

&lt;p&gt;In this program, I am counting the number of students from different cities, and if there is a student from the same city, the count will be incremented at the end, and the output will have the city name along with the number of students from that city.&lt;br&gt;
 The count of students from different cities is 1, since the students come from different cities, so we can see how effective this query is if the data is large.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lssN4fkj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mhh5xn3otpixq2dpolnb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lssN4fkj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mhh5xn3otpixq2dpolnb.png" alt="Image description" width="281" height="332"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  MySQL HAVING Command:
&lt;/h2&gt;

&lt;p&gt;It is used to decide which group will be included in the final result set based on certain conditions.&lt;br&gt;
Because the where keyword could not be used with aggregate functions like sum, count, min, max, and so on, SQL added the HAVING clause. The syntax for this is as follows;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Select fname, sum(marks)
From class
Group by fname
Having sum(marks)&amp;gt;400;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(key words for HAVING statement)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZxDadPog--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1ne0bioy3sk77wund5d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZxDadPog--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1ne0bioy3sk77wund5d.png" alt="Image description" width="356" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  MySQL ORDER BY Command:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Ascending or descending results are sorted using this keyword.&lt;/li&gt;
&lt;li&gt;By default, the order by keyword will sort the records ascending or descending.&lt;/li&gt;
&lt;li&gt;Let me now explain the syntax by selecting and executing these key words.&lt;/li&gt;
&lt;li&gt;The names of cities should be arranged in descending order based on their starting alphabets, for example.  The same process will be repeated for asec order, except only the word will be exchanged with the desc.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Select count(classID), city
From class
Group by city
Order by city desc;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(key words for ORDER BY statement)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_HFPZBEb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lp18hd34zdje53y1jjx5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_HFPZBEb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lp18hd34zdje53y1jjx5.png" alt="Image description" width="342" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  MySQL UPDATE command:
&lt;/h2&gt;

&lt;p&gt;The update command is used to modify rows in a table.&lt;br&gt;
Now let’s look at the syntax for update statement&lt;br&gt;
Here, I want to change the name of student with student ID 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Update class
Set fname = ‘Amar’, lname = ‘Kumar’
Where classID = 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(key words for UPDATE statement)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Yuoxi9bc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uipm20zp7ljtvehv6rao.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Yuoxi9bc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uipm20zp7ljtvehv6rao.png" alt="Image description" width="382" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  MySQL DELETE command:
&lt;/h2&gt;

&lt;p&gt;The SQL delete command is used to delete rows that are no longer required from the database tables&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Delete from student
Where city = ‘sargodha’;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(key words for delete statement)&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;We have covered all the basic concepts of MySQL in this article. Thanks for taking the time to read this article. I hope you found it interesting and informative. I hope you understand what MySQL data, a database, a table, and some basic SQL queries are. while executing these queries,  I hope you guys have a lot of fun.&lt;br&gt;
Please share your feedback with us as well.&lt;br&gt;
Thank YOU!!&lt;/p&gt;

</description>
      <category>mysql</category>
      <category>sql</category>
      <category>database</category>
      <category>datascience</category>
    </item>
  </channel>
</rss>
