Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SaQC
Manage
Activity
Members
Labels
Plan
Issues
36
Issue boards
Milestones
Wiki
Code
Merge requests
8
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rdm-software
SaQC
Commits
1751c8de
Commit
1751c8de
authored
4 years ago
by
Peter Lünenschloß
Browse files
Options
Downloads
Patches
Plain Diff
added cluster reset to flagRegimeAnomaly
parent
e5383d83
No related branches found
Branches containing commit
No related tags found
Tags containing commit
3 merge requests
!193
Release 1.4
,
!188
Release 1.4
,
!138
WIP: Detect and reset offset
Pipeline
#9328
passed with stage
Stage: test
in 6 minutes and 24 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
saqc/funcs/breaks_detection.py
+15
-6
15 additions, 6 deletions
saqc/funcs/breaks_detection.py
with
15 additions
and
6 deletions
saqc/funcs/breaks_detection.py
+
15
−
6
View file @
1751c8de
...
@@ -12,11 +12,11 @@ from saqc.lib.tools import retrieveTrustworthyOriginal, detectDeviants
...
@@ -12,11 +12,11 @@ from saqc.lib.tools import retrieveTrustworthyOriginal, detectDeviants
@register
(
masking
=
'
all
'
)
@register
(
masking
=
'
all
'
)
def
breaks_flagRegimeAnomaly
(
data
,
field
,
flagger
,
cluster_field
,
norm_spread
,
def
breaks_flagRegimeAnomaly
(
data
,
field
,
flagger
,
cluster_field
,
norm_spread
,
linkage_method
=
'
single
'
,
metric
=
lambda
x
,
y
:
np
.
abs
(
np
.
nanmean
(
x
)
-
np
.
nanmean
(
y
)),
metric
=
lambda
x
,
y
:
np
.
abs
(
np
.
nanmean
(
x
)
-
np
.
nanmean
(
y
)),
norm_frac
=
0.5
,
recluster
=
False
,
**
kwargs
):
norm_frac
=
0.5
,
re
set_
cluster
=
False
,
**
kwargs
):
"""
"""
A function to flag values belonging to an anomalous regime of field.
A function to flag values belonging to an anomalous regime
regarding modelling regimes
of field.
"
Normality
"
is determined in terms of a maximum spreading distance, regimes must not exceed in respect
"
Normality
"
is determined in terms of a maximum spreading distance, regimes must not exceed in respect
to a certain metric and linkage method.
to a certain metric and linkage method.
...
@@ -42,13 +42,16 @@ def breaks_flagRegimeAnomaly(data, field, flagger, cluster_field, norm_spread,
...
@@ -42,13 +42,16 @@ def breaks_flagRegimeAnomaly(data, field, flagger, cluster_field, norm_spread,
equal to field)
equal to field)
norm_spread : float
norm_spread : float
A threshold denoting the valuelevel, up to wich clusters a agglomerated.
A threshold denoting the valuelevel, up to wich clusters a agglomerated.
linkage_method : {
"
single
"
,
"
complete
"
,
"
average
"
,
"
weighted
"
,
"
centroid
"
,
"
median
"
,
"
ward
"
}, default
"
single
"
The linkage method used for hierarchical (agglomerative) clustering of the variables.
metric : Callable[[numpy.array, numpy.array], float], default lambda x, y: np.abs(np.nanmean(x) - np.nanmean(y))
metric : Callable[[numpy.array, numpy.array], float], default lambda x, y: np.abs(np.nanmean(x) - np.nanmean(y))
A metric function for calculating the dissimilarity between 2 regimes. Defaults to just the difference in mean.
A metric function for calculating the dissimilarity between 2 regimes. Defaults to just the difference in mean.
norm_frac : float
norm_frac : float
Has to be in [0,1]. Determines the minimum percentage of samples,
Has to be in [0,1]. Determines the minimum percentage of samples,
the
"
normal
"
group has to comprise to be the normal group actually.
the
"
normal
"
group has to comprise to be the normal group actually.
recluster : bool, default False
reset_cluster : bool, default False
If True,
If True, all data, considered
"
normal
"
, gets assigned hte cluster Label
"
0
"
, the
anormal data gets assigned
"
1
"
respectively.
kwargs
kwargs
...
@@ -66,11 +69,17 @@ def breaks_flagRegimeAnomaly(data, field, flagger, cluster_field, norm_spread,
...
@@ -66,11 +69,17 @@ def breaks_flagRegimeAnomaly(data, field, flagger, cluster_field, norm_spread,
clusterser
=
data
[
cluster_field
]
clusterser
=
data
[
cluster_field
]
cluster_num
=
clusterser
.
max
()
+
1
cluster_num
=
clusterser
.
max
()
+
1
cluster_dios
=
dios
.
DictOfSeries
({
i
:
data
[
field
][
clusterser
==
i
]
for
i
in
range
(
cluster_num
)})
cluster_dios
=
dios
.
DictOfSeries
({
i
:
data
[
field
][
clusterser
==
i
]
for
i
in
range
(
cluster_num
)})
plateaus
=
detectDeviants
(
cluster_dios
,
metric
,
norm_spread
,
norm_frac
,
'
single
'
,
'
samples
'
)
plateaus
=
detectDeviants
(
cluster_dios
,
metric
,
norm_spread
,
norm_frac
,
linkage_method
,
'
samples
'
)
for
p
in
plateaus
:
for
p
in
plateaus
:
flagger
=
flagger
.
setFlags
(
field
,
loc
=
cluster_dios
.
iloc
[:,
p
].
index
,
**
kwargs
)
flagger
=
flagger
.
setFlags
(
field
,
loc
=
cluster_dios
.
iloc
[:,
p
].
index
,
**
kwargs
)
if
reset_cluster
:
new_cluster
=
pd
.
Series
(
0
,
index
=
clusterser
.
index
,
dtype
=
int
)
for
p
in
plateaus
:
new_cluster
[
cluster_dios
.
iloc
[:,
p
].
index
]
=
1
data
[
cluster_field
]
=
new_cluster
return
data
,
flagger
return
data
,
flagger
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment