Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
BikeSharingLearner
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hensel
BikeSharingLearner
Commits
6b1bc1af
Commit
6b1bc1af
authored
2 months ago
by
Tobias Hensel
Browse files
Options
Downloads
Patches
Plain Diff
Evaluieren eines vorhandenen Models.
parent
d7d7f48e
Branches
Branches containing commit
Tags
release-2.0.4
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
evaluate_model.py
+74
-0
74 additions, 0 deletions
evaluate_model.py
with
74 additions
and
0 deletions
evaluate_model.py
0 → 100644
+
74
−
0
View file @
6b1bc1af
"""
@author: thensel
@date: 2025-05-02
@description: This function contains a validation test for the model, if you dont want to create a new one.
-
"""
# evaluate_model.py
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
sklearn.model_selection
import
train_test_split
from
sklearn.preprocessing
import
StandardScaler
from
sklearn.metrics
import
mean_squared_error
,
mean_absolute_error
import
pandas
as
pd
from
bikes.model
import
BikeSharingModel
from
bikes.data_prep
import
load_dataset
def
main
():
# 1. Daten laden
feature_names
,
data
=
load_dataset
(
"
data/hour.csv
"
)
X
=
data
[:,
:
-
1
]
Y
=
data
[:,
-
1
]
# 2. Split (gleicher Seed wie im Training)
X_train
,
X_test
,
Y_train
,
Y_test
=
train_test_split
(
X
,
Y
,
test_size
=
0.2
,
random_state
=
42
)
# 3. Skalieren (Scaler muss neu fit auf Trainingsdaten)
scaler
=
StandardScaler
()
X_train_scaled
=
scaler
.
fit_transform
(
X_train
)
X_test_scaled
=
scaler
.
transform
(
X_test
)
# 4. Modell laden
model
=
BikeSharingModel
(
input_dim
=
X
.
shape
[
1
])
model
.
load
(
"
models/bikesharing_model.keras
"
)
# 5. Vorhersagen machen
Y_pred
=
model
.
predict
(
X_test_scaled
)
# 6. Evaluation
mse
=
mean_squared_error
(
Y_test
,
Y_pred
)
mae
=
mean_absolute_error
(
Y_test
,
Y_pred
)
print
(
f
"
\n
Evaluation eines gespeicherten Modells:
"
)
print
(
f
"
Test-MSE:
{
mse
:
.
4
f
}
"
)
print
(
f
"
Test-MAE:
{
mae
:
.
4
f
}
"
)
# 7. Visualisierung der Vorhersagen (erste 50)
plt
.
figure
(
figsize
=
(
10
,
4
))
plt
.
plot
(
Y_test
[:
50
],
label
=
"
Tatsächlich
"
)
plt
.
plot
(
Y_pred
[:
50
],
label
=
"
Vorhersage
"
,
linestyle
=
"
dashed
"
)
plt
.
legend
()
plt
.
title
(
"
Modellvorhersagen vs. Tatsächliche Werte
"
)
plt
.
xlabel
(
"
Beispielindex
"
)
plt
.
ylabel
(
"
Anzahl Fahrten (cnt)
"
)
plt
.
grid
(
True
)
plt
.
tight_layout
()
plt
.
show
()
# 8. Als Tabelle ausgeben
df_results
=
pd
.
DataFrame
({
"
Actual
"
:
Y_test
[:
20
],
"
Predicted
"
:
Y_pred
[:
20
]
})
print
(
"
\n
Beispielergebnisse:
"
)
print
(
df_results
)
if
__name__
==
"
__main__
"
:
main
()
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