import numpy as np import pandas as pd import xgboost as xgb import pandas as pd import random import numpy as np import pandas as pd from sklearn.model_selection import train_test_split,cross_val_score from sklearn.ensemble import RandomForestClassifier,RandomForestRegressor from sklearn.metrics import classification_report,confusion_matrix,accuracy_score from sklearn.neighbors import KNeighborsClassifier,KNeighborsRegressor from sklearn.svm import SVC,SVR from sklearn import datasets from ngboost import NGBRegressor from sklearn.tree import DecisionTreeRegressor df_strength=pd.read_csv("OPS_LWAC.csv") x_strength=df_strength.iloc[:,:-1] y_strength=df_strength.iloc[:,-1] x_strength=df_strength.iloc[:,:-1] y_strength=df_strength.iloc[:,-1] from sklearn.model_selection import train_test_split x_train, x_test, y_train, y_test=train_test_split(x_strength,y_strength, test_size=0.25, random_state=20) learner = DecisionTreeRegressor(criterion='friedman_mse', max_depth=3) clf = NGBRegressor (learning_rate= 0.0708, minibatch_frac= 0.647, n_estimators= 548, Base=learner) clf.fit(x_train, y_train) import gradio as gr def OPS_LWAC(OPC, SCM_FA, SCM_SF, w_b, FA, CA, OPS, SP, T): # Turning the arguments into a numpy array x = np.array([OPC, SCM_FA, SCM_SF, w_b, FA, CA, OPS, SP, T]) prediction = clf.pred_dist(x.reshape(1, -1)) aa=prediction.params["loc"].item() #value1 = aa[0] bb=prediction.params["scale"].item() #value2 = bb[0] #prediction = clf.predict(x.reshape(1, -1)) #-3*y_dists.params["scale"]+y_dists.params["loc"] result_string = "[CS: {:.3f}; σ: {:.3f}]".format(aa, bb) return result_string #return [aa, bb] inputs = [ gr.inputs.Number(label="cement content (OPC, unit: kg/m3)"), gr.inputs.Number(label="fly ash content (SCM_FA, unit: kg/m3)"), gr.inputs.Number(label="silica fume content (SCM_SF, unit: kg/m3)"), gr.inputs.Number(label="water to cementitious material ratio (w_b, unit: -)"), gr.inputs.Number(label="fine aggregate content (FA, unit: kg/m3)"), gr.inputs.Number(label="coarse aggregate content (CA, unit: kg/m3)"), gr.inputs.Number(label="oil palm shell content (OPS, unit: kg/m3)"), gr.inputs.Number(label="superplasticizer content (SP, unit: kg/m3)"), gr.inputs.Number(label="curing time (T, unit: d)") ] outputs = gr.outputs.Textbox(label="Estimated mean prediction and σ value (unit: MPa)") app = gr.Interface(fn=OPS_LWAC, inputs=inputs, outputs=outputs, description="Estimation of compressive strength of OPS-based lightweight concrete") app.launch()