Warum erhalte ich „AttributeError: ‚str‘-Objekt hat kein Attribut ‚value‘“, wenn ich versuche, Darts ExponentialSmoothin
Posted: 11 Jan 2025, 12:08
Hier ist der Code, den ich habe:
Ich erhalte eine Fehlermeldung wie diese:
Der Kontext:
Ich mache Zeitreihenprognosen.
Liegt das an der Methodik, die ich verwende? Den Trainings- und Testdatensatz aufteilen?
Code: Select all
# Define models
models = {
'ExponentialSmoothing': [
ExponentialSmoothing(trend='add', seasonal='add', seasonal_periods=52),
ExponentialSmoothing(trend='add', seasonal='mul', seasonal_periods=12)
],
'SeasonalARIMA': [
ARIMA(p=1, d=1, q=1, seasonal_order=(1, 1, 1, 52)),
ARIMA(p=1, d=1, q=1, seasonal_order=(1, 1, 1, 12))
],
'FFT': [
FFT(nr_freqs_to_keep=10),
FFT(nr_freqs_to_keep=5)
]
}
def evaluate_models(train, test, model_list):
performance = []
for model in model_list:
start_time = time.time()
model.fit(train)
forecast = model.predict(len(test))
end_time = time.time()
# Ensure forecast and test are TimeSeries objects
if not isinstance(forecast, TimeSeries):
raise ValueError(f"Forecast is not a TimeSeries object: {forecast}")
if not isinstance(test, TimeSeries):
raise ValueError(f"Test is not a TimeSeries object: {test}")
performance.append({
'Model': type(model).__name__,
'MAE': mae(test, forecast),
'MSE': mse(test, forecast),
'MASE': mase(test, forecast, train),
'Forecast Bias': (forecast.mean() - test.mean()).values()[0],
'Time Elapsed (s)': end_time - start_time
})
return pd.DataFrame(performance)
# Evaluate weekly data
performance_weekly = {}
for name, model_list in models.items():
performance_weekly[name] = evaluate_models(train_weekly, test_weekly, model_list)
# Evaluate monthly data
performance_monthly = {}
for name, model_list in models.items():
performance_monthly[name] = evaluate_models(train_monthly, test_monthly, model_list)
# Display results
display(pd.concat(performance_weekly.values()))
display(pd.concat(performance_monthly.values()))
Code: Select all
AttributeError: 'str' object has no attribute 'value'
File , line 42
40 performance_weekly = {}
41 for name, model_list in models.items():
---> 42 performance_weekly[name] = evaluate_models(train_weekly, test_weekly, model_list)
44 # Evaluate monthly data
45 performance_monthly = {}
File /local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.11/site-packages/darts/models/forecasting/exponential_smoothing.py:123, in ExponentialSmoothing.fit(self, series)
118 if self.seasonal_periods is None and series.has_range_index:
119 seasonal_periods_param = 12
121 hw_model = hw.ExponentialSmoothing(
122 series.values(copy=False),
--> 123 trend=self.trend if self.trend is None else self.trend.value,
124 damped_trend=self.damped,
125 seasonal=self.seasonal if self.seasonal is None else self.seasonal.value,
126 seasonal_periods=seasonal_periods_param,
127 freq=series.freq if series.has_datetime_index else None,
Ich mache Zeitreihenprognosen.
Liegt das an der Methodik, die ich verwende? Den Trainings- und Testdatensatz aufteilen?