gpr example
Browse files- gbr_example.py +38 -0
gbr_example.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
from sklearn.ensemble import HistGradientBoostingRegressor
|
5 |
+
from sklearn.datasets import load_diabetes
|
6 |
+
from sklearn.multioutput import MultiOutputRegressor
|
7 |
+
|
8 |
+
# Assume y is now a DataFrame with multiple columns
|
9 |
+
X, y = load_diabetes(return_X_y=True, as_frame=True)
|
10 |
+
y = pd.DataFrame([y, y]).T
|
11 |
+
|
12 |
+
# Make the estimator multi-output capable
|
13 |
+
est = MultiOutputRegressor(HistGradientBoostingRegressor()).fit(X, y)
|
14 |
+
|
15 |
+
|
16 |
+
def predict(input_df):
|
17 |
+
prediction = est.predict(input_df)
|
18 |
+
# Assume y has columns named "target1", "target2", etc.
|
19 |
+
return pd.DataFrame(prediction, columns=y.columns)
|
20 |
+
|
21 |
+
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=predict,
|
24 |
+
inputs=gr.Dataframe(
|
25 |
+
value=X.head(1),
|
26 |
+
headers=list(X.columns),
|
27 |
+
col_count=(X.shape[1], "fixed"),
|
28 |
+
row_count=(1, "dynamic"),
|
29 |
+
datatype=X.dtypes.apply(str).replace("float64", "number").values.tolist(),
|
30 |
+
),
|
31 |
+
outputs=gr.Dataframe(
|
32 |
+
value=y.head(1),
|
33 |
+
headers=list(y.columns),
|
34 |
+
col_count=(y.shape[1], "fixed"),
|
35 |
+
datatype=y.dtypes.apply(str).replace("float64", "number").values.tolist(),
|
36 |
+
),
|
37 |
+
)
|
38 |
+
iface.launch()
|