SelfExplainML/PiML-Toolbox

how to run piml as a python module? (not in the jupyter)

hossainirad opened this issue · 6 comments

Hi there.
I want to use piml as a python module in a fastapi service. how to run it out of jupyter?
For example when I run this in python shell I get this error:


from piml import Experiment

exp = Experiment()

exp.data_loader()

------
AttributeError: 'NoneType' object has no attribute 'events'

thanks.

Hi @hossainirad ,

You can use PiML in the high-code mode. For example, the data loader part can be changed to

import pandas as pd
data = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/00265/CASP.csv") 
exp.data_loader(data=data)

See the full example https://colab.research.google.com/github/SelfExplainML/PiML-Toolbox/blob/main/examples/Example_BikeSharing_HighCode.ipynb

thank you.
you mean secend section? Stage 2. Train intepretable models.
Stage 2. Train intepretable models --> has not exp = Experiment()
and then I add it in my code, I get same error.

from piml import Experiment
from piml.models import ReluDNNRegressor

clf1 = ReluDNNRegressor(hidden_layer_sizes=(40, 40), l1_reg=1e-05,
                        batch_size=500, learning_rate=0.001)
exp = Experiment()
exp.model_train(model=clf1, name='ReLU-DNN')
exp.model_diagnose(model="ReLU-DNN", show='accuracy_result')

or:

from piml import Experiment
exp = Experiment()

exp.data_loader(data='BikeSharing')

or:


import pandas as pd
from piml import Experiment
exp = Experiment()
data = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/00265/CASP.csv") 
exp.data_loader(data=data)

Hi @hossainirad

In the high code mode, you are able to run the codes without manually clicking on the buttons like in the low code mode.

But you still need to follow the given procedures as shown in the example, i.e., create an instance of Experiment, load data, and prepare data. Without specifying data, you cannot start training models.

In any case when I create an object from Experiment() I get the error:

import pandas as pd
from piml import Experiment
data = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/00265/CASP.csv") 
exp = Experiment()
exp.data_loader(data=data)

------

Traceback (most recent call last):
  File "/home/ali/Documents/piml/test_piml.py", line 4, in <module>
    exp = Experiment()
  File "piml/api.py", line 67, in piml.api.Experiment.__init__
AttributeError: 'NoneType' object has no attribute 'events'

Hi @hossainirad

Oh, I see.
PiML cannot be used outside jupyter notebook for the time being.
We will add support for terminal calls in the future.

Hi @hossainirad

We have added support for running PiML outside Jupyter notebook starting from v0.3.3.