Spaces:
Sleeping
Sleeping
# Install necessary packages (only for local environment) | |
# !pip install pandas granite-tsfm | |
import pandas as pd | |
from granite_tsfm import TimeSeriesPreprocessor, TinyTimeMixerForPrediction, TimeSeriesForecastingPipeline | |
# Load dataset (Replace with actual dataset) | |
data = pd.read_csv('your_dataset.csv', parse_dates=['timestamp_column']) | |
# Preprocess the data | |
tsp = TimeSeriesPreprocessor( | |
id_columns=[], | |
timestamp_column='timestamp_column', | |
target_columns=['value1', 'value2'], # Replace with your target column names | |
prediction_length=96, | |
context_length=512, | |
scaling=True | |
) | |
processed_data = tsp.fit_transform(data) | |
# Load the pre-trained model | |
model = TinyTimeMixerForPrediction.from_pretrained( | |
'ibm-granite/granite-timeseries-ttm-r2', | |
num_input_channels=tsp.num_input_channels | |
) | |
# Generate forecasts | |
pipeline = TimeSeriesForecastingPipeline( | |
model=model, | |
feature_extractor=tsp | |
) | |
forecasts = pipeline(data) | |
# Display the forecasts | |
print(forecasts) | |