0
$\begingroup$

Given a dataset with 100 observations and 3 features plus one label(regression). we train the model with 100 * 4(3 features + 1 label) data. Now can we predict the features when the label is given as input. For eg:

f1 f2 f3 Label
2  2  3  12.5
3  6  5  3.8
6  5  4  9.2
..........
..........
..........
..........

now the question is to predict f1, f2 and f3 when label is given ( if label=6.7 then predict f1,f2,f3).

It would be of great help if any suggestion or resources is provided.

$\endgroup$
3
  • $\begingroup$ Welcome to DataScienceSE. The word 'label' is normally used for a categorical target, but your example shows a numerical target. To answer your question: you can always train a model to predict every feature value from the target value, but in general it's very unlikely to work well, unless there's a specific relationship between the variables. Usually tasks/datasets are designed so that there it's possible (and meaningful) to predict the target from all the features, but the converse is seldom true. For example one may predict whether a patient has diabetis from their level of sugar at .. $\endgroup$
    – Erwan
    Aug 24, 2022 at 13:55
  • $\begingroup$ .. different times, but there's no way to predict the level of sugar at different times from knowing whether the patient has diabetis. $\endgroup$
    – Erwan
    Aug 24, 2022 at 13:55
  • $\begingroup$ What Erwan said, and there may be an infinite number of answers. If we think in terms of Y = xo + w1 * x1 + w2 * x2, then this question poses we know Y, w1 and w2, can we get x0, x1 and x2. We can get a lot of values for x0, x1 and x2 that equal Y. 1 equation and 3 unknowns. Many of these answers may not be realistic in the problem space you are solving, but I am sure I can come up with many answers that are realistic. This is an underdetermined problem. The 2nd paragraph in the intro is this problem. en.wikipedia.org/wiki/Underdetermination $\endgroup$
    – Craig
    Aug 25, 2022 at 13:09

1 Answer 1

0
$\begingroup$

Potential solutions are a linear or a Random Forest regressors.

Here is a code example, with data generated like yours:

from sklearn.ensemble import RandomForestRegressor
from sklearn.datasets import make_regression
from sklearn.linear_model import LinearRegression

#%%
X, y = make_regression(n_samples=100, n_features=1, n_targets=3,
                           n_informative=1,
                           random_state=0, shuffle=False)


print(X)
print(y)
#%%
model = LinearRegression()
# fit model
model.fit(X, y)
# make a prediction
row = [0.21947749]
yhat = model.predict([row])
# summarize prediction
print(yhat[0])

model = RandomForestRegressor()
# fit model
model.fit(X, y)
# make a prediction
row = [0.21947749]
yhat = model.predict([row])
# summarize prediction
print(yhat[0])

If the linear regression is not good enough, you can also try with a Logistic Regression instead:

https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html

More information about Random Forest Regressor:

https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html?highlight=random+forest+regressor#sklearn.ensemble.RandomForestRegressor

See also:

https://machinelearningmastery.com/multi-output-regression-models-with-python/

$\endgroup$
1
  • $\begingroup$ Does it answer your question? If not, please let me know. $\endgroup$ Sep 9, 2022 at 10:22

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.