-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintame_metric.Rmd
92 lines (77 loc) · 2.4 KB
/
intame_metric.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
title: Intame Losses
author:
- name: Bodo Burger
#affiliation: LMU Munich
#address: >
# First line
# Second line
#email: \email{[email protected]}
#url: http://example.com
#- name: Second Author
#affiliation: Affiliation
date: 2019-03-08
output:
html_document:
toc: yes
github_document:
toc: yes
pdf_document:
toc: yes
urlcolor: blue
#bibliography: "literature.bib"
#link-citations: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = TRUE,
cache = FALSE, cache.path = "cache/intame_metrics")
library("ggplot2")
library("intame")
library("SimilarityMeasures")
theme_set(theme_light())
set.seed(4218)
```
## Overview
Metric Name | Inputs | Range of values | Default theshold | Optimum
-------------- | -------------- | --------------- | ---------------- | --------
R2int | $f$, residuals | $(0, 1)$ | $0.95$ | max
L2 | residuals | $(0, +\infty($ | sd(FE)/5 | min
L1 | residuals | $(0, +\infty($ | sd(FE)/5 | min
Frechet | $f, \hat{f}$ | $(0, +\infty($ | *?* | min
## Formulae
- **R2int**
- **interval**: $1 - \frac{\sum \text{residual}_i^2}{\sum f - \overline{f}}$
- **aggregate**: $\frac{\sum n_k part_k}{\sum n_k}$ (mean weighted by number of points per interval)
- **L2**:
- $\frac{\sum \text{residual}_i^2}{n}$
$\text{residual}_i = f(x_i) - \hat{f}(x_i)$
## Suggest threshold
```{r}
lm.mod = lm(mpg ~ ., data = mtcars)
features_of_interest = c("disp", "hp", "drat", "wt")
suggest_threshold(lm.mod, mtcars, features_of_interest, "R2int", fe_method = "ALE")
st = suggest_threshold(lm.mod, mtcars, features_of_interest, "L1", fe_method = "PD")
st
```
## Frechet Distance
```{r,collapse=TRUE}
x = c(0, 1, 2, 3)
y1 = c(3, 2, 1, 2)
y2 = c(6, 5, 6, 7)
y3 = c(7, 6, 6, 7)
y4 = c(2, 2, 2)
path1 = matrix(c(x, y1-mean(y1)), 4)
path2 = matrix(c(x, y2-mean(y2)+.5), 4)
path3 = matrix(c(x, y3-mean(y3)), 4)
path4 = matrix(c(0, 0, 2, y4-mean(y4)), 3)
plot(path1[,1], path1[,2], type = "l", col = "blue", ylim = c(-3, 3))
lines(path2[,1], path2[,2]+.03, col = "green")
lines(path3[,1], path3[,2], col = "red")
lines(path4[,1], path4[,2], col = "orange")
Frechet(path1, path2)
Frechet(path1, path3)
Frechet(path1, path4)
Frechet(path2, path3)
Frechet(path2, path4)
Frechet(path3, path4)
```