I want to start off by acknowledging that this may be a dumb-sounding question to someone with more machine learning experience to me, so please go easy. Here is the background. I am currently an undergraduate assisting with research/development on a ML-driven robotic chemistry system for synthesizing silver nanocrystals. Currently we have a huge, very old, and undocumented Python codebase that manages the robot and implements various ML techniques for predicting properties of nanocrystals given the concentrations of the reagents used for their synthesis.

Right now we are using multiple polynomial regression to predict the maximum absorbance wavelength of a nanocrystal using a set of varying reagent concentrations as input attributes. We want to develop a new functionality to make this prediction in the reverse direction, or, given a target maximum absorbance wavelength we want to predict the reagent concentrations which should be used in the reaction. Because of the messy and delicate state of the code and some time constraints, we can't do the easy solution of making a new multi-target model. Here is a sample of the code we're using to implement to regression:

from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression

poly_regressor = PolynomialFeatures(degree=6)
X_poly = poly_regressor.fit_transform(X)
poly_reg_model = LinearRegression()
poly_reg_model.fit(X_poly, y)

Here X is usually 2-3 features depending on the experiment. The degree is always fixed at 6. Is there any was I could use the fitted poly_reg_model or any parameter data stored within it to make a sort of "reverse model" that would predict values of X given y? I know that this is a messy and possibly bad approach but my hand is being forced. Thanks!


1 Answer 1


If I'm understanding you correctly, you take an input x which given a 6th degree Polynomial function f gives you an output y, where your function f is the best fit onto some training data?

Polynomials are in general not injective functions which means that they are not reversible. Think y=x^2 where 4 could come from both x=+2 and x=-2. However, if you look at the Fundamental theorem of algebra you will see that your polynomial will have at least one, more likely six (details in the article) roots.

For your specific problem for each point of y you will likely be able to find multiple candidates of x that solve for this specific point. Finding the actual values of x that are roots to your polynomial can be done numerically.

  • $\begingroup$ I see, that makes sense to me. So my best bet is to get the fitted parameters from my model object, convert it into some kind of object that represents a polynomial, and then figure out a way to find it's solutions? $\endgroup$ Feb 12, 2023 at 21:18
  • $\begingroup$ Have a look at numpy.roots. It's a function to calculate the roots of a polynomial if you know the coefficients, which you should be able to obtain by calling poly_reg_model.get_params() and knowing your target variable. $\endgroup$ Feb 13, 2023 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.