# Probability of successful charging based on independent historical or sample data [closed]

I tried my best to find a solution, but failed to find a decent one. Imagine I want to charge a customer and I have last three days of random charge try data:

  +----   Date     ------   Time  ------ Amount  ------  Status ------+
|     2018/05/05    |     08:00    |     500      |       --        |
|     2018/05/05    |     12:00    |     500      |       --        |
|     2018/05/05    |     16:00    |     500      |       --        |
|     2018/05/05    |     20:00    |     500      |       OK        | <-
+-------------------+--------------+--------------+-----------------+
|     2018/05/06    |     08:00    |     500      |       --        |
|     2018/05/06    |     12:00    |     500      |       --        |
|     2018/05/06    |     16:00    |     500      |       OK        |
+-------------------+--------------+--------------+-----------------+
|     2018/05/07    |     08:00    |     500      |       --        |
|     2018/05/07    |     12:00    |     500      |       --        |
|     2018/05/07    |     16:00    |     500      |       OK        |  <-
+-------------------+--------------+--------------+-----------------+
|     2018/05/08    |     08:00    |     500      |       --        |
|     2018/05/08    |     12:00    |     500      |       --        |
|     2018/05/08    |     20:00    |     500      |       --        |
|     2018/05/08    |     22:00    |     500      |       OK        |  <-
+-------------------+--------------+--------------+-----------------+


1- What is the best way to find probability of a success charge on 11:00 O'clock tomorrow?

2- I also have access to 2K user' historical data. How can I use that data to improve probability accuracy?

EDIT: we have some random data (we could not predict by any analysis solution what happen in future), we guess there might be some pattern between different variables (person cell number, week, day, hour, amount of charge) , how could we find this pattern?

• Might also be related to this. – Farshid Ashouri Aug 30 '18 at 1:50
• What is the meaning of status? You try each day at random hour to see if the charge is realized? It happens that a charge is no successful at the end of the day? It can take longer? The samples comes from different clients? Multiple charges for same client? – rapaio Sep 6 '18 at 18:09
• Well, we have a limit of trying to charge users only 4 times and 300 cents. The sample belongs to a one user here. – Farshid Ashouri Sep 6 '18 at 18:32
• Your question is difficult to understand. I suggest that you may explain better your problem. – Rafael Marazuela Sep 6 '18 at 20:08
• You are right. It might be my fault. Let me explain you more. I have a list of 1 million users and I have to charge them 300 cents per day. They might have enough credit or they might have not. We dont know that. All I can do is try 4 times (arbitrary amount) to check if they have enough credit or not. How can I found best times to charge a user based on few days of previous data? – Farshid Ashouri Sep 6 '18 at 20:39

The key variable you are interested on is $X_{iht}$ = balance of the bank account of individual $i$ in hour $h$ on day $t$. Balances might vary across individuals depending on their income level, their type of job, family composition, and so many other variables. Balances might vary over days of the week/month/year too (shopping day, direct debits, salary payment, Christmas, etc). Unless you have some strong assumption of how this variable distributes (for which you would need to look at other data), there is nothing you can say beyond descriptive statistics. As far as I know, all survival and related model (parametric) are based on probability distributions assumptions.

And even these type of models might not be very helpful, because it could well be that the individual had no sufficient money a few hours your charge was successful. In other words, you cannot deduce that because one day your charge was successful at 16:00 it could also have been successful at 22:00 (which is different to data where if you die at 16:00, you are dead at 22:00 too). Your optimal data collection in that sense would be not to stop, even if the event was successful. Here again you need to think on the assumption of the distribution regarding $h$.

In conclusion, your data is totally helpless to answer your question unless you are willing to be explicit on the distribution behind it. For example, if you were willing to assume that the balance of this particular individual (or all in the extended dataset) is the same every day (this is, that the distribution of $X_{iht}$ does not vary across $i$ and $t$), then based on your data you should charge at 16:00 because you measured 3 times and two were successful. On the contrary, 8 or 12 o'clock would not be good because they were never successful. It is evident however that this is a terrible assumption.

