Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Tom Rink
python
Commits
bba60dd4
Commit
bba60dd4
authored
1 month ago
by
rink
Browse files
Options
Downloads
Patches
Plain Diff
add option to pass in absolute tolerance
parent
71490652
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
modules/deeplearning/quantile_regression.py
+6
-40
6 additions, 40 deletions
modules/deeplearning/quantile_regression.py
with
6 additions
and
40 deletions
modules/deeplearning/quantile_regression.py
+
6
−
40
View file @
bba60dd4
...
...
@@ -38,8 +38,7 @@ def make_data(num_points=1000):
return
X_train
,
X_test
,
Y_train
,
Y_test
,
X
,
Y
# Function to create a quantile regression model
def
build_quantile_model
(
q
):
def
build_model
(
loss
=
tf
.
keras
.
losses
.
MeanSquaredError
()):
model
=
tf
.
keras
.
models
.
Sequential
([
tf
.
keras
.
layers
.
InputLayer
(
shape
=
(
1
,)),
tf
.
keras
.
layers
.
Dense
(
64
,
activation
=
'
relu
'
),
...
...
@@ -47,42 +46,9 @@ def build_quantile_model(q):
tf
.
keras
.
layers
.
Dense
(
64
,
activation
=
'
relu
'
),
tf
.
keras
.
layers
.
Dense
(
1
)
# Output layer
])
model
.
compile
(
optimizer
=
'
adam
'
,
loss
=
quantile_
loss
(
q
)
)
model
.
compile
(
optimizer
=
'
adam
'
,
loss
=
loss
)
return
model
def
build_bulk_quantile_model
():
model
=
tf
.
keras
.
models
.
Sequential
([
tf
.
keras
.
layers
.
InputLayer
(
shape
=
(
1
,)),
tf
.
keras
.
layers
.
Dense
(
64
,
activation
=
'
relu
'
),
tf
.
keras
.
layers
.
Dense
(
64
,
activation
=
'
relu
'
),
tf
.
keras
.
layers
.
Dense
(
64
,
activation
=
'
relu
'
),
tf
.
keras
.
layers
.
Dense
(
1
)
# Output layer
])
model
.
compile
(
optimizer
=
'
adam
'
,
loss
=
bulk_quantile_loss
())
return
model
def
build_mae_model
():
model
=
tf
.
keras
.
models
.
Sequential
([
tf
.
keras
.
layers
.
InputLayer
(
shape
=
(
1
,)),
tf
.
keras
.
layers
.
Dense
(
64
,
activation
=
'
relu
'
),
tf
.
keras
.
layers
.
Dense
(
64
,
activation
=
'
relu
'
),
tf
.
keras
.
layers
.
Dense
(
64
,
activation
=
'
relu
'
),
tf
.
keras
.
layers
.
Dense
(
1
)
# Output layer
])
# model.compile(optimizer='adam', loss=tf.keras.losses.MeanSquaredError())
model
.
compile
(
optimizer
=
'
adam
'
,
loss
=
tf
.
keras
.
losses
.
MeanAbsoluteError
())
return
model
def
build_mse_model
():
model
=
tf
.
keras
.
models
.
Sequential
([
tf
.
keras
.
layers
.
InputLayer
(
shape
=
(
1
,)),
tf
.
keras
.
layers
.
Dense
(
64
,
activation
=
'
relu
'
),
tf
.
keras
.
layers
.
Dense
(
64
,
activation
=
'
relu
'
),
tf
.
keras
.
layers
.
Dense
(
64
,
activation
=
'
relu
'
),
tf
.
keras
.
layers
.
Dense
(
1
)
# Output layer
])
model
.
compile
(
optimizer
=
'
adam
'
,
loss
=
tf
.
keras
.
losses
.
MeanSquaredError
())
return
model
def
run
(
num_points
=
1000
,
num_plot_pts
=
200
):
# Define quantiles
...
...
@@ -95,24 +61,24 @@ def run(num_points=1000, num_plot_pts=200):
# Train a model for each quantile
for
q
in
quantiles
:
print
(
f
"
Training quantile
{
q
}
model...
"
)
models
[
q
]
=
build_quantile_
model
(
q
)
models
[
q
]
=
build_
model
(
loss
=
quantile_
loss
(
q
)
)
models
[
q
].
fit
(
X_train
,
Y_train
,
epochs
=
100
,
batch_size
=
32
,
verbose
=
0
)
# Generate test data predictions
X_range
=
np
.
linspace
(
X
.
min
(),
X
.
max
(),
num_plot_pts
).
reshape
(
-
1
,
1
)
predictions
=
{
q
:
models
[
q
].
predict
(
X_range
)
for
q
in
quantiles
}
model
=
build_
mae_
model
()
model
=
build_model
(
loss
=
tf
.
keras
.
losses
.
MeanAbsoluteError
()
)
print
(
f
"
Training MAE model...
"
)
model
.
fit
(
X_train
,
Y_train
,
epochs
=
100
,
batch_size
=
32
,
verbose
=
0
)
mae_predictions
=
model
.
predict
(
X_range
)
model
=
build_
mse_
model
()
model
=
build_model
()
print
(
f
"
Training MSE model...
"
)
model
.
fit
(
X_train
,
Y_train
,
epochs
=
100
,
batch_size
=
32
,
verbose
=
0
)
mse_predictions
=
model
.
predict
(
X_range
)
model
=
build_bulk_quantile_
model
()
model
=
build_
model
(
loss
=
bulk_quantile_
loss
()
)
print
(
f
"
Training bulk quantile model...
"
)
model
.
fit
(
X_train
,
Y_train
,
epochs
=
100
,
batch_size
=
32
,
verbose
=
0
)
bulk_predictions
=
model
.
predict
(
X_range
)
...
...
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