Friday, May 27, 2022
HomeMachinelearningSeaborn library in Python and Machine Learning?

Seaborn library in Python and Machine Learning?

In machine learning, when we are working with the real record at that time to understand it a better way, we need a graph or chart or plot whatever word you say.

In simple words, to draw a graph we had used a matplotlib.

Now here we have another library named seaborn. It also works as a Statical plotting library. So, now the question arises in your mind,

What is the difference between Matplotlib and Matplotlib Pyplot?

Matplotlib, mainly used for basic plotting. Using matplot, you can draw the chart like scatter plots, lines, pies, bars and etc.

But we as humans need some extra every time, so using seaborn you can draw a variety of visualization patterns.

An attractive, effective, and informative data visualization is a key ingredient for our task.

If the result or record is in a more visualized manner then we can easily grab the user’s attention.

So, let’s start our learning, a lot to know a lot to discuss.

What is seaborn in machine learning?

Seaborn is open source.

Seaborn is built on top of matplotlib for visualization that means seaborn is not a replacement but works as a compliment.

It works well with the panda’s data frame object.

It comes with a built-in theme for styling matplot graph.

It has the functionality to control, manage, customize plot/figure.

How do you use seaborn?


How do I install seaborn?

To work with the seaborn, you need to install it in the terminal with either.

pip install seaborn


Conda install seaborn

If you are using Google collab then directly import the library and you are ready to do it.

import seaborn as sns

How to load dataset using seaborn?

Now, we have installed all the necessary library it is time to import the dataset. When we install seaborn some of the important datasets are imported automatically.

How to display all available datasets in seaborn?

To display the name, you need to write this syntax.

print (sns.get_dataset_names()) 

The above line code will return the result which contains the list of all datasets present. Here is the output.

What is a data frame?

In the above line of code, our output is in the form of rectangular grids. One important point here you need to remember is that it is not necessary for the data frame to hold/contain values of the same data type. It can be logical, numeric, character, etc.

Here is an example of the ‘tips’ dataset.

dataframe = sns.load_dataset('tips')

print (dataframe.head())

How to set seaborn style?

First of all, let’s run the code as shown below

To work with seaborn, use the set () function.

Now let’s talk about the style, to customize the style, we need to pass some parameters. To check how many parameters available write the line of code as shown below. You will get the list with value.

{'axes.facecolor': '#EAEAF2',
'axes.edgecolor': 'white',
'axes.grid': True,
'axes.axisbelow': True,
'axes.labelcolor': '.15',
'figure.facecolor': 'white',
'grid.color': 'white',
'grid.linestyle': '-',
'text.color': '.15',
'xtick.color': '.15',
'ytick.color': '.15',
'xtick.direction': 'out',
'ytick.direction': 'out',
'lines.solid_capstyle': 'round',
'patch.edgecolor': 'w',
'patch.force_edgecolor': True,
'image.cmap': 'rocket',
'': ['sans-serif'],
'font.sans-serif': ['Arial', 'DejaVu Sans', 'Liberation Sans', 'Bitstream Vera Sans', 'sans-serif'],
'xtick.bottom': False,
'': False,
'ytick.left': False,
'ytick.right': False,
'axes.spines.left': True,
'axes.spines.bottom': True,
'axes.spines.right': True,
'': True}

You can use this parameter and apply the style to your graph. For demo purposes here I have applied a white grid to my grid or canvas.



Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments