(
x_data: np.ndarray, y_data: np.ndarray, title: str, xlabel: str, ylabel: str, output_path: Path
)
| 355 | |
| 356 | |
| 357 | def create_scatterplot( |
| 358 | x_data: np.ndarray, y_data: np.ndarray, title: str, xlabel: str, ylabel: str, output_path: Path |
| 359 | ): |
| 360 | if len(x_data) == 0 or len(y_data) == 0: |
| 361 | return |
| 362 | |
| 363 | fig, ax = plt.subplots(figsize=(10, 6)) |
| 364 | |
| 365 | ax.scatter(x_data, y_data, alpha=0.6, color="blue", edgecolors="black") |
| 366 | |
| 367 | X = x_data.reshape(-1, 1) |
| 368 | model = LinearRegression() |
| 369 | model.fit(X, y_data) |
| 370 | y_pred = model.predict(X) |
| 371 | |
| 372 | slope = model.coef_[0] |
| 373 | r2 = r2_score(y_data, y_pred) |
| 374 | mse = mean_squared_error(y_data, y_pred) |
| 375 | |
| 376 | ax.plot( |
| 377 | x_data, |
| 378 | y_pred, |
| 379 | color="lightblue", |
| 380 | linewidth=2, |
| 381 | label=f"Slope={slope:.4f}, R²={r2:.4f}, MSE={mse:.4f}", |
| 382 | ) |
| 383 | |
| 384 | ax.set_xlabel(xlabel) |
| 385 | ax.set_ylabel(ylabel) |
| 386 | ax.set_title(title) |
| 387 | ax.legend() |
| 388 | ax.grid(True, alpha=0.3) |
| 389 | |
| 390 | plt.tight_layout() |
| 391 | plt.savefig(output_path, dpi=150, bbox_inches="tight") |
| 392 | plt.close() |
| 393 | |
| 394 | |
| 395 | def generate_base_charts(conn: sqlite3.Connection, output_dir: Path, pbar: tqdm): |
no outgoing calls
no test coverage detected