# Can we predict features from labels in machine learning

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.

• 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 .. Aug 24, 2022 at 13:55
• .. different times, but there's no way to predict the level of sugar at different times from knowing whether the patient has diabetis. Aug 24, 2022 at 13:55
• 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 Aug 25, 2022 at 13:09

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