Code Monkey home page Code Monkey logo

qlik-py-tools's Introduction

Python data science tools for Qlik

Announcements

Version 8.0 has been released. Get it here or with Docker.

This release adds the capability to use pre-trained scikit-learn, Keras or REST API based models with Qlik. More on this here.

Table of Contents

Introduction

Qlik's advanced analytics integration provides a path to making modern data science algorithms accessible to the wider business audience. This project is an attempt to show what's possible.

This repository provides a server side extension (SSE) for Qlik Sense built using Python. The intention is to provide a set of functions for data science that can be used as expressions in Qlik.

Sample Qlik Sense apps are included and explained so that the techniques shown here can be easily replicated.

The current implementation includes:

  • Supervised Machine Learning : Implemented using scikit-learn, the go-to machine learning library for Python. This SSE implements the full machine learning flow from data preparation, model training and evaluation, to making predictions in Qlik.
  • Unsupervised Machine Learning : Also implemented using scikit-learn. This provides capabilities for dimensionality reduction and clustering.
  • Deep Learning : Implemented using Keras and TensorFlow. This SSE implements the full flow of setting up a neural network, training and evaluating it, and using it to make predictions. Deep Learning models can be used for sequence predictions and complex timeseries forecasting.
  • Use of pretrained ML models in Qlik : Pre-trained scikit-learn, Keras and REST API based models can be called from this SSE, allowing predictions to be exposed within the broader analysis and business context of a Qlik app. The implementation also allows for What-if analysis using the models.
  • Named Entity Recognition : Implemented using spaCy, an excellent Natural Language Processing library that comes with pre-trained neural networks. This SSE allows you to use spaCy's models for Named Entity Recognition or retrain them with your data for even better results.
  • Association rules : Implemented using Efficient-Apriori. Association Rules Analysis is a data mining technique to uncover how items are associated to each other. This technique is best known for Market Basket Analysis, but can be used more generally for finding interesting associations between sets of items that occur together, for example, in a transaction, a paragraph, or a diagnosis.
  • Clustering : Implemented using HDBSCAN, a high performance algorithm that is great for exploratory data analysis.
  • Time series forecasting : Implemented using Facebook Prophet, a modern library for easily generating good quality forecasts. Now with the ability to use multiple regressors as input.
  • Seasonality and holiday analysis : Also using Facebook Prophet.
  • Linear correlations : Implemented using Pandas.

Further information on these features is available through the Usage section below.

For more information on Qlik Server Side Extensions see qlik-oss.

Disclaimer: This project has been started by me in a personal capacity and is not supported by Qlik.

Demonstration Videos

Forecasting, Clustering & Supervised Machine Learning:

Demonstration Video 1

Deep Learning & Additional Regressors with Prophet:

Demonstration Video 2

Clustering COVID-19 Literature:

Demonstration Video 3

Note on the approach

In this project we have defined functions that expose open source algorithms to Qlik using the gRPC framework. Each function allows the user to define input data and parameters to control the underlying algorithm's output.

While native Python script evaluation is possible in Qlik as demonstrated in the qlik-oss Python examples, I have disabled this functionality in this project.

I prefer this approach for two key reasons:

  • Separation of the Python implementation from usage in Qlik: App authors in Qlik just need to be able to use the functions, and understand the algorithms at a high level. Any complexity such as handling missing values or scaling the data is abstracted to simple parameters passed in the Qlik expression.
  • Security: This server side extension can not be used to execute arbitrary code from Qlik. Users are restricted to the algorithms exposed through this SSE. Security can be further enhanced by running the SSE on a separate, sandboxed machine, and securing communication with certificates.

Docker Image

A Docker image for qlik-py-tools is available on Docker Hub. If you are familiar with containerisation this is the simplest way to get this SSE running in your environment.

If you want to install this SSE locally on a Windows machine, you can jump to the Pre-requisites section.

To pull the image from Docker's public registry use the command below:

docker pull nabeeloz/qlik-py-tools

The image uses port 50055 by default. You can add encryption using certificates as explained here.

docker run -p 50055:50055 -it nabeeloz/qlik-py-tools

Containers built with this image only retain data while they are running. This means that to persist trained models or log files you will need to add a volume or bind mount using Docker capabilities for managing data.

# Store predictive models to a Docker volume on the host machine
docker run -p 50055:50055 -it -v pytools-models:/qlik-py-tools/models nabeeloz/qlik-py-tools

# Store log files to a bind mount on the host machine
docker run -p 50055:50055 -it -v ~/Documents/logs:/qlik-py-tools/core/logs nabeeloz/qlik-py-tools

# Run a container in detached mode, storing predictive models on a volume and logs on a bind mount
docker run \
    -p 50055:50055 \
    -d \
    -v pytools-models:/qlik-py-tools/models \
    -v ~/Documents/logs:/qlik-py-tools/core/logs \
    nabeeloz/qlik-py-tools
    
# Run a container in detached mode, storing predictive models on a volume , logs on a bind mount and restart the container on reboot
docker run \
    -p 50055:50055 \
    -d \
    --restart unless-stopped \
    -v pytools-models:/qlik-py-tools/models \
    -v ~/Documents/logs:/qlik-py-tools/core/logs \
    nabeeloz/qlik-py-tools

