Python Forum
Optimizing a model output (Y) with some (X) parameters defined - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Optimizing a model output (Y) with some (X) parameters defined (/thread-19130.html)



Optimizing a model output (Y) with some (X) parameters defined - pierrelouisbescond - Jun-14-2019

Hi Everyone,
(Disclaimer: I am quite a beginner onPython and Data Science in general… Smile )

I have designed and published my 1st kernel on Kaggle (here: https://www.kaggle.com/plbescond/quality-prediction-r-0-81-mse-0-12), based on a nice industrial Kaggle dataset (and this is not for a specific competition, just for fun).

So I now have a model which I can run to to predict a "Y" (%silicate rate) according to 10 parameters (Xs).
Note: the Xs input is an array like this:
Output:
[[-0.33660127 0.61050275 -0.19441589 -0.1988209 0.3357553 0.16947863 0.11750669 -0.09867687 0.29995688 0.03718947]]
Now I would like to:
1/ find a way to define the values of the 10 Xs to reach a specific Y value
2/ find a way to set values for some Xs (let's say 4 out of 10), set my Y target… and get the corresponding values for the remaining Xs, like this:
Output:
[[-0.3 (defined) X2? X3? X4? X5? 0.2 (defined) X7? X8? 0.4 (defined) 0.05(defined)]]
I have tried to convert the model into a function and optimize it but it does not get me anywhere (probably by a lack of knowledge), like this:

filename = 'mining_model.sav'
gbr = pickle.load(open(filename, 'rb'))

# Parameters Optimization
def gbr_function(x):
    y = gbr.predict(x)
return y

… and then I tried some different optimization algorithms from "scipy.optimize" with no luck…
Anyone who could guide me a bit on how to do that?
Thanks,
Pierre-Louis