- Machine Learning with Spark(Second Edition)
- Rajdeep Dua Manpreet Singh Ghotra Nick Pentreath
- 202字
- 2021-07-09 21:07:52
Plotting
In this segment, we will see how to use Breeze to create a simple line plot from the Breeze DenseVector.
Breeze uses most of the functionality of Scala's plotting facilities, although the API is different. In the following example, we create two vectors x1 and y with some values, and plot a line and save it to a PNG file:
package linalg.plot
import breeze.linalg._
import breeze.plot._
object BreezePlotSampleOne {
def main(args: Array[String]): Unit = {
val f = Figure()
val p = f.subplot(0)
val x = DenseVector(0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8)
val y = DenseVector(1.1, 2.1, 0.5, 1.0,3.0, 1.1, 0.0, 0.5,2.5)
p += plot(x, y)
p.xlabel = "x axis"
p.ylabel = "y axis"
f.saveas("lines-graph.png")
}
}
The preceding code generates the following Line Plot:

Breeze also supports histogram. This is drawn for various sample sizes 100,000, and 100,0000 normally distributed random numbers into 100 buckets.
package linalg.plot
import breeze.linalg._
import breeze.plot._
object BreezePlotGaussian {
def main(args: Array[String]): Unit = {
val f = Figure()
val p = f.subplot(2, 1, 1)
val g = breeze.stats.distributions.Gaussian(0, 1)
p += hist(g.sample(100000), 100)
p.title = "A normal distribution"
f.saveas("plot-gaussian-100000.png")
}
}

A Gaussian distribution with 1000000 elements is shown in this next image:

A Gaussian distribution with 100 elements
推薦閱讀
- Splunk 7 Essentials(Third Edition)
- Introduction to DevOps with Kubernetes
- OpenStack for Architects
- Managing Mission:Critical Domains and DNS
- Mastering VMware vSphere 6.5
- AWS Administration Cookbook
- 工業(yè)機器人操作與編程
- 云原生架構(gòu)進階實戰(zhàn)
- 激光選區(qū)熔化3D打印技術(shù)
- 基于企業(yè)網(wǎng)站的顧客感知服務(wù)質(zhì)量評價理論模型與實證研究
- R Machine Learning Projects
- Red Hat Enterprise Linux 5.0服務(wù)器構(gòu)建與故障排除
- 軟件需求十步走
- Microsoft 365 Mobility and Security:Exam Guide MS-101
- Mastering Microsoft Dynamics 365 Customer Engagement