Skip to content

Commit 78c831e

Browse files
CopilotAndreasTraut
andcommitted
Address code review feedback: Add error handling and improve configurability
Co-authored-by: AndreasTraut <55921277+AndreasTraut@users.noreply.github.com>
1 parent 5cdab54 commit 78c831e

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

upgrade2025/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ conda install pandas numpy scikit-learn matplotlib seaborn jupyterlab
8484

8585
### Mit Docker
8686

87-
Ein Docker-Setup für die Spark-Beispiele finden Sie im Hauptverzeichnis des Repositories. Für die "Small Data" Beispiele in diesem Ordner genügt eine lokale Installation.
87+
**Hinweis:** Die Beispiele in diesem `/upgrade2025/` Ordner sind für lokale Ausführung optimiert und benötigen kein Docker.
88+
89+
Ein Docker-Setup für die Spark-Beispiele ("Big Data") finden Sie im Hauptverzeichnis des Repositories. Für die "Small Data" Beispiele in diesem Ordner genügt eine lokale Installation mit Python und den in `requirements.txt` aufgeführten Paketen.
8890

8991
## 📦 Unterstützte Versionen
9092

upgrade2025/Sklearn_MachineLearning_AirBnB_upgrade2025.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
RANDOM_STATE = 42
7676
np.random.seed(RANDOM_STATE)
7777

78+
# Feature-Namen für Extra-Features
79+
REVIEWS_FEATURE = "number_of_reviews"
80+
REVIEWS_PER_MONTH_FEATURE = "reviews_per_month"
81+
7882
# Pfade
7983
PROJECT_ROOT = Path(".")
8084
DATASET_NAME = "AirBnB"
@@ -105,10 +109,16 @@ def save_figure(
105109
path = IMAGES_PATH / f"{prefix}_{fig_id}.{fig_extension}"
106110
logger.info(f"Speichere Figur: {path}")
107111

108-
if tight_layout:
109-
plt.tight_layout()
110-
111-
plt.savefig(path, format=fig_extension, dpi=resolution)
112+
try:
113+
if tight_layout:
114+
plt.tight_layout()
115+
116+
plt.savefig(path, format=fig_extension, dpi=resolution)
117+
logger.info(f"Figur erfolgreich gespeichert: {path}")
118+
except (IOError, OSError) as e:
119+
logger.error(f"Fehler beim Speichern der Figur {path}: {e}")
120+
except Exception as e:
121+
logger.error(f"Unerwarteter Fehler beim Speichern der Figur: {e}")
112122

113123

114124
def load_data(dataset_path: Path = DATASET_PATH) -> pd.DataFrame:
@@ -262,8 +272,8 @@ def add_extra_features(X: np.ndarray, feature_names: list) -> np.ndarray:
262272
"""
263273
# Finde Indizes der benötigten Features
264274
try:
265-
reviews_idx = feature_names.index("number_of_reviews")
266-
reviews_per_month_idx = feature_names.index("reviews_per_month")
275+
reviews_idx = feature_names.index(REVIEWS_FEATURE)
276+
reviews_per_month_idx = feature_names.index(REVIEWS_PER_MONTH_FEATURE)
267277

268278
# Berechne neues Feature
269279
reviews_product = X[:, reviews_idx] * X[:, reviews_per_month_idx]
Binary file not shown.

0 commit comments

Comments
 (0)