• Thank you. Based on a colleague request, I updated my question to fit the requirement. Please take a look. – Farshid Ashouri Sep 8 '18 at 20:44

I am going to make these assumptions:

1. The success rates $\theta_i$ of an hour $i$ are independent from one another.
2. (The success rates stay the same between any two days.)
3. The costumers have independent success rates.
4. Prior to observations we assume all possible rates to be equally likely.

The first assumption is made because we have no indication how the hours could relate. It means we will simply not use $\theta_i$ to make any predictions for a different hour.

We only gonna look at one costumer. The same logic can be applied on any other costumer individually.

We will call the number of recorded successes $s_i$ and the total number of trails $n_i$ for a given hour $i$.

The trial weather the charge was successful is a Bernoulli trial. Hence the number of successes $s_i$ are binomially distributed. We are interested in the probability density function of $\theta_i$. This can be calculated by Bayes' theorem like here. To fulfill assumption 4 we assume prior $\theta_i \sim Beta(1, 1)$. Hence your expected success rate after making an observations is: $$\mathbb E[\theta_i] = \frac{s_i + 1}{n_i + 2}$$

In order to maximize your chances of charging successful you can try to charge at the 4 hours with the highest $\mathbb E[\theta_i]$. Of course all are equal before you make any observations, when $n_i=0$ and $s_i=0$. But this will change when you gain data on the client.

Concerning your edit: You suggest there might be some dependencies to discrete variables like phone number or day of the week. Since I do not know how rates for different days of the week or phone numbers relate I can only model them independently. This would mean to calculate the rates for each day or phone number individually. Lets call $j$ the day then $$\mathbb E[\theta_{i,j}] = \frac{s_{i,j} + 1}{n_{i,j} + 2}$$ You can do that for any variable $j$ and only use data from the day or phone number $j$. You can then compare the rates between different $j$. If we want to make this any more powerful we need to know how the rates between different $j$ could be connected. E.g. are success rates between neighboring days more similar then between distant days.

Pattern Recognition: What you could do to find patterns and relations between the $\theta_{i,j}$ is to look at the vectors $$x_k=(\mathbb E[\theta_{1,1}],\mathbb E[\theta_{2,1}],\dots,\mathbb E[\theta_{m,n}])$$ where $n$ is the number of different hours and $m$ the number of values for $j$ (days or phone numbers) for all clients $k$. Your data set is $X=\{x_1, \dots, x_N\}$ where $N$ is the number of clients. Then you could apply principal component analysis to find linear dependencies between the $\theta_{i,j}$. If the explained variances is large for the first components and drops of quickly, then the first components correspond to recurrent patterns in your data. This corresponds to the "variance explained" plots in this example.

It is up to use how to use or interpret these patterns. If you assume that everything not matching the patterns is random noise you could project the $x_k$ of a new client $k$ on a linear combination of these patters in order to remove that noise. In R this could be done like that:

X <- rbind(x1, x2, ..., xN) # your data set
xk <- c(Eo[1,1], Eo[2,1], ..., Eo[m, n]) # data of the new client

pc <- prcomp(X)
# make a plot to see how many components to use:
plot(sv$sdev^2/sum(sv$sdev^2), type = "b", pch = 16,
xlab = "components", ylab = "variance explained")

l <- the number of components that you choose
projection <- pc$rotation[, 1:l] %*% t(pc$rotation[, 1:l])
shift <- pc$center - (pc$center %*% projection)

new_xk <- xk %*% projection + shift # projected data of the new client


Then the 4 maximum values of new_xk per day/phone number are where you want to attempt charging the client. So for a given $j$ the 4 best hours are order(new_xk[(j*m+1):(j*m+n)], decreasing=TRUE)[1:4]. Note that these cannot be interpreted as expected success rates anymore.