File size: 1,196 Bytes
1e10b8f
 
 
 
 
 
 
 
 
 
298b47c
1e10b8f
 
3d21777
2423e7a
1e10b8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2423e7a
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gradio as gr

from sklearn.multioutput import MultiOutputRegressor

from sklearn.datasets import load_linnerud
from sklearn.multioutput import MultiOutputRegressor
from sklearn.linear_model import Ridge

X, y = load_linnerud(return_X_y=True, as_frame=True)
regr = MultiOutputRegressor(Ridge(random_state=123)).fit(X, y)
# example usage: regr.predict(X.iloc[[0]])

iface = gr.Interface(
    title="MultiOutputRegressor Example",
    fn=regr.predict,
    inputs=gr.Dataframe(
        value=X.head(1),
        headers=list(X.columns),
        col_count=(X.shape[1], "fixed"),
        row_count=(1, "dynamic"),
        datatype=X.dtypes.apply(str).replace("float64", "number").values.tolist(),
    ),
    outputs=gr.Numpy(
        value=regr.predict(X.head(1)),
        headers=list(y.columns),
        col_count=(y.shape[1], "fixed"),
        datatype=y.dtypes.apply(str).replace("float64", "number").values.tolist(),
    ),
)
iface.launch()

# %% Code Graveyard

# def predict(X):
#     max_rows = 100000
#     if X.shape[0] > max_rows:
#         raise ValueError(
#             f"Too many rows ({X.shape[0]}), please use less than {max_rows} rows."
#         )
#     return regr.predict(X)