SelfExplainML / PiML-Toolbox

PiML (Python Interpretable Machine Learning) toolbox for model development & diagnostics
https://selfexplainml.github.io/PiML-Toolbox
Apache License 2.0
912 stars 109 forks source link

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

Closed hossainirad closed 1 year ago

hossainirad commented 1 year ago

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.

ZebinYang commented 1 year ago

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

hossainirad commented 1 year ago

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)
ZebinYang commented 1 year ago

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.

hossainirad commented 1 year ago

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'
ZebinYang commented 1 year ago

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.

ZebinYang commented 1 year ago

Hi @hossainirad

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