fix minimize to work with tree models

This commit is contained in:
franzi
2022-10-17 19:17:05 +02:00
parent 40f2d06348
commit a2305c0a23

View File

@@ -23,20 +23,11 @@
"import numpy as np\n", "import numpy as np\n",
"import pandas as pd\n", "import pandas as pd\n",
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",
"from scipy.stats import pearsonr\n",
"from scipy.optimize import minimize\n", "from scipy.optimize import minimize\n",
"# machine learning stuff\n", "# machine learning stuff\n",
"from sklearn.metrics import mean_absolute_error\n", "from sklearn.metrics import mean_absolute_error\n",
"from sklearn.dummy import DummyRegressor\n", "from sklearn.dummy import DummyRegressor\n",
"from sklearn.preprocessing import MaxAbsScaler\n", "from sklearn.model_selection import train_test_split\n",
"from sklearn.pipeline import make_pipeline\n",
"from sklearn.linear_model import ElasticNetCV\n",
"from sklearn.svm import SVR\n",
"from sklearn.ensemble import RandomForestRegressor, StackingRegressor\n",
"from sklearn.model_selection import GridSearchCV, train_test_split\n",
"from sklearn import tree\n",
"from sklearn.inspection import plot_partial_dependence, permutation_importance\n",
"from sklearn.manifold import TSNE\n",
"# interactive plotting (parallel coordinate plot)\n", "# interactive plotting (parallel coordinate plot)\n",
"import plotly.express as px\n", "import plotly.express as px\n",
"# suppress unnecessary warnings\n", "# suppress unnecessary warnings\n",
@@ -350,7 +341,7 @@
" # the start value for the optimization is the original water content.\n", " # the start value for the optimization is the original water content.\n",
" # to get realistic values, we additionaly specify bounds\n", " # to get realistic values, we additionaly specify bounds\n",
" # based on the actual min/max values for the water content\n", " # based on the actual min/max values for the water content\n",
" res = minimize(_loss_fun, np.array([water_org]), bounds=[(value_min, value_max)])\n", " res = minimize(_loss_fun, np.array([water_org]), bounds=[(value_min, value_max)], method=\"Powell\")\n",
" # the optimized water content is stored in res.x (again a np.array)\n", " # the optimized water content is stored in res.x (again a np.array)\n",
" water_new = res.x[0]\n", " water_new = res.x[0]\n",
" # check the final strength prediction\n", " # check the final strength prediction\n",