# Need an algorithm to find the input factors that are most affecting the output

I apologize if this question is already answered and appreciate any pointers to existing answers. I'm not familiar with statistical or data mining terms so my search was limited to basic words used in the title of this question. I did look at some algorithms but could not decide if they serve the purpose.

I'm looking for an algorithm that can give me % probability or % confidence that out of given set of input factors which inputs are affecting the output most. Let us take an example below and assume that input and output will be recorded 4 times a day for a month.

Output:

• Phone's battery drainage
• Phone heating up (temperature).

Input:

• Ambient temperature
• Which apps were used most when the output was measured (multiple input points)
• Number of calls received and call length
• Screen brightness
• GPS connectivity enabled?
• Bluetooth enabled?
• Cellular signal strengh

If we measure this data for month, we will find that Cellular Signal Strength and screen brightness probably will be linked to Battery Drainage most. On the other hand 3D resource intensive games will be linked to Phones heating up the most. Can I deduce such relationship using any existing algorithm(s)?

## Fundamental limitations on what you can achieve

The principled answer is: No, you can't reliably deduce such causal connections. When you have only observations of the data, you can use statistical analysis to look for correlations, but you can't deduce causation. Correlation does not imply causation. You are looking for causality, but you cannot infer causality from field data (from external, uncontrolled observations of a system). To test causality you need a controlled experiment.

This is a problem not just in principle, but often in practice as well. In practice, we might have correlations among your "independent variables" or confounding factors you haven't accounted for, which causes correlations that aren't an indication of causality.

For instance, you might find that ambient temperature is correlated to display brightness (because at night it is cooler and darker, so phones turn down display brightness, whereas at day it is warmer and brighter, so phones turn up display brightness to compensate for the daytime light). Now we'd expect that when the display brightness is higher, the battery will be drained faster. Can you deduce this causal connection from statistical inference applied to some observations? Well, you might observe a correlation between display brightness and battery drain rate, which sounds good. But if display brightness is correlated to ambient temperature, then when you do a statistical analysis, you might also discover a correlation between ambient temperature and display brightness -- and that's a spurious correlation that doesn't indicate any causal connection.

That said, the pragmatic answer is to use statistical analysis of your data to look for correlations, and then hope that at least some of the correlations will represent something real. You have to go into it with eyes open knowing that some of the correlations will be spurious, for the reasons explained above, but maybe that's OK. Maybe statistical analysis can still be useful to you.

So, how should you do the statistical analysis? There are many possible ways. It's best to say what is the best; that probably depends upon what relationships between the input and output you think are plausible.

But a very simple approach that I suspect will work well for you is to use linear regression. Try to find a linear model that expresses an output variable (e.g., the battery drain rate) as a weighted linear combination of the input variables. Linear regression can find the best weights for you that minimizes the prediction error.

Then, the size of those weights tells you exactly what you want to know. Suppose you are predicting the battery drain rate, and in your linear model the weight for the screen brightness input variable is 0.7. This means that if you increase the screen brightness by adding $\Delta$, then the battery drain rate is predicted to increase by adding $0.7 \Delta$.

## Tricky details

There are a few things about your specific problem that might be a bit tricky.

One tricky aspect is the business about apps, and how to code that into a linear regression framework. One way is to pick a few categories of apps, and then have a separate indicator input variable for each category (0 if that app is not present, 1 if it is present). However, you don't want to have too many input variables, because that will require a lot more data to reliably form a linear model. A few dozen app categories might be fine, but thousands of input variables for the thousands of different possible apps probably would not be.

Another tricky aspect arises if you expect there to be non-linear dependencies, and you want to find them. For instance, you mention in a comment the possibility that low cellphone signal strength combined with running a 3D game might increase battery drain rate in a way that neither alone would. If you expect those kinds of non-linearities, one standard way to deal with them is to introduce new input variables for "interaction effects": e.g., you introduce a new input variable which is the product of the signal strength times the indicator variable that indicates whether a 3D game is running. (These new input variables are derived from the other input variables, but in a non-linear way.) You can introduce one new "interaction" input variable for each pair of original input variables that you think might exhibit a combined effect of this sort (where the effect of their combination is greater than the sum of their individual effects). This is a standard technique that you can find described in good tutorials on linear regression.

Ultimately, there's lots more to say on statistical data analysis, linear regression, and applying it to practice -- more than I can write in a single answer. I recommend you read a good tutorial or two on linear regression and maybe the relevant chapters of some statistical textbooks. If you still have more questions after all of that, it's also worth knowing about Cross Validated, a Stack Exchange site on statistics.

Well, you are asking for derivatives! You want to measure how the change of an input affects the output. That's exaclty a derivative.

Call "Cellular signal strengh" x and "Phone's battery drainage" f(x).

Let's say that you fix the cellular cellular signal strengh to a level of 3 ($x_0=3$). You measure a corresponding phone's battery drainage of 10% / hour ($f(x_0) = f(3) =$ 10% /hour).

Then you change the signal strengh to a level of 4($x_1=4$). The phone's battery drainage dropped to 7% / hour ($f(x_1) = f(4) =$ 7% / hour).

This way you estimate a corresponding change of the output with respect of the input (aka derivative) of $\frac{f(x_1) - f(x_0)}{x_1 - x_0} = \frac{7 - 10}{4-3}$ % /hour = - 3 % / hour = $f'(\xi)$ with $\xi \in [x_0, x_1]$.

You estimate that a change of signal level of 1 gives you a battery drainage 3% less than before. Note that the information it gives you information is just "local": that value is calculate in the proximity of level 3, so close to level 1 you could get a very different change.

How is that useful? Let's say that you repeat the same measurement, but this time regarding temperature. You might find out that a temperature change of 1 degree raises your battery drainage of 0.1% / hour.

Now you can compare the different effects: a small change in the signal level gives you a big change in the battery drainage, while a small change in temperature gives you a very small change. Is it what you were asking for?

A final remark: here it is very important how you gather data, how fine (=resolution) the data is and how often you get it.

If you want to gather data from a mobile phone that is under actual use and is not being tested in controlled environment, you have to make sure that the polling rate is high enough: ambient temperature might change slowly (minutes), but signal strength might change pretty fast (seconds). Thus you have to make sure that you can resolve these fast changes.

Let's formalize a little bit.

We say that the output is a vector $\vec{x} = (x_1, x_2, x_3, x_4, ...)$, $x \in S$ where S is the set of the possible values of the input. Then the output is $f = f(x)$, a function that takes the touple $\vec{x} = (x_1, x_2, x_3, x_4, ...)$ and gives you the corresponding output.

What you are computing here are the partial derivatives of $f(\vec{x})$:

$\frac{\partial f(\vec{x})}{\partial x_1}|_{\vec{x} = (x_1, x_2, x_3, x_4, ...)}$,

$\frac{\partial f(\vec{x})}{\partial x_2}|_{\vec{x} = (x_1, x_2, x_3, x_4, ...)}$, etc.

The partial derivatives are computed at particular values of the input. Look at the partial derivatives as the corresponding change of the output caused by a little variation of the input. The bigger the partial derivative, the bigger the effect. Note that the partial derivatives are calculated at a particular combination of the input. That is: at a particular screen brightness, at a particular battery level, at a particular temperature, you estimate the effect of changing the phone level by a little.

If you are lucky you will see that to some extent some variables are influential to the partial derivative: for example the partial derivative might not change with gps connectivity enabled or not (as probably will).

• Really appreciate the detailed explanation. Would this approach give me the combination of inputs that are affecting the output? After I posted the question I realized that it is never going to be a single input that will always affect the output. Its going to be a certain combination of inputs. For example Low Cellphone Signal and 3D games will drain the battery and Raise the temperature, but individually they might not affect the output significantly. Also can it rank the inputs/input groups with in the order of it weight (ability to affect the output)? – MVCNinja May 30 '14 at 16:27
• Using derivatives requires a controlled experiment. If you're just gathering data from a phone that's in actual use, you won't have the opportunity to compute derivatives exactly (you probably won't observe two time periods where all the input variables are the same except for just one). Therefore, in that setting, something like linear regression or some other statistical estimation technique is probably going to be more effective. – D.W. May 30 '14 at 16:39
• @D.W. It depends on polling rate and the size of the state space. If it's not too big and the polling rate is high enough you could estimate the gradient almost everywhere without too much hassle. Furthermore, probably here everything is almost linear, so a regression analysis is definitely the point. – Lelesquiz May 30 '14 at 16:51