# Run a container in detached mode, restart on reboot, store models and logs to bind mounts, and use certificates for secure communication
docker run \
-p 50055:50055 \
-d \
--restart unless-stopped \
--name qlik-py-tools \
-v ~/sse_PyTools_generated_certs/sse_PyTools_server_certs:/qlik-py-tools/pem-dir \
-v ~/Documents/models:/qlik-py-tools/models \
-v ~/Documents/logs:/qlik-py-tools/core/logs \
nabeeloz/qlik-py-tools python __main__.py --pem_dir=/qlik-py-tools/pem-dir

Pre-requisites

  • Qlik Sense Enterprise or Qlik Sense Desktop
  • Python >= 3.4 <= 3.6.9. The recommended version is 3.6.8.
    • Note: The latest stable version of Python for this SSE is 3.6. The pystan library, which is required for fbprophet, is known to have issues with Python 3.7 on Windows.
  • Microsoft Visual C++ Build Tools

Installation

This installation requires Internet access. To install this SSE on a machine without Internet access refer to the offline installation guide.

  1. Get Python from here. Make sure you get the 64 bit version. Remember to select the option to add Python to your PATH environment variable.

  2. You'll also need a recent C++ compiler as this is a requirement for the pystan library used by fbprophet. One option is to use Microsoft Visual C++ Build Tools. If you are having trouble finding the correct installer try this direct link. An alternative is to use the mingw-w64 compiler as described in the PyStan documentation.

    • If you're using the Visual Studio installer, select the Visual C++ Build Tools workload in the installer and make sure you select the C++ compilers in the optional components:

      C++ Compiler Installation
  3. Download the latest release for this SSE and extract it to a location of your choice. The machine where you are placing this repository should have access to a local or remote Qlik Sense instance.

  4. Right click Qlik-Py-Init.bat and chose 'Run as Administrator'. You can open this file in a text editor to review the commands that will be executed. If everything goes smoothly you will see a Python virtual environment being set up, project files being copied, some packages being installed and TCP Port 50055 being opened for inbound communication.

    • Note that the script always ends with a "All done" message and does not check for errors.
    • If you need to change the port you can do so in the file core\__main__.py by opening the file with a text editor, changing the value of the _DEFAULT_PORT variable, and then saving the file. You will also need to update Qlik-Py-Init.bat to use the same port in the netsh command. This command will only work if you run the batch file through an elevated command prompt (i.e. with administrator privileges).
    • Once the execution completes, do a quick scan of the log to see everything installed correctly. The libraries imported are: grpcio, grpcio-tools, numpy, scipy, pandas, cython, joblib, pyyaml, pystan, fbprophet, scikit-learn, hdbscan, spacy, efficient-apriori, tensorflow, keras and their dependencies. Also, check that the core and generated directories have been copied successfully to the newly created qlik-py-env directory.
    • If the initialization fails for any reason, you can simply delete the qlik-py-env directory and re-run Qlik-Py-Init.bat.
  5. Now whenever you want to start this Python service you can run Qlik-Py-Start.bat.

  6. Now you need to set up an Analytics Connection in Qlik Sense Enterprise or update the Settings.ini file in Qlik Sense Desktop. If you are using the sample apps make sure you use PyTools as the name for the analytics connection, or alternatively, update all of the expressions to use the new name.

    • For Qlik Sense Desktop you need to update the settings.ini file. There may be two copies of this file; one at C:/Users/<User ID>/Documents/Qlik/Sense/ and another at C:/Users/AppData/Local/Programs/Qlik/Sense/Engine. Add the SSE settings to both files.

      QSD Analytics Connection
      SSEPlugin=PyTools,localhost:50055;
      
    • For Qlik Sense Enterprise you need to create an Analytics Connection through QMC:

      QSE Analytics Connection
    • The Analytics Connection can point to a different machine and can be secured with certificates:

      QSE Secure Analytics Connection
  7. Finally restart the Qlik Sense engine service for Qlik Sense Enterprise or close and reopen Qlik Sense Desktop. This step may not be required if you are using Qlik Sense April 2018 and beyond.

    If a connection between Python and Qlik is established you should see the capabilities listed in the terminal.

handshake log Capabilities may change as this is an ongoing project.

Usage

We go into the details of each capability in the sections below.

Sample Qlik Sense apps are provided and each app includes extensive techniques to use this SSE's capabilities in Qlik.

Most of the sample apps require the Dashboard Extension Bundle which was released with Qlik Sense November 2018.

Documentation Sample App Additional App Dependencies
Correlations Correlations None.
Clustering Clustering with HDBSCAN None.
Predictions with pretrained models Predictions with scikit-learn and Keras Follow the pre-requisites and steps in the documentation.

If using Qlik Sense Desktop you will need to download the data source, create a data connection named AttachedFiles in the app, and point the connection to the folder containing the source file.
Machine Learning Train & Test

Predict

K-fold Cross Validation

Parameter Tuning

K-fold CV & Parameter Tuning

Complex Forecasting with scikit-learn
Make sure you reload the K-fold Cross Validation or Train & Test app before using the Predict app.

If using Qlik Sense Desktop you will need to download the data source, create a data connection named AttachedFiles in the app, and point the connection to the folder containing the source file.

The forecasting app is best understood together with the Deep Learning section below. Here we just use more traditional ML algorithms rather than Deep Learning for producing the forecast.

Make sure you reload the app before using the final sheets to make predictions. The data source for this app can be found here.
Deep Learning Complex Forecasting with Keras Make sure you reload the app before using the final two sheets to make predictions.

If using Qlik Sense Desktop you will need to download the data source, create a data connection named AttachedFiles in the app, and point the connection to the folder containing the source file.
Forecasting Facebook Prophet (Detailed)

