Package: metats
MetaTS | Meta-Learning for Global Time Series ForecastingFeatures:Generating meta featuresStatistical features : TsFresh, User defined featuresAutomated feature extraction using Deep Unsupervised Learning : Deep AutoEncoder (MLP, LSTM, GRU, ot custom model)Supporting sktime and darts libraries for base-forecastersProviding a Meta-Learning pipelineQuick StartInstalling the packagepip install metatsGenerating a toy dataset by sampling from two different processesfrommetats.datasetsimportETSDatasetets_generator=ETSDataset({'A,N,N':512,'M,M,M':512},length=30,freq=4)data,labels=ets_generator.load(return_family=True)colors=list(map(lambdax:(x=='A,N,N')*1,labels))Normalizing the time seriesfromsklearn.preprocessingimportStandardScalerscaled_data=StandardScaler().fit_transform(data.T)data=scaled_data.T[:,:,None]Checking How data looks likeimportmatplotlib.pyplotasplt_=plt.plot(data[10,:,0])Generating the meta-featuresStatistical features using TsFreshfrommetats.features.statisticalimportTsFreshstat_features=TsFresh().transform(data)Deep Unsupervised FeaturesTraining an AutoEncoderfrommetats.features.unsupervisedimportDeepAutoEncoderfrommetats.features.deepimportAutoEncoder,MLPEncoder,MLPDecoderenc=MLPEncoder(input_size=1,input_length=30,latent_size=8,hidden_layers=(16,))dec=MLPDecoder(input_size=1,input_length=30,latent_size=8,hidden_layers=(16,))ae=AutoEncoder(encoder=enc,decoder=dec)ae_feature=DeepAutoEncoder(auto_encoder=ae,epochs=150,verbose=True)ae_feature.fit(data)Generating features using the auto-encoderdeep_features=ae_feature.transform(data)Visualizing both statistical and deep meta-featuresDimensionality reduction using UMAP for visualizationfromumapimportUMAPdeep_reduced=UMAP().fit_transform(deep_features)stat_reduced=UMAP().fit_transform(stat_features)Visualizing the statistical features:plt.scatter(stat_reduced[:512,0],stat_reduced[:512,1],c='#e74c3c',label='ANN')plt.scatter(stat_reduced[512:,0],stat_reduced[512:,1],c='#9b59b6',label='MMM')plt.legend()plt.title('TsFresh Meta-Features')_=plt.show()And similarly the auto encoder's featuresplt.scatter(deep_reduced[:512,0],deep_reduced[:512,1],c='#e74c3c',label='ANN')plt.scatter(deep_reduced[512:,0],deep_reduced[512:,1],c='#9b59b6',label='MMM')plt.legend()plt.title('Deep Unsupervised Meta-Features')_=plt.show()Meta-Learning PipelineCreating a meta-learning pipeline with selection strategy:frommetats.pipelineimportMetaLearningpipeline=MetaLearning(method='selection',loss='mse')Adding AutoEncoder features:frommetats.features.unsupervisedimportDeepAutoEncoderfrommetats.features.deepimportAutoEncoder,MLPEncoder,MLPDecoderenc=MLPEncoder(input_size=1,input_length=23,latent_size=8,hidden_layers=(16,))dec=MLPDecoder(input_size=1,input_length=23,latent_size=8,hidden_layers=(16,))ae=AutoEncoder(encoder=enc,decoder=dec)ae_features=DeepAutoEncoder(auto_encoder=ae,epochs=200,verbose=True)pipeline.add_feature(ae_features)You can add as many features as you like:frommetats.features.statisticalimportTsFreshstat_features=TsFresh()pipeline.add_feature(stat_features)Adding two sktime forecaster as base-forecastersfromsktime.forecasting.naiveimportNaiveForecasterfromsktime.forecasting.composeimportmake_reductionfromsklearn.neighborsimportKNeighborsRegressorregressor=KNeighborsRegressor(n_neighbors=1)forecaster1=make_reduction(regressor,window_length=15,strategy="recursive")forecaster2=NaiveForecaster()pipeline.add_forecaster(forecaster1)pipeline.add_forecaster(forecaster2)Specify some meta-learnerfromsklearn.ensembleimportRandomForestClassifierpipeline.add_metalearner(RandomForestClassifier())Training the pipelinepipeline.fit(data,fh=7)Prediction for another set of datapipeline.predict(data,fh=7)About the packageContributorsSasan BarakAmirabbas AsadiWe wish to see your name in the list of contributors, So we are waiting for pull requests!