- Ensemble Machine Learning Cookbook
- Dipayan Sarkar Vijayalakshmi Natarajan
- 267字
- 2021-07-02 13:21:55
There's more...
We have seen a few ways to explore data, both statistically and visually. There are quite a few libraries in Python that you can use to visualize your data. One of the most widely used of these is ggplot. Before we look at a few commands, let's learn how ggplot works.
There are seven layers of grammatical elements in ggplot, out of which, first three layers are mandatory:
- Data
- Aesthetics
- Geometrics
- Facets
- Statistics
- Coordinates
- Theme
You will often start by providing a dataset to ggplot(). Then, you provide an aesthetic mapping with the aes() function to map the variables to the x and y axes. With aes(), you can also set the color, size, shape, and position of the charts. You then add the type of geometric shape you want with functions such as geom_point() or geom_histogram(). You can also add various options, such as plotting statistical summaries, faceting, visual themes, and coordinate systems.
The following code is an extension to what we have used already in this chapter, so we will directly delve into the ggplot code here:
f = pd.melt(housepricesdata, id_vars=['SalePrice'],value_vars= numerical_features[0:9])
ggplot(f,aes('value', 'SalePrice')) + geom_point(color='orange') + facet_wrap('variable',scales='free')
The preceding code generates the following chart:

Similarly, in order to view the density plot for the numerical variables, we can execute the following code:
f_1 = pd.melt(housepricesdata, value_vars=numerical_features[0:9])
ggplot(f_1, aes('value')) + geom_density(color="red") + facet_wrap('variable',scales='free')
The plot shows us the univariate density plot for each of our numerical variables. The geom_density() computes and draws a kernel density estimate, which is a smoothed version of the histogram:

- 大學(xué)計算機(jī)基礎(chǔ):基礎(chǔ)理論篇
- 會聲會影X5視頻剪輯高手速成
- TestStand工業(yè)自動化測試管理(典藏版)
- Blockchain Quick Start Guide
- 數(shù)據(jù)庫原理與應(yīng)用技術(shù)學(xué)習(xí)指導(dǎo)
- 自動檢測與轉(zhuǎn)換技術(shù)
- PHP開發(fā)手冊
- Embedded Programming with Modern C++ Cookbook
- Docker High Performance(Second Edition)
- Mastering pfSense
- C++程序設(shè)計基礎(chǔ)(上)
- 傳感器與自動檢測
- 人工智能云平臺:原理、設(shè)計與應(yīng)用
- Machine Learning in Java
- 人工智能基礎(chǔ)