Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corr plot module #220

Merged
merged 30 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f61a696
fillDiagonal in correlation utils
IKrukov-HORIS Oct 28, 2020
8d5253b
corr.py module
IKrukov-HORIS Oct 28, 2020
879af8a
Removed format parameter
IKrukov-HORIS Oct 28, 2020
fd3d999
Removed _get_format method
IKrukov-HORIS Oct 28, 2020
6927fcd
_tooltip_spec without format parameter
IKrukov-HORIS Oct 28, 2020
4c079ab
flip = True by default
IKrukov-HORIS Oct 28, 2020
d1240b5
flip = True by default
IKrukov-HORIS Oct 28, 2020
53912e8
flip = True by default
IKrukov-HORIS Nov 10, 2020
04bbd2b
_set_diverging_palette renamed to _set_brewer_palette
IKrukov-HORIS Nov 10, 2020
791deef
Using API in build
IKrukov-HORIS Nov 10, 2020
9e6e822
Removed div arg
IKrukov-HORIS Nov 10, 2020
2d0eee9
layers creation deferred till build
IKrukov-HORIS Nov 10, 2020
6dbfcbd
Legend change: Correlation -> Corr
IKrukov-HORIS Nov 11, 2020
4e74f4c
Add fill_scale
IKrukov-HORIS Nov 11, 2020
0f51ad7
tiles implemented via geom_tile
IKrukov-HORIS Nov 11, 2020
f3495e0
Fixed tile implementation.
IKrukov-HORIS Nov 12, 2020
8e4c8e5
Fix height calculation
IKrukov-HORIS Nov 12, 2020
3aabfeb
coord_cartesian when tiles layer is active
IKrukov-HORIS Nov 16, 2020
84d893f
tiles width / height = 0.99
IKrukov-HORIS Nov 17, 2020
663666c
Additive expand 0.5
IKrukov-HORIS Nov 17, 2020
0116ad0
Set fill_diagonal in StatProto
IKrukov-HORIS Nov 17, 2020
7b240e9
Change parameter passing way and some defaults
IKrukov-HORIS Nov 18, 2020
35dda1e
correlation matrix examples
IKrukov-HORIS Nov 18, 2020
709fe1b
Fix typo in methods names
IKrukov-HORIS Nov 18, 2020
ce6aac2
Fix typo in demo
IKrukov-HORIS Nov 18, 2020
25c24b5
Demo layout fix
IKrukov-HORIS Nov 18, 2020
f821be6
brewer palette legend fix
IKrukov-HORIS Nov 19, 2020
80deb81
brewer palette legend fix in demo
IKrukov-HORIS Nov 19, 2020
6eb36e8
brewer palette example update
IKrukov-HORIS Nov 20, 2020
206be8f
add scale_fill_identity for tiles na values
IKrukov-HORIS Nov 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5,505 changes: 5,505 additions & 0 deletions docs/examples/jupyter-notebooks-dev/correlation_matrix.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,27 @@

package jetbrains.datalore.plot.base.stat

import jetbrains.datalore.base.numberFormat.NumberFormat
import jetbrains.datalore.plot.base.Aes
import jetbrains.datalore.plot.base.DataFrame
import jetbrains.datalore.plot.base.StatContext
import jetbrains.datalore.plot.base.stat.CorrelationUtil.correlationMatrix
import jetbrains.datalore.plot.base.stat.math3.correlationPearson
import kotlin.math.abs


class CorrelationStat : BaseStat(DEF_MAPPING) {
var correlationMethod = DEF_CORRELATION_METHOD
var type = DEF_TYPE
var fillDiagonal = DEF_FILL_DIAGONAL

override fun apply(data: DataFrame, statCtx: StatContext, messageConsumer: (s: String) -> Unit): DataFrame {
if (correlationMethod != Method.PEARSON)
throw IllegalArgumentException(
"Unsupported correlation method: $correlationMethod (only pearson is currently available)"
)
require(correlationMethod == Method.PEARSON) {
"Unsupported correlation method: $correlationMethod (only Pearson is currently available)"
}


val cm = correlationMatrix(data, type, ::correlationPearson)
val vals = cm.getNumeric(Stats.CORR)
val abs: List<Double> = vals.map { abs(it!!) }
val cm = correlationMatrix(data, type, fillDiagonal, ::correlationPearson)
val values = cm.getNumeric(Stats.CORR)
val abs: List<Double?> = values.map { it?.let(::abs) }

return cm.builder().putNumeric(Stats.CORR_ABS, abs).build()
}
Expand Down Expand Up @@ -59,6 +58,7 @@ class CorrelationStat : BaseStat(DEF_MAPPING) {

private val DEF_CORRELATION_METHOD = Method.PEARSON
private val DEF_TYPE = Type.FULL

const val FILL_DIAGONAL = "fill_diagonal"
const val DEF_FILL_DIAGONAL = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,25 @@ object CorrelationUtil {
fun correlationMatrix(
data: DataFrame,
type: CorrelationStat.Type,
fillDiagonal: Boolean,
corrfn: (DoubleArray, DoubleArray) -> Double
): DataFrame {
val numerics = data.variables().filter { isNumeric(data, it.name) }

val var1: ArrayList<String> = arrayListOf()
val var2: ArrayList<String> = arrayListOf()
val corr: ArrayList<Double> = arrayListOf()
val corr: ArrayList<Double?> = arrayListOf()

for ((i, vx) in numerics.withIndex()) {

var1.add(vx.label)
var2.add(vx.label)
corr.add(1.0)

if (fillDiagonal) {
corr.add(1.0)
} else {
corr.add(null)
}

val xs = data.getNumeric(vx)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ class CorrelationTest {

val labels2series = mapOf("A" to a, "B" to b, "C" to c)

val cm = correlationMatrix(data, CorrelationStat.Type.FULL, ::correlationPearson)
val cm = correlationMatrix(data, CorrelationStat.Type.FULL, fillDiagonal = true, corrfn = ::correlationPearson)

assertEquals(cm.rowCount(), a.size.ipow(2).toInt())

val v1 : List<String> = cm[Stats.X] as List<String>
val v2 : List<String> = cm[Stats.Y] as List<String>
val cr : List<Double> = cm.getNumeric(Stats.CORR) as List<Double>
val v1: List<String> = cm[Stats.X] as List<String>
val v2: List<String> = cm[Stats.Y] as List<String>
val cr: List<Double> = cm.getNumeric(Stats.CORR) as List<Double>

for ((v12, corr) in v1.zip(v2).zip(cr)) {
val s1 = labels2series[v12.first]
val s2 = labels2series[v12.second]
assertNotNull(s1)
assertNotNull(s2)
assertEquals(corr, correlation( s1, s2, ::correlationPearson))
assertEquals(corr, correlation(s1, s2, ::correlationPearson))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ class StatProto {
}
}

stat.fillDiagonal = OptionsAccessor.over(options)
.getBoolean(CorrelationStat.FILL_DIAGONAL, def = CorrelationStat.DEF_FILL_DIAGONAL)

return stat
}

Expand Down
1 change: 1 addition & 0 deletions python-package/lets_plot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .export import *
from .frontend_context import *
from .settings_utils import *
from .bistro import *

__all__ = (plot.__all__ +
bistro.__all__ +
Expand Down
5 changes: 3 additions & 2 deletions python-package/lets_plot/bistro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Use of this source code is governed by the MIT license that can be found in the LICENSE file.

from .im import *
from .corr import *

__all__ = im.__all__

__all__ = (im.__all__ +
corr.__all__)