<jupyter_start><jupyter_text>Time series Model Example NotebookThis notebook helps in understanding how to use a time series model from DXC Industrialized AI Starter library. In this example we have used monthly sales data. Data source ref: https://raw.githubusercontent.com/jbrownlee/Datasets/master/monthly_champagne_sales.csv<jupyter_code>#Install the DXC_Industrialized-AI-Starter Package.
%%capture
#!pip install DXC-Industrialized-AI-Starter

#or

!pip install git+https://github.com/dxc-technology/DXC-Industrialized-AI-Starter.git<jupyter_output><empty_output><jupyter_text>From DXC-Industrialized-AI-Starter library import dxc-ai package<jupyter_code>from dxc import ai<jupyter_output>[nltk_data] Downloading package punkt to /root/nltk_data...
[nltk_data]   Unzipping tokenizers/punkt.zip.<jupyter_text>Access the raw data<jupyter_code>#reads csv from a url and loads it into a dataframe
csv_url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/monthly_champagne_sales.csv'
raw_data = ai.read_data_frame_from_remote_csv(csv_url, col_names = [], delim_whitespace=False, header = 'infer')
raw_data.head()<jupyter_output><empty_output><jupyter_text>Clean the raw dataThis method imputes missing data, cleans the column headings, removes empty rows and columns<jupyter_code>#clean the data
impute = True
clean_data = ai.clean_dataframe(raw_data, impute)
clean_data.head()<jupyter_output><empty_output><jupyter_text>Explore the raw dataIf you want to explore your data through visualization then you can use the below visulations functions.<jupyter_code>ai.visualize_missing_data(clean_data)
ai.explore_features(clean_data)
ai.plot_distributions(clean_data)<jupyter_output><empty_output><jupyter_text>Run Time series experimentThis function executes an experiment on Time series model. Update experiment_design with parameters that fit your project. The data parameter should be same as the refined training data. The model parameter must be a timeseries. The labels parameter indicates the column of the data dataframe which has time series data. Here defining your meta data is optional. By deafult this model consider last 7 historical values for evaluation of results. Based on those results this model automatically selects best model for your data.<jupyter_code>experiment_design = {
    #model options include ['regression()', 'classification()']
    "model": 'timeseries',
    "labels": clean_data.sales,
    "data": clean_data,
    #Tell the model which column is 'output'
    #Also note columns that aren't purely numerical
    #Examples include ['nlp', 'date', 'categorical', 'ignore']
    "meta_data": {
      "Sales": "output",
      "Month": "date"
  }
}
trained_model = ai.run_experiment(experiment_design, verbose = True)
#Predicting the future results for next 8 instances.
predictions = trained_model.predict(len(clean_data)-8,len(clean_data)+8)
print(predictions)<jupyter_output>[ 4122.46472382  4717.54543353  5156.13160207  4969.38215431
  4741.0957225   1532.67612872  6082.24200573  7281.73079667
 10041.9325823  12871.96309806  4692.51614504  3426.52629856
  3892.99956271  4754.95390661  5253.7296647   5066.28589882
  4818.35584209]<jupyter_text>Visual represntation for model prediction values vs original values<jupyter_code>from matplotlib import pyplot as plt
plt.figure(figsize=(12,8))
plt.plot(list(clean_data['sales'].tail(8)) , color = "blue" , label = "testing data")
plt.plot(predictions, color='red' , label = "prediction")
plt.legend(loc='best')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09060118543607112, 'fraction_numerical': 0.05955405023990968, 'mean_word_length': 6.203252032520325, 'pattern_counts': {'":': 6, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '459175', 'license': 'Apache-2.0', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1122, 'n_words': 308, 'path': 'Examples/Time_series_Model.ipynb', 'repo_name': 'RameshwarGupta97/DXC-Industrialized-AI-Starter', 'size': '3543'}