Blogs

Blogs

How to Create and Use Sets in Tableau: Types and Examples

                                                                                                                       Photo by Clay Banks on Unsplash Tableau Sets are used to create subsets of data based on certain conditions defined by the user. It allows you to pick specific segments of a dimension that will generate insights in your data. We can create Sets for just about anything based on quantitative thresholds. A perfect example of why Sets are used is when we want to compare insight from a part of our data, we can accomplish this with a Set. We can do that by selecting our column of interest to make a subset and selecting only a few details we need. Implementing Sets in our dashboard makes it more interactive for the audience. Now, let’s discuss the two types of sets we have and how to create them. Types of Tableau Sets Dynamic Sets Fixed Sets Dynamic Sets: Just as the name suggests, it’s very dynamic, whereby when the value in the dynamic sets changes, the underlying data also changes. This dynamic Set is usually based on a single dimension. How to Create Dynamic Sets Follow each step below to create a Dynamic set in Tableau Desktop. Step 1: Open your Tableau Desktop and bring in the Sample Superstore Dataset, which we will use for demonstration. Step 2: Now, let’s create a Set. Go to your Data Pane, Select the Customer Name Dimensions and click on Create → Set. Step 3: In the “Create Set” window, we have three ways to customize our Set. Let’s discuss this below ; General: The General tab gives users a list of options to select required values from. These selected values will be used in our Set. We can also select the “Use All” option to consider all values always, even when new values are being added or removed. Condition: We also have the condition tab, which we can use to define conditions that determine what values to include in the Set. In the image below, we applied a condition of having values where our Sales is greater than $10,000. Top: Now, the third way of customizing our Set is by using the “Top” tab. The Top tab is used for selecting only specified ’N’ number of top or bottom values. For instance, we can apply a condition of having top 10 customers based on profits, as we have below. Now that we’ve seen how we can create Dynamic Sets, let’s discuss the Fixed Sets and how we can also create them. Fixed Sets: Fixed sets can either be single-dimensional or multi-dimensional. They are sets that do not change and we can create this Set by following the steps listed below; Step 1: Draw a Scatter chat using Profit and Sales. Step 2: In the chart, we’ll select any area(one or more scatter dots) we’re interested in creating a set with. After you’ve highlighted the area, you Right Click and select Create Set. Step 3: Enter the Set’s name in the dialog box and click ok. You should have your Set in the Pane. And that’s how to create Sets in Tableau. Follow the steps above to get started. Hope you found this post helpful. If you do, share and follow for more posts.

Blogs

