from unittest.mock import MagicMock import sys sys.modules["xgboost"] = MagicMock() from explainerdashboard import RegressionExplainer, ExplainerDashboard explainer = RegressionExplainer.from_file("explainer.joblib") # you can override params during load from_config: db = ExplainerDashboard.from_config(explainer, "dashboard.yaml", title="Test") app = db.flask_server() # run waitress-serve --port=8070 dashboard:app in command line
model = pickle.load(open(MODELS_DIR / 'general_model.pkl', 'rb')) y = pd.read_csv(DATA_DIR / 'general_target.csv', index_col=['Ticker']).drop(columns=['Date']) X = pd.read_csv(DATA_DIR / f'general_features.csv', index_col=['Ticker']).drop(columns=['Date']) # Dashboard Explainer is fussy about Column Names X.columns = X.columns.str.replace('.', '') feature_names = model.get_booster().feature_names feature_names = [x.replace('.', '') for x in feature_names] model.get_booster().feature_names = feature_names explainer = RegressionExplainer(model, X, y) db = ExplainerDashboard( explainer, title="Stock Valuation Explainer", description= "Visit https://share.streamlit.io/gardnmi/fundamental-stock-prediction to see the model in use,", shap_interaction=False, precision='float32', decision_trees=False) db.to_yaml("dashboard.yaml", explainerfile="explainer.joblib", dump_explainer=True) db = ExplainerDashboard.from_config("dashboard.yaml") app = db.flask_server()
def test_load_config_explainer(self): db = ExplainerDashboard.from_config( self.explainer, self.pkl_dir / "dashboard.yaml") self.assertIsInstance(db, ExplainerDashboard)