Last active
May 25, 2024 10:20
-
-
Save dacr/8691088404d627dc2d1c7b8429a4087d to your computer and use it in GitHub Desktop.
smile visualization histograms / published by https://github.com/dacr/code-examples-manager #25fb6f11-ace3-4e58-bc17-16e1e2287da2/2ba83f40e7dd75fe0863af0de26213399ffe5dfc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// summary : smile visualization histograms | |
// keywords : smile, chart, visualization | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : 25fb6f11-ace3-4e58-bc17-16e1e2287da2 | |
// created-on : 2021-03-05T09:23:01Z | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.4.2" | |
//> using dep "com.github.pathikrit::better-files:3.9.2" | |
//> using dep "com.github.haifengl:smile-scala_2.13:3.0.1" | |
//> using dep "org.bytedeco:javacpp-platform:1.5.8" | |
//> using dep "org.bytedeco:javacpp:1.5.8,classifier=linux-x86_64" | |
//> using dep "org.bytedeco:arpack-ng:3.8.0-1.5.8,classifier=linux-x86_64" | |
//> using dep "org.bytedeco:openblas:0.3.21-1.5.8,classifier=linux-x86_64" | |
//> using dep "org.slf4j:slf4j-nop:2.0.7" | |
//> using dep "com.lihaoyi::requests:0.8.0" | |
// --------------------- | |
import better.files.* | |
import smile.stat.distribution.* | |
import smile.math.matrix.* | |
import smile.plot.swing.* | |
import smile.plot.show | |
import smile.plot.Render.* | |
// examples coming from http://haifengl.github.io/visualization.html | |
// -------------------------------------------------------------------- | |
val inputFileName = "cow.txt" | |
val inputFile = inputFileName.toFile | |
if (inputFile.notExists) { | |
val url = "https://gist.githubusercontent.com/dacr/90501dc71a302d1c2b41ffbc17383540/raw/f2531da9031e297943c4b438569f7f60e5348852/cow.txt" | |
for {out <- inputFile.newOutputStream.autoClosed} {requests.get(url).writeBytesTo(out)} | |
} | |
val cowdf = smile.read.csv(inputFileName, header=false) | |
println(cowdf.summary()) | |
val cow = cowdf("V1").toDoubleArray | |
// -------------------------------------------------------------------- | |
implicit val renderer:Canvas=>Unit = JWindow.apply | |
{ | |
val canvas = hist(cow, 50) | |
canvas.setAxisLabels("Weight", "Probability") | |
show(canvas) | |
} | |
// -------------------------------------------------------------------- | |
{ | |
val canvas = hist(cow.filter(_ <= 3500), 50) | |
canvas.setAxisLabels("Weight", "Probability") | |
show(canvas) | |
} | |
// -------------------------------------------------------------------- | |
{ | |
val gauss = new MultivariateGaussianDistribution(Array(0.0, 0.0), Matrix.of(Array(Array(1.0, 0.6), Array(0.6, 2.0)))) | |
val data = (0 until 10000) map { (i: Int) => gauss.rand } | |
show(hist3(data.toArray, 50, 50)) | |
} | |
// -------------------------------------------------------------------- | |
println("enter to exit"); scala.io.StdIn.readLine() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment