Data Science with Python Certification Time Series Analysis and Forecasting 1 — Questions and Answers
Question 1: Which Python library provides ARIMA and SARIMA models for time series forecasting?
- scikit-learn
- statsmodels (Correct answer)
- matplotlib
- seaborn
Correct answer: statsmodels
The `statsmodels` library provides ARIMA, SARIMA, and other classical time series modeling tools in Python.
Question 2: What does 'stationarity' mean in the context of time series analysis?
- The data has no missing values
- Statistical properties like mean and variance are constant over time (Correct answer)
- The time series has no seasonal pattern
- The data is sorted in ascending order
Correct answer: Statistical properties like mean and variance are constant over time
A stationary time series has a constant mean, variance, and autocorrelation structure that do not change over time.
Question 3: Which test is used to check for stationarity in a time series?
- Shapiro-Wilk test
- Augmented Dickey-Fuller test (Correct answer)
- Levene's test
- Mann-Whitney U test
Correct answer: Augmented Dickey-Fuller test
The Augmented Dickey-Fuller (ADF) test checks for a unit root; a low p-value indicates the series is stationary.
Question 4: How do you parse a date column automatically when reading a CSV file with pandas?
- pd.read_csv(file, date_col='date')
- pd.read_csv(file, parse_dates=['date']) (Correct answer)
- pd.read_csv(file, datetime='date')
- pd.read_csv(file, index_dates=['date'])
Correct answer: pd.read_csv(file, parse_dates=['date'])
The `parse_dates` parameter in `pd.read_csv()` automatically converts specified columns to pandas datetime objects.
Question 5: What does an ACF (Autocorrelation Function) plot show in time series analysis?
- The seasonal decomposition of the series
- The correlation of the series with its own lagged values (Correct answer)
- The trend component of the series
- The residuals after differencing
Correct answer: The correlation of the series with its own lagged values
ACF plots display the correlation between a time series and its lagged versions, helping identify the MA (q) order for ARIMA.
Question 6: In pandas, how do you resample a time series to monthly frequency and compute the mean?
- df.groupby('month').mean()
- df.resample('M').mean() (Correct answer)
- df.rolling('M').mean()
- df.pivot_table(freq='M')
Correct answer: df.resample('M').mean()
`df.resample('M').mean()` resamples a DatetimeIndex time series to monthly buckets and computes each month's mean.
Which Python library provides ARIMA and SARIMA models for time series forecasting?