Automate Your WhatsApp Messages with Python in Minutes

                                                                                                   Photo by Christian Wiediger on Unsplash In this tutorial, we’ll learn how to automate WhatsApp messages with Python programming language. Python, as we know, is a very flexible language utilized by Developers daily in performing different tasks ranging from website and software development to task automation, data analysis, data visualization, game development, embedded applications, and many more. We want to automate our tasks; implementing this will make life easier. We don’t have to be bothered about forgetting to send messages to our loved ones, especially on their Birthdays or any other urgent messages. With Python, we can easily automate our message to be sent at our desired time. The Python library we’ll use in this project is Pywhatkit, a library used for sending WhatsApp messages. It has a lot of dependencies, and various WhatsApp features like sending images and gifs to personal contact or even a group chat. Now, let’s see how we can use this library. This implementation will be done in a step-by-step process. Step 1: Set up a Virtual Environment The first thing we need to do is to set up a virtual environment for our project. We do that to keep our dependencies isolated, whereby we don’t break our system tools. Note: A windows machine is used in implementing this project. 1 #If you don’t have virtualenv you can install with the command 2 pip install virtualenv 3 4 #Create the virtaul environment 5 virtualenv mypython 6 7 #Activate the Virtual Environemt 8 mypthon\Scripts\activate   Step 2: Install Pywhatkit After you’ve activated your virtual environment, what we do next is install the Pywhatkit Library and flask by using the command below; 1 pip install pywhatkit 2 pip install flask   Step 3: Send Message to WhatsApp Contact Here, we’ll demonstrate how to send a message to a particular contact on our WhatsApp App. Before going into that, you must log in to your WhatsApp account using WhatsApp Web. You can use this address WhatsApp Web on your Chrome Desktop. Here is a code to demonstrate how to send our message in seconds. We used the .sendwhatmsg endpoint to pass in our arguments. The first argument, “+xxxxxxxx “is telling us what contact number we want to send our message to, while the “This is our xxxxxx “is the message body we want to send. This “13” is the time in hours, while the next number is time in minutes, and the next one is the time in seconds. The “True” argument indicates we want our WhatsApp tab to be closed automatically in our browser after the message has been delivered. The last argument is the time we want the tab closed in seconds. 1 #import the library 2 import pywhatkit 3 #pass in your arguments here 4 pywhatkit.sendwhatmsg(“+xxxxxxxxx”, “This is our first demo text message with python”, 13, 15, 10, True, 2   Step 4: Send Message to WhatsApp Group We can also send messages to a group chat in Python; to do that, we need the “id” of the group. This will be used in place of a number. You can get the id of your group by clicking the group info → scroll down and click on the invite via link → click on the copy link. Now you will extract the suffix part of the link, which will be the id to use in the code. 1 #import the library 2 import pywhatkit 3 #pass in your arguments here 4 pywhatkit.sendwhatmsg_to_group(“your group id”, “This is our first demo text message with python”, 13, 20, 10, True, 2)   Step 5: Send Images To WhatsApp Contact & Groups You may also want to share images with your contact or group. We can do that using the code below. 1 #import the library 2 import pywhatkit 3 # Send an Image to a Group with the Caption “Check out this image” 4 pywhatkit.sendwhats_image(“your group id”, “Images/Hello.png”, “Check out this image”) 5 6 # Send an Image to your contact with the no Caption 7 pywhatkit.sendwhats_image(“+xxxxxxxxxxx”, “Images/Hello.png”)   Wow! You created your own powerful, database-driven WhatsApp automation tool. To really appreciate Python’s simplicity, you must now give it a try. Hope you enjoyed this post. Thanks for reading.

Blogs

How to Convert Speech to Text in Python

In this tutorial, we’ll learn how to convert speech or an audio file to text format. This very interesting topic has been utilized in different ways such as Business, Content Creation, Bots, and lots more. The Speech Recognition library is an essential library to discuss whenever we’re looking into speech-to-text. Python supports many speech recognition engines and APIs, including the Google Speech Engine, Google Cloud Speech API, IBM Speech to Text, and lots more. Speech recognition can be broken down into three stages: Automatic speech recognition (ASR): This performs the task of transcribing the audio file. Natural language processing (NLP): It works on deriving meaning from the speech data and each text converted. Text-to-speech (TTS): This converts text to human-like speech. Our primary focus here is how we can convert speech to text. We’ll demonstrate in a step-by-step process. Step 1: Install Libraries Here, we’ll install all essential libraries we need in our code to convert speech or audio file to text. The first library we need to install is the Python Speech Recognition Module. We can install it with the command below; 1 pip install speechrecognition   The next library to install is the Pydub library which is very useful for manipulating audio files. You can install it with this command; 1 pip install pydub The last one to install is the Pyaudio Library, which we can install with the command below; 1 pip install pyaudio Step 2: Convert Speech to Text In this code, we’ll use the Speech recognition library to gain access to our Microphone, whereby we’ll speak and this will be converted to text here. The code we used for demonstrating is shown below; 1 #import Library 2 import speech_recognition as sr 3 4 # this will be used to get audio from the microphone 5 v = sr.Recognizer() 6 #Here, we represent our microphone as source 7 with sr.Microphone() as source: 8 print(“Speak:”) 9 #This is where it listens to our speech before going further to recognize it 10 the_audio = v.listen(source) 11 12 try: 13 print(“Your Speech was:” + v.recognize_google(the_audio)) 14 except sr.UnknownValueError: 15 print(“Could not understand audio”)   Output Step 3: Convert Audio Files to Text We converted our speech to text from what we did in the earlier step, but here we will work with an Audio file. To work with our Demo Audio, we’ll use the Pydub library we installed earlier to break our file into smaller pieces. We usually do that for a long Audio file to make the speech recognition library listen well and return accurate text format. The code used is shown below; 1 #we import our libraries here 2 from pydub import AudioSegment 3 from pydub.utils import make_chunks 4 import os 5 import speech_recognition as sr 6 import warnings 7 warnings.filterwarnings(“ignore”) 8 9 def process_audio(filename): 10 #We open a text file here to write in our Audio file that has been converted to text 11 txtf = open(“the_audio.txt”, “w+”) 12 #we use the AudioSegment to open our audio file, this file is in .wav format 13 myaudio = AudioSegment.from_wav(filename) 14 #we specify our chunk length we want to use 15 chunks_length_ms = 7000 16 chunks = make_chunks(myaudio, chunks_length_ms) 17 #Here, we loop through our chunk object, which we already pass our Audio file in and the length 18 for i, chunk in enumerate(chunks): 19 #we save this chunked file individually in a folder in same wav format 20 chunkName = ‘./chunked/’+filename+”_{0}.wav”.format(i) 21 print(‘I am exporting’, chunkName) 22 chunk.export(chunkName, format=”wav”) 23 #From here, we pass in the file individually to be recognized via speech recognition library 24 file = chunkName 25 #we assign an object method from the speech recognition library 26 r = sr.Recognizer() 27 #We make use of the speech recognition library here, listening to each of our files 28 with sr.AudioFile(file) as source: 29 audio_listened = r.listen(source) 30 try: 31 #Here it tries to recognize and convert to text 32 rec = r.recognize_google(audio_listened) 33 #Now, we use our earlier text file we opened and pass in the result of our conversion inside 34 txtf.write(rec+”.”) 35 #This handles error incase, the speech recognition library doesn’t understand your audio 36 except sr.UnknownValueError: 37 print(“I don’t recognize your audio”) 38 except sr.RequestError as e: 39 print(“could not get the result.check your internet”) 40 #we created a folder where all those Audio files broken down will be saved 41 try: 42 os.makedirs(“chunked”) 43 except: 44 pass 45 46 #we call our function here 47 48 process_audio(“hello.wav”) 49 50 51   Follow the steps we highlighted above to start converting your speech to text in Python. Thanks for reading.

