Skip to content
Snippets Groups Projects
Commit 6b1bc1af authored by Tobias Hensel's avatar Tobias Hensel
Browse files

Evaluieren eines vorhandenen Models.

parent d7d7f48e
Branches
Tags release-2.0.4
No related merge requests found
"""
@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"\nEvaluation eines gespeicherten Modells:")
print(f"Test-MSE: {mse:.4f}")
print(f"Test-MAE: {mae:.4f}")
# 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("\nBeispielergebnisse:")
print(df_results)
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment