# Exercise 3: inverse-rate forecast of a failure time # If 1/rate falls roughly in a straight line, extend the line to zero. days = [0, 1, 2, 3, 4, 5] rates = [10, 12.5, 16.7, 25, 50, 100] # events per hour (invented) inv = [1 / r for r in rates] n = len(days) mean_x = sum(days) / n mean_y = sum(inv) / n slope = sum((x - mean_x) * (y - mean_y) for x, y in zip(days, inv)) / sum((x - mean_x) ** 2 for x in days) intercept = mean_y - slope * mean_x t_zero = -intercept / slope print(f"slope {slope:.4f} per day, 1/rate reaches zero at day {t_zero:.1f}") # slope -0.0186 per day, 1/rate reaches zero at day 5.3 # (the last reading was day 5, so the fit says the trend is about to run out) # The method assumes a smooth, accelerating trend. Real data are noisy and trends can # stall, so the forecast is a range of dates, never a single exact moment.