Blogs

How to Read Data from API in Power BI

                                                             Photo by Markus Spiske on Unsplash This tutorial will discuss how to read data from API with Power BI. This will be demonstrated step-by-step by bringing in your data and representing it in a tabular form before plotting your visualization. Before going into that, let’s discuss the API and how it works. Application Programming Interface is a server we can use to retrieve and send data using a code, or we can also say it’s a set of programming code that enables data transmission between one software product and another. An API can either be Private or Public(Open). When an API is private, it is only accessible to Developers and users within an organization. Also, when an API is public, external Developers or users have easy access to information available. Good examples of public APIs are; The Google Map API, News API, Weather Forecast API, and lots more. Also, it is excellent to know that API servers send in their responses in JSON format which means you must know to handle your data and extract them neatly. HTTP Methods In Knowing what actions to perform on the Web Service’s resources, the REST APIs usually listen for HTTP methods which are GET, POST, and DELETE. This HTTP method instructs the API on how to handle the resource. Now that we have a good knowledge of what an API is, we can go move further to discuss how we can connect to API with Power BI. Connect to API with Power BI We will use the Open Air Quality (OpenAQ) Api in our Power BI. This API can be found here, and we will use the countries endpoint. Let’s follow the steps below to see how to connect with API in Power BI. Step 1 Open your Power BI Desktop and click Get Data → Web as shown below; Step 2: After you’ve selected the Web, a new window will come up. Here you will see two radio buttons (Basic and Advanced Option). You will select the Advanced button and configure the task. In the URL parts, put the complete URL of the API you want to work with. You can also add a command timeout and a Request header. These are both optional, though. After you’ve done that, click on OK. Step 3 After you’ve selected OK, it opens a new page which is more of an anonymous authentication for connecting. Select the endpoint you want, and click on Connect to bring your data in. Step 4 Your data should be in tabular form, as shown below. For cases whereby your data isn’t in the proper format, you can use Power BI Query Editor to transform your data into your desired format. And that’s how to read data from API with Power BI. Hope you found it helpful; let’s know in the comments section below. Thanks for reading.

Blogs

