DelphiLearn PythonPythonPython GUIRAD StudioWindows

What You Need To Add Powerful Statistical And Series Analysis

blog banner statsmodels

Are you looking for an easy yet powerful way to solve Time Series problems and build a nice GUI for them? You can deliver complete Statistical And Time Series Analysis easily by combining statsmodels and Python4Delphi library, inside Delphi and C++Builder IDE software.

This post will guide you on how to run the statsmodels library and use Python for Delphi to display it in the Delphi Windows GUI app.

 

What is time series analysis?

Time Series is an ordered sequence of data points that spread over a period of time. Thus it is a sequence of discrete-time data. The Time Series Data is monitored over constant temporal intervals. This data can be in any measurable and quantifiable parameter related to the field of business, science, finance, etc (for example: Heights of ocean tides, counts of sunspots, the daily closing value of the Dow Jones Industrial Average, etc.).

Time Series Analysis refers to the identification of the common patterns displayed by the data over a period of time. For these tasks, experts employ specific methods to study the data’s characteristics and extract meaningful statistics that eventually aid in forecasting.

Time Series Analysis is beneficial and commonly used for Economic Forecasting, Yield Projection, Inventory Studies, Census Analysis, Sales Forecasting, Stock Market Analysis, Budgetary Analysis, etc.

 

Why use Python for time series analysis?

  1. Python is a general-purpose interpreted programming language (unlike R or Matlab).
  2. Easy to learn and use primarily because it focuses on readability.
  3. It is a popular language in general, consistently appearing in the top 10 programming languages in surveys on StackOverflow (for example, the 2015 survey results).
  4. Python is a dynamic language and very suited to interactive development and quick prototyping with the power to support the development of large applications.
  5. Python is also widely used for Machine Learning and Data Science because of the excellent library support (in this post, you will learn how to implement Machine Learning for Time Series tasks).
  6. It means that you can perform your research and development (figuring out what models to use) in the same programming language that you use in productions, greatly simplifying the transition from development to production.

Read more here, for Why use Python for Scientific Computing:

 

What is the statsmodels library?

statsmodels-logo-v2-horizontal-1222049

statsmodels is a Python module that provides classes and functions for the estimation of many different statistical models, as well as for conducting statistical tests and statistical data exploration. statsmodels provides a complement to SciPy for statistical computations including descriptive statistics and estimation and inference for statistical models.

statsmodels provides an extensive list of result statistics that are available for each estimator. The results are tested against existing statistical packages to ensure that they are correct.

Time series analysis is one of the statistical tools included in the statsmodels library. In this example, we will perform ARMA (Autoregressive Moving Average) to the real dataset, the Sunspots Data.

 

How do I enable statsmodels inside Python4Delphi in Windows?

First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on GitHub. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.

What You Need To Add Powerful Statistical And Series Analysis. Demo project int eh IDE
Open Demo01.dproj

The next step is installing statsmodels into your system. Here is how you can get statsmodels using pip for a stable release, to work with Python4Delphi to create GUI with Statistical And Time Series Analysis capabilities:

 

How do you do time series analysis using Python statsmodels?

Demo for Autoregressive Moving Average (ARMA)

The following is a code example of statsmodels for ARMA modeling for Sunspots dataset (Run this inside the lower Memo of Python4Delphi Demo01 GUI):

Here is the statsmodels for ARMA result in the Python GUI:

What You Need To Add Powerful Statistical And Series Analysis. Sample Plots.
statsmodels Demo with Python4Delphi in Windows.
What You Need To Add Powerful Statistical And Series Analysis. Autocorrelation charts
statsmodels Demo with Python4Delphi in Windows.
What You Need To Add Powerful Statistical And Series Analysis Demo app.
statsmodels Demo with Python4Delphi in Windows.

Last, let’s try our model to make predictions. How good it will be?

Here is the output: The red line is the predicted sunspot activity from 1990 to 2012.

What You Need To Add Powerful Statistical And Series Analysis, Super plot in effect.
statsmodels Demo with Python4Delphi in Windows.

And run the following code to print out the Mean Forecast Error:

What You Need To Add Powerful Statistical And Series Analysis. Python for Windows demo.
statsmodels Demo with Python4Delphi in Windows.

Check out the full source code here!

Congratulations, now you have learned how to run the statsmodels library using Python for Delphi to display it in the Delphi Windows GUI app! Now you can solve various real-world time series problems using the framework created by the statsmodels library and Python4Delphi.

 

Where can I find more examples of building GUI for Scientific Computing libraries?

Check out the statsmodels for statistical and time series analysis framework for Python and use it in your projects: https://www.statsmodels.org/stable/install.html, and

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi: https://github.com/pyscripter/python4delphi

Or read our collections of Scientific Computing articles:

6 Scientific Computing Libs To Empower Your Apps: 

5 Time Series Analysis Libs To Empower Your Apps: 

6 Bioinformatics Libs To Empower Your Apps: 

10 Ultimate Python AI Libraries:

Try these examples now by downloading a free demo copy of Delphi.

close
Related posts
Learn PythonPythonPython GUI

Why It Is Easier to Succeed with Python Coding Software Than You Might Think

Python GUI

A Step-by-Step Guide To Python Scripting For Absolute Beginners

Learn PythonPythonPython GUIVideos

Everything You Need To Create A Python GUI Using Tkinter

IDEPython

The Most Innovative Things Happening with Python Programming Software

Leave a Reply

Your email address will not be published.

en_USEnglish