Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FreeForestML
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Benjamin Paul Jaeger
FreeForestML
Commits
6006e28c
Verified
Commit
6006e28c
authored
5 years ago
by
Frank Sauerburger
Browse files
Options
Downloads
Patches
Plain Diff
Improve confusion_matrix example
parent
4dc5e43e
No related branches found
No related tags found
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ConfusionMatrix.ipynb
+35
-21
35 additions, 21 deletions
ConfusionMatrix.ipynb
nnfwtbn/plot.py
+42
-40
42 additions, 40 deletions
nnfwtbn/plot.py
with
77 additions
and
61 deletions
ConfusionMatrix.ipynb
+
35
−
21
View file @
6006e28c
This diff is collapsed.
Click to expand it.
nnfwtbn/plot.py
+
42
−
40
View file @
6006e28c
...
...
@@ -148,43 +148,42 @@ def hist(dataframe, variable, bins, stacks, selection=None,
stack_props
=
props
[
i_stack
]
process_kwds
[
kwd
]
=
stack_props
[
i_process
%
len
(
stack_props
)]
if
"
histtype
"
in
process_kwds
:
if
process_kwds
[
"
histtype
"
]
==
"
points
"
:
del
process_kwds
[
'
histtype
'
]
defaults
=
{
'
markersize
'
:
4
,
'
fmt
'
:
'
o
'
}
defaults
.
update
(
process_kwds
)
process_kwds
=
defaults
n
,
_
=
np
.
histogram
(
variable
(
dataframe
[
sel
(
dataframe
)]),
bins
=
bins
,
range
=
range
,
weights
=
weight
(
dataframe
[
sel
(
dataframe
)]))
bin_centers
=
(
bins
[
1
:]
+
bins
[:
-
1
])
/
2
bin_widths
=
bins
[
1
:]
-
bins
[:
-
1
]
axes
.
errorbar
(
bin_centers
,
bottom
+
n
,
np
.
sqrt
(
n
),
bin_widths
/
2
,
label
=
process
.
label
,
**
process_kwds
)
else
:
n
,
_
,
_
=
axes
.
hist
(
variable
(
dataframe
[
sel
(
dataframe
)]),
bins
=
bins
,
range
=
range
,
bottom
=
bottom
,
label
=
process
.
label
,
weights
=
weight
(
dataframe
[
sel
(
dataframe
)]),
**
process_kwds
)
if
"
histtype
"
in
process_kwds
and
process_kwds
[
"
histtype
"
]
==
"
points
"
:
del
process_kwds
[
'
histtype
'
]
defaults
=
{
'
markersize
'
:
4
,
'
fmt
'
:
'
o
'
}
defaults
.
update
(
process_kwds
)
process_kwds
=
defaults
n
,
_
=
np
.
histogram
(
variable
(
dataframe
[
sel
(
dataframe
)]),
bins
=
bins
,
range
=
range
,
weights
=
weight
(
dataframe
[
sel
(
dataframe
)]))
bin_centers
=
(
bins
[
1
:]
+
bins
[:
-
1
])
/
2
bin_widths
=
bins
[
1
:]
-
bins
[:
-
1
]
axes
.
errorbar
(
bin_centers
,
bottom
+
n
,
np
.
sqrt
(
n
),
bin_widths
/
2
,
label
=
process
.
label
,
**
process_kwds
)
else
:
n
,
_
,
_
=
axes
.
hist
(
variable
(
dataframe
[
sel
(
dataframe
)]),
bins
=
bins
,
range
=
range
,
bottom
=
bottom
,
label
=
process
.
label
,
weights
=
weight
(
dataframe
[
sel
(
dataframe
)]),
**
process_kwds
)
bottom
+=
n
axes
.
set_xlim
((
bins
.
min
(),
bins
.
max
()))
axes
.
set_ylim
((
0
,
axes
.
get_ylim
()[
1
]
*
1.
4
))
axes
.
legend
(
frameon
=
False
)
axes
.
set_ylim
((
0
,
axes
.
get_ylim
()[
1
]
*
1.
6
))
axes
.
legend
(
frameon
=
False
,
loc
=
1
)
if
variable
.
unit
is
not
None
:
axes
.
set_xlabel
(
"
%s in %s
"
%
(
variable
.
name
,
variable
.
unit
),
...
...
@@ -241,21 +240,24 @@ def confusion_matrix(df, x_processes, y_processes, x_label, y_label,
elif
axes
is
None
:
axes
=
figure
.
subplots
()
data
=
{
x_label
:
[],
y_label
:
[],
'
z
'
:
[]}
y_processes
.
reverse
()
data
=
np
.
zeros
((
len
(
y_processes
),
len
(
x_processes
)))
for
i_x
,
x_process
in
enumerate
(
x_processes
):
x_df
=
df
[
x_process
.
selection
(
df
)]
total_weight
=
weight
(
x_df
).
sum
()
for
i_y
,
y_process
in
enumerate
(
y_processes
):
x_y_df
=
x_df
[
y_process
.
selection
(
x_df
)]
data
[
x_label
].
append
(
x_process
.
label
)
data
[
y_label
].
append
(
y_process
.
label
)
data
[
'
z
'
].
append
(
weight
(
x_y_df
).
sum
()
/
total_weight
)
data
[
i_y
][
i_x
]
=
weight
(
x_y_df
).
sum
()
/
total_weight
data
=
pd
.
DataFrame
(
data
)
data
=
data
.
pivot
(
y_label
,
x_label
,
"
z
"
)
data
=
pd
.
DataFrame
(
data
,
columns
=
[
p
.
label
for
p
in
x_processes
],
index
=
[
p
.
label
for
p
in
y_processes
])
sns
.
heatmap
(
data
,
**
dict
(
vmin
=
0
,
vmax
=
1
,
cmap
=
"
Greens
"
,
ax
=
axes
,
cbar_kws
=
{
'
label
'
:
"
$P($%s$|$%s$)$
"
%
(
y_label
,
x_label
)
}
),
**
kwds
)
axes
.
set_xlabel
(
x_label
)
axes
.
set_ylabel
(
y_label
)
return
data
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