Why Storytelling in Data Analysis is Important

                                                Photo by Dmitry Ratushny on Unsplash Storytelling with data is one of the effective skills a Data Scientist or Data Analyst must possess. This is simply the act of communicating insights and patterns in data using the data combination, visual or narrative form. Whenever Data Scientist works with a data, his ability to produce high-quality story is crucial. While not just that, forming opinions and arguments about the data is also essential in making key business decisions. Now, let’s discuss why this is a must-have skill for everyone. Why Storytelling with Data is Important With the amount of data available to us, only data storytelling can give human knowledge what the data connotes and some form of coherence. With a compelling story behind the data, we can engage people’s emotions and intellects by creating a deeper understanding of what they need to know. A good example we can relate to is a weather forecaster who provides weather reports. He also issues advanced warnings for potentially severe weathers and hurricanes. Without him providing the viewers an interactive graphics or visuals, there is no way many could have understood his report. It would mean that storytelling on his part was inadequate. These and many numerous reasons are why many organizations put a lot of efforts into data visualization and storytelling because it prevents them from making bad decisions in business. Also, on the part of the Data Scientist, lack of Storytelling reduces the quality of his work which makes decision making a guessing game. Let’s move further and discuss how exactly we can carry out an effective Storytelling for our Data. How to Do Effective Data Storytelling Understand your Audience The major key thing to always consider is the audience we are working with. We must know what they want and the goal/target that needs to be reached. This is also telling us that the inference generated in a data or let’s say a visualization Dashboard communicates well-detailed information to the audience whereby they understand what the content is and also meet up with their business demand. Make Sure your Story is Concise and Transparent When working with your data, you must have a deeper understanding of what you want to do, having that, communicating your result will be much easier. This result must be concise which means you have a well detailed information in few words. The result also has to be transparent enough for the Audience whereby giving them clear necessary details they need. Understand the Whys When communicating your result to the audience, you must understand the whys; this means you must be able to explain factors responsible for market rising and falling in your data. You can also make this interactive by producing numbers in your data which will make your findings solid. Ensure your Story is Clear When presenting to your audience, you also need to be very clear. You should be able to express yourself in a layman’s language which isn’t too technical for them to understand. You also need to be well engaging so that the information you are giving to them can be memorable. Ensure your Story has a Significant Context The context we mentioned here is a very key point all Data Scientist must not do without. Working with context is what builds value from insights generated. This means the result generated provides a sense of clarity and every essential information required. Hope you enjoyed this post. If you do, give it a clap, share, and follow for more educative posts. Thanks for reading.

Blogs

How to use TabPy in Tableau to Predict Customers Churn

                                                                     Photo by Headway on Unsplash Customer churn is a common problem across businesses in many sectors. If you want to grow as a company, you have to invest in acquiring new customers. So, whenever a customer leaves, it’s a significant loss. This means as a business owner you have to invest time and effort in replacing them. The ability to predict when a customer is likely to leave is very important, which is why churn analytics enables organizations to identify and analyze the factors influencing customer churn. Here, we will use Telco Customer Churn dataset to build a machine learning model, which will be used in TabPy for making our predictions. Let’s get started; Step1: Installation You need to have Anaconda on your machine, if you don’t. You can download with the steps below; Visit Anaconda.com/downloads Select Windows Download the .exe installer Open and run the .exe installer Open the Anaconda Prompt and run some Python code to test Step2: Install TabPy & Connect with Tableau Desktop Install TabPy on your Machine and connect with Tableau Desktop; you can visit our previous tutorial on how to do that. Step3: Building the Model Here, our model will be built based on any supervised learning approach model, whereby with our training data , the model gets to capture the relationship between our features and target. We trained our model using Logistic Regression Algorithm. The code is shown below; 1 import pandas as pd 2 import numpy as np 3 import seaborn as sns 4 from matplotlib import pyplot as plt 5 df = pd.read_csv(‘WA_Fn-UseC_-Telco-Customer-Churn.csv’) 6 df.head() 7 df.info() 8 df.describe() 9 df.drop(‘customerID’, axis=1, inplace=True) 10 df.head() 11 df.columns = df.columns.str.lower().str.replace(‘ ‘, ‘_’) 12 df.churn = (df.churn == ‘Yes’).astype(int) 13 df_encoding= pd.get_dummies(df, drop_first=True) 14 categorical = [‘gender’, ‘seniorcitizen’, ‘partner’, ‘dependents’, 15 ‘phoneservice’, ‘multiplelines’, ‘internetservice’, 16 ‘onlinesecurity’, ‘onlinebackup’, ‘deviceprotection’, 17 ‘techsupport’, ‘streamingtv’, ‘streamingmovies’, 18 ‘contract’, ‘paperlessbilling’, ‘paymentmethod’] 19 numerical = [‘tenure’, ‘monthlycharges’, ‘totalcharges’] 20 X = df_encoding.drop(‘churn’, axis=1) 21 # Target 22 y = df_encoding[‘churn’] 23 from sklearn.model_selection import train_test_split 24 X_train_full, X_test, y_train_full, y_test = train_test_split(X, y, test_size=0.2, random_state=1) 25 X_train, X_valid, y_train, y_valid = train_test_split(X_train_full, y_train_full, test_size=0.2, random_state=1) 26 print(“Training Data Size: “, len(y_train)) 27 print(“Validation Data Size: “, len(y_valid)) 28 print(“Testing Data Size: “, len(y_test)) 29 from sklearn.linear_model import LogisticRegression 30 model = LogisticRegression(solver=’liblinear’, random_state=1) 31 model.fit(X_train, y_train) 32 y_val_pred = model.predict_proba(X_valid) 33 y_test_pred = model.predict_proba(X_test) 34 y_test_pred 35 print(‘LogisticRegression Training Accuracy: ‘, round(model.score(X_train, y_train), 2)) 36 print(‘LogisticRegression Validation Accuracy: ‘, round(model.score(X_valid, y_valid), 2)) 37 print(‘LogisticRegression Testing Accuracy: ‘, round(model.score(X_test, y_test), 2))   We were able to generate these scores: 1 array([[0.93961448, 0.06038552], 2 [0.92559415, 0.07440585], 3 [0.69169312, 0.30830688], 4 …, 5 [0.99088494, 0.00911506], 6 [0.81732224, 0.18267776], 7 [0.35925132, 0.64074868]]) 8 LogisticRegression Training Accuracy: 0.87 9 LogisticRegression Validation Accuracy: 0.81 10 LogisticRegression Testing Accuracy: 0.81   The output of logistic regression is usually a probability, which means the probability our observation is positive, or y = 1. For our case, it’s the probability that the customer will churn. It is also possible to look at factors or possible features responsible for this churn in our dataset. We can do that by carrying out a feature importance. Now that we’ve trained our model, we will save it on our machine with pycaret.classification.save_model, for which we can use inside Tableau by passing the link to the location of the file. Step4: Working with Tableau Here, we ensure TabPy is connected with Tableau Desktop. We confirm that by opening http://localhost:9004/ After then, you open a calculated field and put in the code below. Drag this field in the Pane and see your predictions values. 1 SCRIPT_REAL(“import pandas as pd 2 import pycaret.classification 3 the_model=pycaret.classification.load_model (‘C:/Users/Cndro/Downloads/churn_model’) 4 X_pred = pd.DataFrame({‘gender’:_arg1, 5 ‘SeniorCitizen’:_arg2, ‘Partner’:_arg3, 6 ‘Dependents’:_arg4,’tenure’:_arg5, 7 ‘PhoneService’:_arg6, 8 ‘MultipleLines’:_arg7,’InternetService’:_arg8, 9 ‘OnlineSecurity’:_arg9,’OnlineBackup’:_arg10, 10 ‘DeviceProtection’:_arg11, 11 ‘TechSupport’:_arg12,’StreamingTV’:_arg13, 12 ‘StreamingMovies’:_arg14,’Contract’:_arg15, 13 ‘PaperlessBilling’:_arg16,’PaymentMethod’:_arg17, 14 ‘MonthlyCharges’:_arg18,’TotalCharges’:_arg19}) 15 pred = pycaret.classification.predict_model(the_model,X_pred) 16 return pred[‘Label’].tolist()”, 17 ATTR([gender]),ATTR([SeniorCitizen]),ATTR([Partner]), ATTR([Dependents]), 18 ATTR([Tenure]),ATTR([PhoneService]),ATTR([MultipleLines]), ATTR([InternetService]), 19 ATTR([OnlineSecurity]),ATTR([OnlineBackup]), ATTR([DeviceProtection]),ATTR([TechSupport]), 20 ATTR([StreamingTV]),ATTR([StreamingMovies]), ATTR([Contract]),ATTR([PaperlessBilling]), 21 ATTR([PaymentMethod]),ATTR([MonthlyCharges]), ATTR([TotalCharges])   Hope you found this article helpful.  Thanks for reading.

Scroll to Top