Package: perlib
PerlibThis repository hosts the development of the Perlib library.About PerlibPerlib is a framework written in Python where you can use deep and machine learning algorithms.Perlib isFeature to use many deep or machine learning models easily
Feature to easily generate estimates in a single line with default parameters
Understanding data with simple analyzes with a single line
Feature to automatically preprocess data in a single line
Feature to easily create artificial neural networks
Feature to manually pre-process data, extract analysis or create models with detailed parameters, produce tests and predictionsUsageThe core data structures are layers and models. For quick results with default parameters
To set up more detailed operations and structures, you should use the Perflib functional API, which allows you to create arbitrary layers or write models completely from scratch via subclassing.Installpipinstallperlibfromperlib.forecasterimport*This is how you can use sample datasets.fromperlibimportdatasets# or  from perlib.datasets import *importpandasaspddataset=datasets.load_airpassengers()data=pd.DataFrame(dataset)data.index=pd.date_range(start="2022-01-01",periods=len(data),freq="d")To read your own dataset;importperlibpr=perlib.dataPrepration()data=pr.read_data("./datasets/winequality-white.csv",delimiter=";")model_selector=perlib.ModelSelection(data_l)model_selector.select_model()DimensionReductionAnalysis:Sizereductionisnotrecommended.SelectedModels:1.('BILSTM','Data symmetric, BILSTM is available.')2.('CONVLSTM','There are spatial and temporal patterns, CONVLSTM can be used.')3.('SARIMA','No time series data found, SARIMA is not recommended.')4.('PROPHET','No time series data found, PROPHET is not recommended.')5.('LSTM','Insufficient dataset size, LSTM is not recommended.')6.('LSTNET','Insufficient dataset size, LSTNet is not recommended.')7.('TCN','No temporal dependencies, TCN is not recommended.')8.('XGBoost','No irregular and heterogeneous data, XGBoost is not recommended.')The easiest way to get quick results is with the 'get_result' function.
You can choice modelname ;
"RNN", "LSTM", "BILSTM", "CONVLSTM", "TCN", "LSTNET", "ARIMA" ,"SARIMA" or all machine learning algorithmsforecast,evaluate=get_result(dataFrame=data,y="Values",modelName="Lstnet",dateColumn=False,process=False,forecastNumber=24,metric=["mape","mae","mse"],epoch=2,forecastingStartDate=2022-03-06,verbose=1)ParameterscreatedThemodeltrainingprocesshasbeenstarted.Epoch1/2500/500[==============================]-14s23ms/step-loss:0.2693-val_loss:0.0397Epoch2/2500/500[==============================]-12s24ms/step-loss:0.0500-val_loss:0.0092ModeltrainingprocesscompletedThemodelisbeingsaved1/1[==============================]-0s240ms/step1/1[==============================]-0s16ms/step1/1[==============================]-0s10ms/step1/1[==============================]-0s16ms/stepValuesPredictsDate2022-03-077179.4372632022-03-148484.2829062022-03-219088.0962982022-03-288782.875603MAPE:3.576822717339706forecastPredictsActualDate2022-03-077179.4372632022-03-088484.2829062022-03-099088.0962982022-03-108782.875603evaluate{'mean_absolute_percentage_error':3.576822717339706,'mean_absolute_error':14.02137889193878,'mean_squared_error':3485.26570064559}he Time Series module helps to create many basic models
without using much code and helps to understand which models
work better without any parameter adjustments.fromperlib.piplines.dpiplineimportTimeseriespipline=Timeseries(dataFrame=data,y="Values",dateColumn=False,process=False,epoch=1,forecastingStartDate="2022-03-06",forecastNumber=24,models="all",metrics=["mape","mae","mse"])predictions=pipline.fit()mean_absolute_percentage_error|mean_absolute_error|mean_squared_errorLSTNET14.05|67.70|5990.35LSTM7.03|38.28|2250.69BILSTM13.21|68.22|6661.60CONVLSTM9.62|48.06|2773.69TCN12.03|65.44|6423.10RNN11.53|59.33|4793.62ARIMA50.18|261.14|74654.48SARIMA10.48|51.25|3238.20With the 'summarize' function you can see quick and simple analysis results.summarize(dataFrame=data)With the 'auto' function under 'preprocess', you can prepare the data using general preprocessing.preprocess.auto(dataFrame=data)12-202215:04:36.22-DEBUG-ConversiontoDATETIMEsucceededforfeature"Date"27-12-202215:04:36.23-INFO-CompletedconversionofDATETIMEfeaturesin0.0097seconds27-12-202215:04:36.23-INFO-Startedencodingcategoricalfeatures...Method:"AUTO"27-12-202215:04:36.23-DEBUG-SkippedencodingforDATETIMEfeature"Date"27-12-202215:04:36.23-INFO-Completedencodingofcategoricalfeaturesin0.001252seconds27-12-202215:04:36.23-INFO-Startedfeaturetypeconversion...27-12-202215:04:36.23-DEBUG-ConversiontotypeINTsucceededforfeature"Salecount"27-12-202215:04:36.24-DEBUG-ConversiontotypeINTsucceededforfeature"Day"27-12-202215:04:36.24-DEBUG-ConversiontotypeINTsucceededforfeature"Month"27-12-202215:04:36.24-DEBUG-ConversiontotypeINTsucceededforfeature"Year"27-12-202215:04:36.24-INFO-Completedfeaturetypeconversionfor4feature(s)in0.00796seconds27-12-202215:04:36.24-INFO-Startedvalidationofinputparameters...27-12-202215:04:36.24-INFO-Completedvalidationofinputparameters27-12-202215:04:36.24-INFO-AutoProcessprocesscompletedin0.034259secondsIf you want to build it yourself;fromperlib.core.models.dmodelsimportmodelsfromperlib.core.trainimportdTrainfromperlib.core.testerimportdTesterYou can use many features by calling the 'dataPrepration' function for data preparation operations.data=dataPrepration.read_data(path="./dataset/Veriler/ayakkabÄ±_haftalÄ±k.xlsx")data=dataPrepration.trainingFordate_range(dataFrame=data,dt1="2013-01-01",dt2="2022-01-01")You can use the 'preprocess' function for data preprocessing.data=preprocess.missing_num(dataFrame=data)data=preprocess.find_outliers(dataFrame=data)data=preprocess.encode_cat(dataFrame=data)data=preprocess.dublicates(dataFrame=data,mode="auto")You should create an architecture like below.layers={"unit":[150,100],"activation":["tanh","tanh"],"dropout":[0.2,0.2]}You can set each parameter below it by calling the 'req_info' object.fromperlib.forecasterimportreq_info,dmodelsfromperlib.core.trainimportdTrainfromperlib.core.testerimportdTester#layers = {#        "CNNFilters":100,#        "CNNKernel":6,#        "GRUUnits":50,#        "skip" : 25,#        "highway" : 1#          }req_info.layers=Nonereq_info.modelname="lstm"req_info.epoch=30#req_info.learning_rate = 0.001req_info.loss="mse"req_info.lookback=30req_info.optimizer="adam"req_info.targetCol="Values"req_info.forecastingStartDate="2022-01-06 15:00:00"req_info.period="daily"req_info.forecastNumber=30req_info.scaler="standard"s=dmodels(req_info)It will be prepared after importing it into models.s=models(req_info)After sending the dataframe and the prepared architecture to the dTrain, you can start the training process by calling the .fit() function.train=dTrain(dataFrame=data,object=s)train.fit()After the training is completed, you can see the results by giving the dataFrame,object,path,metric parameters to 'dTester'.t=dTester(dataFrame=data,object=s,path="Data-Lstm-2022-12-14-19-56-28.h5",metric=["mape","mae"])t.forecast()1/1 [==============================] - 0s 21ms/step
1/1 [==============================] - 0s 20ms/step
1/1 [==============================] - 0s 19ms/step
1/1 [==============================] - 0s 20ms/step
1/1 [==============================] - 0s 20ms/step
1/1 [==============================] - 0s 21ms/step
1/1 [==============================] - 0s 20ms/step
1/1 [==============================] - 0s 20ms/step
1/1 [==============================] - 0s 21ms/step
1/1 [==============================] - 0s 21ms/step
1/1 [==============================] - 0s 21ms/step
1/1 [==============================] - 0s 22ms/step
1/1 [==============================] - 0s 21ms/stept.evaluate()MAPE:3.35fromperlib.core.models.smodelsimportmodelsasarmodelsfromperlib.core.trainimportsTrainfromperlib.core.testerimportsTesteraR_info.modelname="sarima"aR_info.forcastingStartDate="2022-6-10"ar=armodels(aR_info)#train = sTrain(dataFrame=data,object=ar)res=train.fit()r=sTester(dataFrame=data,object=ar,path="Data-sarima-2022-12-30-23-49-03.pkl")r.forecast()r.evaluate()fromperlib.core.models.mmodelsimportmodelsfromperlib.core.trainimportmTrainm_info.testsize=.01m_info.y="quality"m_info.modelname="SVR"m_info.auto=Falsem=models(m_info)train=mTrain(dataFrame=data,object=m)preds,evaluate=train.predict()# If you want to make any other data predictions you can use the train.tester# func after train.predict. You can make predictions withpredicts=train.tester(path="Data-SVR-2023-01-08-09-50-37.pkl",testData=data.iloc[:,1:][-20:])