Facebook Prophet (Simple)

Facebook Prophet (Multiple regressors)
For the detailed app, use the bookmarks to step through the sheets with relevant selections.

For calling Prophet through the load script refer to the simple app. If you want to reload the app using Qlik Sense Desktop you will need to download the data source, create a data connection named AttachedFiles in the app, and point the connection to the folder containing the source file.

For the use of Prophet's additional regressors capability refer to the multiple regressors app. The data for this app is found here.
Named Entity Recognition NER and Association Rules If using Qlik Sense Desktop you will need to download the data sources, create a data connection named AttachedFiles in the app, and point the connection to the folder containing the source files.
Association Rules / Market Basket Analysis NER and Association Rules

Market Basket Analysis
If using Qlik Sense Desktop you will need to download the data sources, create a data connection named AttachedFiles in the app, and point the connection to the folder containing the source files.

Qonnections 2019 Workshop

At Qonnections 2019 we ran hands-on workshops with PyTools and Qlik Sense. The content for these workshops, including the sample apps and exercise intructions, is available here.

The workshop exercises can be used as a tutorial for using this Server Side Extension with Qlik Sense Enterprise or Desktop.

qlik-py-tools's People

Contributors

cleveranjos avatar nabeel-oz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qlik-py-tools's Issues

Error when selecting the CHECK Box for dimensions.

Hi,

Currently, just testing this in the latest desktop version. The visualization with python gives an error when we select a dimension while python is calculating in the background. "Error: Unknown Error".

Steps to recreate:

  1. Select a value from a filter that impacts and triggers the visualization to recompute.
  2. Before the computation is complete, select the green checkbox to confirm the dimension selection.

That's it.

Regards

Integrating with qlikview

Hi Nabeel,

This is great, it works well with Qlik Sense. Thank you for sharing your knowledge and work with us. Coming to the point, I would like to know if this integration works with Qlikview as well?
As you know, we usually update setting.ini or analytic connection with the port number 50055 to integrate with Qlik Sense. Does this work with Qlik view as well? if I committed the same thing as I did with Qlik Sense.

DLL Load Failed error

While running the Qlik-py-Start.bat file, I am facing" Import Error: DLL Load failed: The specified procedure could not be found.
And when I try to run in qliksense, error pops up "PyTool.sklearn_Setup is not a registered SSE function. Ensure the plugin is running"

Not getting prediction

Hello!

Hoping you can help me sort this issue out:
Was trying this implementation and got it workign with the sample databooks provided with predictions as it should as shown here. And the console (Qlik-Py-Start.bat) is putting out some form of output as shown here.

However, when I try do to it with my own data it doesn't put anything at all to the console and the linegraph in Qlik Sense Desktop (QSD) is just a straight line instead of looking like an actual line which is shown here.

I have used the same expression and variables as used in the samplebooks provided and changed the parameters to match the name of those in my datasource.

There must then be some kind of issue with the SSE connection to my workbook since nothing is happening with my prediction-line?

Best Regards

Requesting Help - Save data using Pandas

So I know this library is not for this reason but I had a unique case where I am trying to save a variable value outside of Qlik. Let's say to_csv using panda. Can you please provide an example of where using panda we can export the data out and stage it in a particular folder. A good use case will be to triage events that are predicted. For a close loop to exist we can have other users evaluate the results and highlight false positives that will then again become part of the training model.

In short, can we use python to extract the data out on to access to a destination of our choice? (and I am not talking about right-clicking and exporting the data). If you do intend to build a sample, would be nice to have a sample of how a variable value can be saved and if possible a table can be exported.

Regards,
Syed

Dashboard Does not cluster

SSE is working, capabilities are shown, but when i open dashboard there is no clustering of data, tried on server and desktop, both the same

Can't connect to docker

Hello,

I would like to use this extension, but I don't succeed to make a connection between QlikSense Desktop (June 2019) and the Docker image.

I changed my "settings.ini" file with
SSEPlugin=PyTools,localhost:50055

I made
docker pull nabeeloz/qlik-py-tools
and launched it with
docker run -p 50055:80 -it nabeeloz/qlik-py-tools

I have the following output:

INFO:matplotlib.font_manager:generated new fontManager
2019-09-24 06:42:51,026 - INFO - Logging enabled
2019-09-24 06:42:51,030 - INFO - *** Running server in insecure mode on port: 50055 ***

When I launch QlikSense, I don't see the expected "GetCapabilites" output. There is nothing more in the console.

I tried with different ports without success.

I don't have problem to run others SSE Plugins (like PythonSentiment for instance).

I there a step I missed?

Thank you.

Regressor doen't work properly

Hi Nabeel, I have been experiencing difficulties using the regressor, I have used my own data with the classifiers but I have no clue from this point since I;m not able to notice what's the error here (I understand it but works well with any classifier which doesn't makes any sense), I left the code write down:

I'm using 9 features + 1 target, the regressor is LR but crash at the same point with any of the other choices.

ERROR - Exception iterating responses: 9 columns passed, passed data had 10 columns
Traceback (most recent call last):
File "D:\EDISA\Python\qlik-py-tools-5.1\qlik-py-env\lib\site-packages\pandas\core\internals\construction.py", line 500, in _list_to_arrays
content, columns, dtype=dtype, coerce_float=coerce_float
File "D:\EDISA\Python\qlik-py-tools-5.1\qlik-py-env\lib\site-packages\pandas\core\internals\construction.py", line 583, in _convert_object_array
"{con} columns".format(col=len(columns), con=len(content))
AssertionError: 9 columns passed, passed data had 10 columns

