Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
KerasROOTClassification
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nikolai.Hartmann
KerasROOTClassification
Commits
64b90646
Commit
64b90646
authored
6 years ago
by
Nikolai.Hartmann
Browse files
Options
Downloads
Patches
Plain Diff
Loading and saving of StandardScaler
parent
2d10bf67
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
toolkit.py
+32
-0
32 additions, 0 deletions
toolkit.py
with
32 additions
and
0 deletions
toolkit.py
+
32
−
0
View file @
64b90646
...
...
@@ -10,13 +10,17 @@ from root_numpy import tree2array, rec2array
import
numpy
as
np
import
pandas
as
pd
import
h5py
from
sklearn.preprocessing
import
StandardScaler
from
sklearn.externals
import
joblib
import
ROOT
class
KerasROOTClassification
:
dataset_names
=
[
"
x_train
"
,
"
x_test
"
,
"
y_train
"
,
"
y_test
"
,
"
w_train
"
,
"
w_test
"
]
def
__init__
(
self
,
name
,
signal_trees
,
bkg_trees
,
branches
,
weight_expr
,
identifiers
,
layers
=
3
,
nodes
=
64
,
out_dir
=
"
./outputs
"
):
...
...
@@ -50,6 +54,9 @@ class KerasROOTClassification:
self
.
s_eventlist_train
=
None
self
.
b_eventlist_train
=
None
self
.
_scaler
=
None
def
load_data
(
self
):
try
:
...
...
@@ -125,6 +132,29 @@ class KerasROOTClassification:
logger
.
info
(
"
Data loaded
"
)
@property
def
scaler
(
self
):
# create the scaler (and fit to training data) if not existent
if
self
.
_scaler
is
None
:
filename
=
os
.
path
.
join
(
self
.
project_dir
,
"
scaler.pkl
"
)
try
:
self
.
_scaler
=
joblib
.
load
(
filename
)
logger
.
info
(
"
Loaded existing StandardScaler from {}
"
.
format
(
filename
))
except
IOError
:
logger
.
info
(
"
Creating new StandardScaler
"
)
self
.
_scaler
=
StandardScaler
()
logger
.
info
(
"
Fitting StandardScaler to training data
"
)
self
.
_scaler
.
fit
(
self
.
x_train
)
joblib
.
dump
(
self
.
_scaler
,
filename
)
return
self
.
_scaler
def
_transform_data
(
self
):
pass
def
_create_model
(
self
):
pass
def
train
(
self
):
pass
...
...
@@ -161,3 +191,5 @@ if __name__ == "__main__":
c
.
load_data
()
print
(
c
.
x_train
)
print
(
len
(
c
.
x_train
))
print
(
c
.
scaler
)
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