,

Installation Issues

I actually reinstalled my windows for this. lol. So having two issues when running int.

Issue one (heads up, I already have tried moving back to the older version and tried updating Numpy and HDBSCAN).
image

The second issue is for spacy.
image

This might be a simple fix for most but I am new to this.

visualization was not found on the server

Invalid visulaisation

Hi Nabeel,

Hope you're doing fine. I am facing an issue as it is in the above image, for now, I am running this in the desktop. May I know what is the issue I am going through?

NER crash during Association_Rules

Hi Nabeel,

Thanks for your hard work on this.
We are currently running the docker image pulled from the hub on a DigitalOcean Ubuntu/Docker server but when running the NER script (using just a single chapter from the LOTR QVDs), once it finishes the epoch loop, and gets to execute function 33 - Association_Rules, it continues on for approx 5 minutes and then causes the docker container to crash and restart.

Any tips on how to find logs/if there is anything you an think of that is causing this?
Server resources don't seem to be stressed so unsure what it could be...

Thanks again!

Unable to run start

Hi there, I'm using py tools 3.8 and python 3.7 to try the forecasting apps. After the initialization, I tried starting the start file but am faced with the following:

Traceback (most recent call last):
File "main.py", line 16, in
import ServerSideExtension_pb2 as SSE
File "C:\Users\Documents\qlik-py-tools-3.8\qlik-py-env\generated\ServerSideExtension_pb2.py", line 6, in
from google.protobuf.internal import enum_type_wrapper
ModuleNotFoundError: No module named 'google'
Press any key to continue . . .

Am new to this and appreciate your help, thanks!

  • Olive

Classification Modeling issue - logistic regression model: Connector reply error: grpc::StatusCode::UNKNOWN: 'Exception iterating responses: n_features must be integral, got '2' (<class 'str'>).'

Hi Nabeel,

Hope you doing great, just tried to implement the actual sample data for Logistic regression model alone, but when tired fitting the data
EXTENSION PyTools.sklearn_Fit(TEMP_SAMPLES{Model_Name, N_Features});

getting the below error"
The following error occurred:
Connector reply error: grpc::StatusCode::UNKNOWN: 'Exception iterating responses: n_features must be integral, got '2' (<class 'str'>).'

Not sure, what am missing here, the actual data set is this, just thought to check with you.

IRN | Paying_Regularly | Age | Gender | Marital_Status | Employment_Ind | Num_Dependents | Receive_Benefits_Ind | Receive_Alimony_Ind | Receive_Child_Support_Ind | Med_exp_ind | Incarceration_Ind
2098 | Yes | 35 | M | Single | Yes | 0 | Yes | No | Yes | No | 0
8765 | No | 46 | M | Single | Yes | 2 | Yes | No | Yes | Yes | 1
4536 | Yes | 27 | F | Single | Yes | 0 | No | No | Yes | No | 0
4219 | No | 65 | F | Single | No | 3 | No | No | Yes | Yes | 1
7699 | No | 54 | F | Married | No | 2 | No | Yes | Yes | No | 1
9123 | No | 44 | M | Married | No | 1 | No | Yes | No | No | 1
5647 | No | 32 | F | Single | No | 0 | Yes | Yes | Yes | No | 0
3189 | Yes | 65 | M | Married | Yes | 0 | Yes | Yes | No | No | 0
6123 | No | 49 | M | Married | No | 3 | No | No | No | No | 1
4912 | No | 37 | M | Married | No | 3 | No | No | No | No | 1
5812 | Yes | 43 | F | Married | Yes | 0 | Yes | No | Yes | No | 0
8213 | No | 58 | F | Married | No | 1 | No | No | Yes | Yes | 0
5678 | No | 29 | M | Single | No | 2 | Yes | Yes | No | No | 1
2987 | No | 36 | M | Single | No | 3 | No | No | Yes | Yes | 1
6219 | No | 47 | F | Married | No | 2 | No | Yes | Yes | No | 1
6231 | Yes | 35 | F | Single | Yes | 0 | No | No | No | No | 0
8812 | No | 54 | M | Married | No | 1 | No | No | No | No | 1
7034 | No | 58 | M | Single | No | 2 | No | No | No | Yes | 0
8518 | No | 42 | F | Single | No | 1 | No | No | Yes | No | 1
4745 | No | 31 | M | Single | No | 0 | No | Yes | No | No | 1

[Estimators]:
LOAD * INLINE
[
Model Name;Estimator;Hyperparameters
HR-Attrition-LR;LogisticRegression;
](delimiter is ';');

Scaler,
[Null Value Handling],
[Scale Hashed Features],
[Hyperparameters] AS [Scaler.Hyperparameters];
LOAD * INLINE
[
Scaler;Null Value Handling;Scale Hashed Features;Hyperparameters
StandardScaler;zeros;true;with_mean=True|bool, with_std=True|bool
](delimiter is ';');

Name,
Variable_Type,
Data_Type,
Feature_Strategy,
Hash_Features
FROM [lib://Feature Definitions/SampleDataforPrediction_V1.1 (1).xlsx]
(ooxml, embedded labels, table is Feature_Definitions);

IRN,
"Paying_Regularly",
"Age",
Gender,
Marital_Status,
Employment_Ind,
Num_Dependents,
Receive_Benefits_Ind,
Receive_Alimony_Ind,
Receive_Child_Support_Ind,
Med_exp_ind,
Incarceration_Ind
FROM [lib://Feature Definitions/SampleDataforPrediction_V1.1 (1).xlsx]
(ooxml, embedded labels, table is LR_Classification_Results_1);

// Set up a variable for the scaler parameters
LET vScalerArgs = 'scaler=' & peek('Scaler', 0, 'Scaler') & ',' &
'missing=' & peek('Null Value Handling', 0, 'Scaler') & ',' &
'scale_hashed=' & peek('Scale Hashed Features', 0, 'Scaler') & ',' &
peek('Scaler.Hyperparameters', 0, 'Scaler');

// Set up a variable for execution parameters
LET vExecutionArgs = 'overwrite=true,test_size=0.3,calculate_importances=true';

LET i = 0;

// Create a model for each estimator
For Each vModel in FieldValueList('Model Name')

// Set up a variable for this estimator's parameters
LET vEstimatorArgs = 'estimator=' & peek('Estimator', $(i), 'Estimators') & ',' & peek('Hyperparameters', $(i), 'Estimators');

// Set up a temporary table for the model parameters
[MODEL_INIT]:
LOAD
    [Model Name] as Model_Name,
    '$(vEstimatorArgs)' as EstimatorArgs,
    '$(vScalerArgs)' as ScalerArgs,
    '$(vExecutionArgs)' as ExecutionArgs    
RESIDENT Estimators
WHERE [Model Name] = '$(vModel)';

// Use the LOAD...EXTENSION syntax to call the Setup function
[Result-Setup]:
LOAD
    model_name,
    result,
    timestamp
EXTENSION PyTools.sklearn_Setup(MODEL_INIT{Model_Name, EstimatorArgs, ScalerArgs, ExecutionArgs});

[FEATURES]:
LOAD
	'$(vModel)' as Model_Name,
    Name,
    Variable_Type,
    Data_Type,
    Feature_Strategy,
    Hash_Features
RESIDENT [Feature Definitions];

// Use the LOAD...EXTENSION syntax to call the Set_Features function
[Result-Setup]:
LOAD
    model_name,
    result,
    timestamp
EXTENSION PyTools.sklearn_Set_Features(FEATURES{Model_Name, Name, Variable_Type, Data_Type, Feature_Strategy, Hash_Features});

Drop table MODEL_INIT, FEATURES;   

LET i = $(i) + 1;

Next vModel;

IRN &'|'&
Paying_Regularly &'|'&
Age &'|'&
Gender &'|'&
Marital_Status &'|'&
Employment_Ind &'|'&
Num_Dependents &'|'&
Receive_Benefits_Ind &'|'&
Receive_Alimony_Ind &'|'&
Receive_Child_Support_Ind &'|'&
Med_exp_ind &'|'&
Incarceration_Ind As N_Features
RESIDENT Train-Test;

LET i = 0;

// Train and Test each model
For Each vModel in FieldValueList('Model Name')

[TEMP_SAMPLES]:
LOAD
	'$(vModel)' as Model_Name,
    N_Features
RESIDENT [TEMP_TRAIN_TEST];

// Use the LOAD...EXTENSION syntax to call the Fit function
[Result-Fit]:
LOAD
    model_name,
    result as fit_result, 
    time_stamp as fit_timestamp, 
    score_result, 
    score
EXTENSION PyTools.sklearn_Fit(TEMP_SAMPLES{Model_Name, N_Features});

Can't start Service: ModuleNotFoundError fbprophet

Hi, after updating the files and setting up a new venv i run into this error.

errorfbprophet

I don't know how to handle this.
The ModuleNotFoundError "google" i can solve with downgrading grpcio.
Running this on Windows Server 2012 R2.
I had it successfully running in the past.

Thanks alot!

Assertion Error - Passing features to Sklearn

Hi Nabeel,

Hope you doing well.
I was trying to run the train and test model, fitting my data model. But something is occurring very often.
Every time that I try to load my data, the same error keeps showing up:

image

The number of columns seems to never match the data that I'm loading. It's not even the real columns quantity (17 columns)

Here is a sample of my data. I already checked the fields and special symbols, without any success.

Name Variable_Type Data_Type Feature_Strategy Hash_Features
IDPROCESSO identifier int scaling
HIDROLISEVOLADITIVO feature float scaling
HIDROLISEDURPROCESSO feature float scaling
HIDROLISED075315GSD feature int scaling
HIDROLISED075315EFICIENCIA target str one hot encoding
FERVURA01VOLINID0753 feature float scaling
FERVURA01TMPFIMTIC0753PV feature float scaling
FERVURA01DURFERVURA01 feature float scaling
FERVURA01ABEFIMTIC0753OUT feature float scaling
DESCARGATMPINITIC0753PV feature float scaling
DESCARGATMPFIMTIC0753PV feature float scaling
DESCARGADURDESCD0753 feature float scaling
DESCARGADURABERTURAHS07571 feature float scaling
DESCARGAABEINITIC0753OUT feature float scaling
DESCARGAABEFIMTIC0753OUT feature float scaling
AQUECIMENTOVOLFIMD0753 feature float scaling
AQUECIMENTODURAQUECHS07533 feature float scaling

------###-------

N_Features

3|148.94|0.17|0|95.6|74.09|110.11|0.03|34.47|106.83|80.24|0.01|0.01|0|0|74.09|0.04
7|135.4|0.45|0|96.3|74.39|109.88|0.03|40.66|104.91|77.01|0.26|0.26|0|0|74.39|0.05
8|144|0.18|0|96.5|74.89|109.73|0.03|41.23|106.66|81.01|0.01|0.01|0|0|74.89|0.05
10|136.54|0.19|0|96.7|74.55|109.79|0.03|41.13|105.99|80.39|0.01|0.01|0|0|74.55|0.05
11|78.39|0.31|0|96|91.98|110.11|0.03|34.03|102.87|74.77|0.04|0.04|0|0|91.98|0.06
13|95.3|0.22|0|95.8|93.06|109.67|0.03|43.53|105.73|74.61|0.02|0.02|0|0|93.06|0.07
14|133.56|0.24|0|96|92.61|109.97|0.03|41.35|103.05|73.14|0.03|0.03|0|0|92.61|0.05
15|142.05|0.41|0|95.9|92.39|109.26|0.03|50.26|94.51|70.63|0.02|0.02|1.46|1.46|92.39|0.07
16|140.91|0.31|0|96|92.25|109.31|0.03|50.45|107.33|82.76|0.02|0.02|15|15|92.25|0.07
21|131.99|0.22|0|96.6|90.68|109.78|0.03|46.31|104.92|75.26|0.01|0.01|0|0|90.68|0.06
22|129.75|0.2|0|95.6|90.94|109.6|0.03|44.03|106.38|75.93|0.01|0.01|0|0|90.94|0.06
28|140.12|0.19|0|95.8|89.09|109.65|0.03|44.03|106.23|74.92|0.01|0.01|0|0|89.09|0.05
34|141.7|0.25|0|95.6|0|0|0|0|106.46|76.38|0.01|0.01|0|0|0|0
40|129.2|0.2|0|95.9|88.99|109.83|0.03|40.04|107.37|74.45|0.01|0.01|0|0|88.99|0.05
45|121.79|0.21|0|96.3|89.46|110.06|0.03|38.13|106.92|72.48|0.02|0.02|0|0|89.46|0.05
61|129.67|0.24|0|96.1|90.3|110.12|0.03|31.75|105.27|75.29|0.02|0.02|0|0|90.3|0.05
64|125.19|0.18|0|95.7|89.27|110.2|0.03|31.96|107.12|74.81|0.02|0.02|0|0|89.27|0.05
66|138.72|0.21|0|95.8|89.79|110.17|0.03|31.46|106.68|73.84|0.02|0.02|0|0|89.79|0.05

I've tried to use only integer numbers: Not working. I've noticed that it returns an error if I tag the target field as a float.

If possible, I would like to understand how the strings are broken on python to run the algorithms.

Thank you for your help.

Cosme Henrique.

One Feature Short (Connector reply error: grpc::StatusCode::UNKNOWN: 'Exception iterating responses: 11 columns passed, passed data had 12 columns')

Hi Nabeel,

I am getting the following error. Funny thing is that that are moments when I don't get this error and it goes thought to a successful load. I first thought that this could be due to my data but I tried fixing this in the load script (you will see one you load the file).

image
image

My data and the structured data with the Qlik App is part of the ticket. I am using publically available data so anyone who is doing this is most welcome to dive in.

My Files:
winequality-white-setup.xlsx
ML Training.zip

Another fun fact, when this runs, the best results I get are in lower 50%s. Any tips to improve those will also help.

internal error

Hello , I am getting error "Internal Error" in the screen Emergency attendances forecast "Actual Vs Forecast".

I have followed all the above steps. pls help.

internal error.docx

Error in example app of Sample App - Train & Test

Hi,

We are having problems on this example app. It is supossed that we need to execute this app to make others work like Sample App - Predict. We are trying with same Excel and same app in two different Qlik Sense Desktops and we are having two different problems in the same part of script:

[Result-Fit]:
LOAD
    model_name,
    result as fit_result, 
    time_stamp as fit_timestamp, 
    score_result, 
    score
EXTENSION PyTools.sklearn_Fit(TEMP_SAMPLES{Model_Name, N_Features});

One error is: Connector reply error: grpc::StatusCode::UNKNOWN: 'Exception iterating responses: 31 columns passed, passed data had 35 columns'

Second error is: Connector reply error: grpc::StatusCode::UNKNOWN: 'Exception iterating responses: n_features must be integral, got '' (<class 'str'>).'

We dont understand why we have different problems with same aps. Is this function working well?

Thanks.

Classification (Logistic Regression)

Hey @nabeel-oz, hope you're doing well.
I'm trying to reverse engineer the Qonnections machine learning sample (appointment no-shows), using different data. While the SSE seems to work fine when I do a load for the original sample app, on the new app it gives me the following error:

error: Connector reply error: grpc::StatusCode::UNKNOWN: 'Exception iterating responses: local variable 'scale_df' referenced before assignment'

This happens in the Model Training and Testing sheet (I checked using the exit script).

Here is the actual code I have:
Code 1
Code 2
Code 3
Code 4

I'm really new to both Qlik and Python, so I apologize if it's something elementary I'm getting stuck on. Please let me know if I can provide any more information. Thank you!

Add my own functions

Hello,
Is that possible to add my own function to call them in Qlik ? if Yes I have to modify the _main.py file and the functions.json in which folder and do i have to modify other file or create new one ?

Thank you

:)

Forecast Calendar with (Standar) Master Calendar of Qlik

Hi:
I have created my application environment under the Qlik standard 'Master Calendar', I have tried to modify the Master calendar to work with 'Forecast Calendar', but I haven't succeeded. How can I join 'Master Calendar' with 'Forecast Calendar'?
How to make them work together?

Creating joblib files

Hi,

I am having issues running prediction in the 'Sample-App-scikit-learn-Predict.qvf'. When running the script or clicking the Predict button a file not found and Exception iterating responses error appears. file directory '..\models\HR-Attrition-LR.joblib'. Looking through the Traceback most recent call the '_machine_learning.py' file on line 68 fails. It seems the models directory isn't getting created.

Could you please help with this or advice possible steps.

microsoftteams-image

Thanks

Set expression on time series forecasting

Hi Nabeel,

  Hope you are doing well.

I was trying to forecast using the facebook prophet model but ended up not getting the prediction of what I supposed to get. Basically, I have a measure to be calculated using the following expression

(1-(sum({$<Année=,Semaine=,Jour=,LieA={'Cause Fournisseur'}>}$(vValManq))/(sum({$<Année=,LieA={'Cause Fournisseur'},Semaine=,Jour=>}$(vValManq)) + Sum({$<Année=,Semaine=,Jour=>}$(vValSortie)))))*100

but I am just wondering how can it be manipulated to the following expression as you have used in your measure to forecast the values or is it something to be replaced with my measure.

Count({$<FORECAST_LINK_TYPE = {'Actual'}>} Distinct ACCIDENT_NO)

Whatever that has been written in the measure has to be added to the pytools.prophet function as well when we forecast the values. I hope you clarify my doubts.

Some posible problems

  1. in my recent expirences, i executed of bat Qlik-Py-Init, but is possible that, do not move "generated" and "core" folders, if you no executas the bat in the path. This problem because are statements: move generate and move core
    move generated "%~dp0\qlik-py-env" move core "%~dp0\qlik-py-env"`

they not have the index %~dp0. a possible solution is the used the comant pront opcion of file explorer:
image

and execute the .bat the next form:

start Qlik-Py-Init.bat

2.. the installed pip install fbprophet, is possible that not install. For that you can install pip install fbprophet, You duty have installed ** pystan ** compiled with mingw,
i recomend that you used the next link with a guide:

http://pystan.readthedocs.io/en/latest/windows.html#

http://pystan.readthedocs.io/en/latest/windows.html#setting-up-mingw-w64-on-windows,
and
https://facebook.github.io/prophet/docs/installation.html

Possible VC++ MSVC issues for fbprohphet

Hi Nabeel,

I tried installing the SSE desktop version as per the instructions on 2 different windows 10 machines but failed to install fbprophet on both of them.
On researching I found that pystan has issues with the MSVC Lib files and there is very less support on the issue.

Can I use any other C++ compilers? Can you please point to the version compatible with all the packages?

Best,
Paarth Sanghavi

Errors when multiple users access the app

Hi Nabeel,

We are getting the error when we use the prophet library extension sometimes :

ValueError: 'Series([], Name: ds, dtype: object)' is not compatible with origin='1899-12-30 00:00:00'; it must be numeric with a unit specified.

Do you know what could be the issue?

Qlik-Py-Init Errors

I am encountering errors when I run Qlik-Py-Init.bat file and then when running Qlik-Py-Start.bat.
Please see the screenshots attached.
I have installed Python 3.6.8 and MS C++ compiler as instructed before running Qlik-Py-Tools bat files
Qlik Sense accordingly does not recognize the PyTools functions in expressions containing them

Thanks in advance for a solution

QlikPyToolsInit_ErrorCode1

QlikPyToolsInit_ErrorCode2

QlikPyToolsStart_ErrorCode

Clustering - Index contains duplicate values, cannot reshape

I'm using the clustering sample app, but not able to recreate it. I've tried to make my dataset as similar to the sample as possible, but I'm not being able to diagnose my mistake. I've attached my data load script and the error trace. I only have one table (I prepared the data to look similar to the victoria dataset in Excel), and I've posted a sample of the data:

trace1
trace2

script1
script2

DataSample

error

(error occurs on line 21 of the cluster 1 tab)
I created the ca_iucr_desc field to create one unique field, but it doesn't seem to work. I tried adding an index to my table and that didn't either.

Field 'ds' not found

Hi Nabeel,

Thank you for making the PY tools available to the community. I tried performing forecasting on my own data and was prompted with "Field 'ds' not found.". I am using the latest SSE v4.4, as per the community info
DS nto found
.
I tried to run the load script for the sample app (Hospital attendance data) and it worked fine.

Thanks,
Olive

Script

hello, is it possible for the forecast calculation to be performed in the script instead of the graph? for the sake of performance.

Not working with sense Nov 2018 desktop?

Hi,

Installed qlik sense desktop Nov18. cannot find Setting.ini anywhere, so I created it manually:
[Settings 7] SSEPlugin=PyTools,localhost:50055;R,localhost:50050

but this does not work - the Qlik-Py-Start.bat window does not show that it is loading the extensions...

Error execute prophet function

Hello, i try the package and when i use prophet function sometimes i receive a message error in chart. I see the logs into the package and i find which the python function not receive the input value but when I change something in the chart (for example sorting type, it reload and return the chart value).

I think which Qlik execute the prophet function in the chart above to send the value to python ( even when I apply a filter).

What can I do?

Thank you

Marco

Prophet Not Showing Results

Hi there,

After I managed to get C++ compiler and pystan working I am still not seeing results from the Prophet function on Qlik. Note that all other functions work perfectly. Here is what I get when I execute the function.
Untitled

Create future dates for forecast in script

Hi:

I have a problem. I need to use the forecast in script like example app Sample_App_Forecasting_Simple. My question is if it's possible to create date to forecast in this example, because in the excel that app reads it has the dates to predict already created. So what can I do if I want to crate dates to predict for each hospital and I don't have them created in Excel?

Thanks!

Any plans to Certify this extension by Qlik?

Hi,

Just wanted to ask if there are plans to certify this extension by Qlik? As an enterprise client, it is hard for me to push for this extension to be incorporated just like other clients who are now trending to adopt Qlik certified extensions only.

Regards,
Syed

ValueError Found Infinity in Column Y

Dear @nabeel-oz , I have adopted the workflow of your sample_app_forecasting_simple,qvf. However, for this precalculated method, I do not know which part of your scripting controls the forecast period required, for example 6 months or 12 months, or 24 months, as compared to your another calendar method. For this precalculated method, I have three questions.
(1) In the LOAD script, is the field PERIOD or the [MONTH START] responsible for the last month to be forecasted?
(2) Are we using the chart expression to indicate the starting month to be forecasted instead of the LOAD script?
(3) Can we forecast Attendance values for months in year 2020? If so, how can we do that in the scripting?
Part one:
Besides these two questions, I have also encountered several problems that I am so eager to share with you and other users. Please advise me to solve it.
What I have done so far: I have prepared my LOAD script and obtained the data model as shown below. It is not as what we expect actually. There is no link key available.
data_model_1

Part two:
Part two is based on my own data and not the hospital attendance dataset. What happened is that I have encountered error as shown below.
field_error_qs

The qlik sense cannot proceed with the error above and the Command-line also generated the same error as shown below.
forecast_error_output

@nabeel-oz , do we need to change the code block for the Prophet to bypass this error or can we reply on the scripting in Qlik Sense to solve this infinity error? I have no experience in dealing with infinity issue on the response variable.

Please advise me for these questions in the two parts above.
Thank you for your time.

Qlik pytools

Hi Nabeel,
Hope you are doing great

I tried forecasting the data and I am successful in doing the same using the qlik-py-tools, thank you so much introducing this extension

I am in need of some clarifications on this model

  1. In this model the data is getting forecasted for history as well as the future years, but I do not want to forecast the data for the past history data rather I wanted to forecast the data only for the future years based on parameter
    scenario: Years 2017,2018,2019 and actual data is available for 2017,2018,2019
    parameter: 2 years
    After the logic the prediction will happen for 5 years from 2017, 2018,2019,2020,2021 but forecast should happen only for 2020 and 2021 and not for the 2017,2018 and 2019 hope my question is clear
    I am trying to modify the logic and implement but I feel some difficulties

Any ideas to do this?

Thank you so much again
Regards
Subash

qlik with Python for Machine Learning

Hi Nabeel,

I am trying to integrate the Python with Qlik sense desktop with the steps you have mentioned in the Github (https://github.com/nabeel-oz/qlik-py-...)
After installing the required prerequisites (Python 3.6 version, Qlik Desktop and Microsoft Visual C++ Build Tools), I am still facing the below issue, after I execute the Qlik-Py-Init.bat, windows.bat file

  1. "error: Command "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\skumar\appdata\local\temp\temp5_qlik-py-tools-4.0.zip\qlik-py-tools-4.0\qlik-py-env\include -IC:\Users\skumar\AppData\Local\Programs\Python\Python37\include -IC:\Users\skumar\AppData\Local\Programs\Python\Python37\include -IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt /EHsc /Tppystan/_misc.cpp /Fobuild\temp.win-amd64-3.7\Release\pystan/_misc.obj" failed with exit status 2"

  2. "Command "c:\users\skumar\appdata\local\temp\temp5_qlik-py-tools-4.0.zip\qlik-py-tools-4.0\qlik-py-env\scripts\python.exe -u -c "import setuptools, tokenize;file='C:\Users\skumar\AppData\Local\Temp\pip-install-9fy4r3pa\pystan\setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record C:\Users\skumar\AppData\Local\Temp\pip-record-1qbg_m01\install-record.txt --single-version-externally-managed --compile --install-headers c:\users\skumar\appdata\local\temp\temp5_qlik-py-tools-4.0.zip\qlik-py-tools-4.0\qlik-py-env\include\site\python3.7\pystan" failed with error code 1 in C:\Users\skumar\AppData\Local\Temp\pip-install-9fy4r3pa\pystan"

Please suggest any solution, if you could help me out on this!!
Thank you so much for the support and great work
Regards
Subash Kumar
[email protected]

Calling python functions in the data load editor

Hi Nabeel,
I have written a library of functions in Python which I am able to successfully call from Qlik sense. However I wish to achieve the following:
Given a list of selections by the user from a drop down menu in the app, I pass this list to my python function and save the output in a variable which I can use repeatedly. Could you please help me with some direction here? Thanks.

logger error

Hi,
While installing the libraries especially pystan i am getting the error. i installed the Microsoft visual ++ builder tool also

capture

Facebook prophet forecasting not working for filters

Hi nabeel,

Hope you're doing well

Basically, I worked out the forecasting model and it was successfully forecasting but the problem is that when I select the filters it's not forecasting accordingly for overtime instead it just shows the visual of the data that fed into.

Here the first screenshot shows the forecast with no filter selection and the second one is with filter selection(also you can see that it's not predicting for the selection made). I would like to forecast for the filter selection as well, could you give me some suggestions.
image

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.