Binning long-tailed / pareto data before clustering

There are several approaches. You can start from the second one.

 Equal-width (distance) partitioning:

It divides the range into N intervals of equal size: uniform grid
if A and B are the lowest and highest values of the attribute, the width of intervals will be: W = (B-A)/N.
The most straightforward
- Outliers may dominate presentation
- Skewed data is not handled well.

 Equal-depth (frequency) partitioning:

It divides the range into
N intervals, each containing approximately
same number of samples
Good data scaling
Managing categorical attributes can be tricky.

Other Methods

Rank: The rank of a number is its size relative to other values of a numerical variable. First, we sort the list of values, then we assign the position of a value as its rank. Same values receive the same rank but the presence of duplicate values affects the ranks of subsequent values (e.g., 1,2,3,3,5). Rank is a solid binning method with one major drawback, values can have different ranks in different lists.
Quantiles (median, quartiles, percentiles, ...): Quantiles are also very useful binning methods but like Rank, one value can have different quantile if the list of values changes.
Math functions: For example, logarithmic binning is an effective method for the numerical variables with highly skewed distribution (e.g., income).

Entropy-based Binning

Entropy based method uses a split approach. The entropy (or the information content) is calculated based on the class label. Intuitively, it finds the best split so that the bins are as pure as possible that is the majority of the values in a bin correspond to have the same class label. Formally, it is characterized by finding the split with the maximal information gain.


Assuming you already have resized and other preprocessing your image data into a multi-dimensional numpy array and split the data into training and test.

To use the flow() method. You first want to create a generator using ImageDataGenerator(). The example below DOES NOT DO image augmentation. It will feed only the images in your training set. I added the rescale parameter in case one had not normalized the pixel data.

You then pass your training data to the fit() method of the generator (datagen.fit()).

datagen = ImageDataGenerator(rescale=1./255)
datagen.fit(x_train)

Now you can train your model using the fit_generator() method for your model.

model.fit_generator(datagen.flow(x_train, y_train, batch_size=batchSize),
                    steps_per_epoch=len(x_train) / batchSize, epochs=epochs)

You can do it the manual way:

for epoch in range(epochs):
    for x_batch, y_batch in datagen.flow(x_train, y_train, batch_size=batchSize):
        model.fit(x_batch, y_batch)

Here's the link to the corresponding Keras documentation: https://keras.io/preprocessing/image/


Free API for historical weather US data?

Maybe you can use NCEI Data

And use "httr" package to access the API in r.


Binary classification using images and an external dataset

Yes you can most certainly combine the two ways of information in CNNs.
Let's take a look at a CNN:

Roughly speaking, CNNs consist of two parts:

one that has convolutional layers and optinally pooling ones
and one that has fully connected layers.

The first is used for extracting features from the image, while the second is used for using these extracted features to classify the image. The last part essentially is like a regular fully-connected Neural Network.
If you want to add more information to the CNN, which is not an image, you can add this to the first fully connected layer of the network. This way this information bypasses the feature extraction step (which is relevant only for imaging data) and is used only for classification.


Sum of squares for matrix valued data over $\mathbb{R}$ and $\mathbb{C}$

Essentially you want to pick a function that will give you the "size" of a matrix. The most obvious way I can think of is by choosing a matrix norm, which is a map $\lVert \cdot \rVert \colon \mathbb{R}^{k, k} \to [0, \infty)$ (or you could generalise to a complex $k \times k$ matrix if you wished).
Your suggestion seems similar to computing
$$S = \sum_i (M_i - \hat M_i)^2$$
then using the Frobenius norm $\lVert S \rVert_F$ to turn this into a real number. The Frobenius norm essentially means "squash $S$ into a vector of dimension $k \times k$, then compute the Euclidean norm".
There are plenty of other norms you could consider, such as the operator norms. Interestingly enough it can be proved that any two matrix norms are equivalent up to a constant scaling factor, so your choice of norm isn't particularly important, and minimising the "sum of squares" under any norm should be more or less the same.


How would I be able to improve my CNN model (Keras)?

The first thing you should notice is that you've almost ruined your input signal. Take a look at a $28\times28$ image of a face? what can you see? is there any difference between a teenager and a middle-aged person? The point is that the network should be trained using data that does not have high Bayes error which means you as an expert can distinguish between inputs and label them correctly. Increase the size of your inputs. By doing so, if you use the current regime, you may have lots of trainable parameters between dense layers and convolutional layers. Consequently, try to employ more convolutional layers and some pooling layers among them. Also, try to add more dense layers with more neurons in each.


tensorflow pseudo inverse doesn't work for complex matrices!

I just faced the same situation. If you need to explicitly build the inverse, check this paper:

https://pdfs.semanticscholar.org/f278/b548b5121fd0d09c2e589439b97fad16ece3.pdf

In particular, given a Matrix M that you need to invert, you can just do:

    A = tf.math.real(M)
    C = tf.math.imag(M)

    r0  = tf.linalg.pinv(A) @ C
    y11 = tf.linalg.pinv(C @ r0 + A)
    y10 = -r0 @ y11

    M_inverse = tf.cast(tf.complex(y11,y10), dtype = M.dtype)

The complexity is a bit higher than the pure-complex implementation, but so far it has proven to be pretty stable for me.

(just copying my answer from your other post:
https://stackoverflow.com/questions/60025950/tensorflow-pseudo-inverse-doesnt-work-for-complex-matrices/60128892#60128892)


For text classification that has innumerable features, how do I choose the number of neurons and layers for MLPClassifier?

As you know, you can basically reduce the number of features by choosing best discriminant ones.
If you used scikit-learn vectorizers like TF-IDF, they have the parameter max_features which chooses $n$ best features for you. But my point is something else:

All BoW models which I guess you used are unsupervised. I strongly recommend that you use mutual information between features and targets (you may also search "Supervised TF-IDF" to get more insight) and choose your best features more effectively. At the end you need to choose $n$ neurons as input layer but with this way you may be able to get the most out of less number of features.

If you are familiar with autoencoders, they are also a pretty strong way to reduce the number of features effectively.

Hope it helps!


Same input size but cannot fit the model in keras

ValueError: Error when checking input: expected data to have shape (None, 224, 224, 3) but got array with shape (9730, 244, 224, 3) it clearly says that while preprocessing that either X_train or X_valid have (9730, **244**, 224, 3) instead of (9730, **224**, 224, 3)


Welcome to the site - great first question!

In your scenario (assuming I understand it correctly) you have a saved model in python right? So, what I would do is create a new API layer (written in python, using something like the Flask framework) and I would create API endpoints for your algorithmic functions (could be as simple as just 1 for your predict function).

From there, you could run that python script on a server and expose that API to the outside world and it will run/respond just like any other REST API service. At that point, it would be fairly trivial to write C# code to access the API (or any other language you want).


How does personalized machine learning work?

You should google recommendation systems. A good starting point is this place https://paperswithcode.com/task/recommendation-systems where they have some papers on recommendation systems with code.


How to build Non Linear Vector auto regression using Neural Nets

The type of artificial neural nets (ANN) you are looking for is ANN with cycles which is widely known as recurrent neural networks(RNN). As you have mentioned Vector Auto regression (VAR) I would recommend you to check out this paper which compares VAR to RNN on two different tasks pertaining to two different real world datasets.

One specific type of RNN is Long short term memory (LSTM). It is particularly good at learning over long sequences. Although RNN is also perfectly capable of that theoretically, but with little empirical success. So, in recent years LSTM has gained huge popularity and has been very successful over sequence learning tasks. I would recommend this book which provides a fair bit of understanding of ANN with cycles and the tasks they are being applied to.

For implementation of RNN there are many APIs available. Keras provides a high level API for the same.

For modelling multivariate time series with LSTM check out this tutorial.

You can also have a look at this question that I answered on cross validated.


Does dataset training and test size affect algorithm?

It is completely normal in some circumstances. If you consider the learning problem from a statistical perspective, learning is done by trying to estimate the conditional estimate of your output variable given input variables. When you are doing learning you basically have to main components: sample data from training and the learning algorithm, and you use both to build an estimation of the aforementioned conditional probability. Now consider the relation of each component with the desired estimated probability.

Training sample

Training data is only a sample from all the possible data. You do not have all the possible data since if you would have it you would not need to do learning, right? So a sample is just a fraction of the data. This sample could cover more or less the whole domain of the possible data. An immediate thought is that a bigger sample is better than a smaller one. As an extreme case to illustrate the idea is to have only one observation. But the size of the sample is not the whole story. It is possible that the probability you want to estimate is very complex. The complexity of that space requires also more data than a simple probability space. To give an example consider the problem of learning the mean of the heights of males from USA. Having a small random sample often would be enough if you assume a normal distribution. One the other hand take the example of learning to recognize speech. Since pronouncing is not the same against individuals you would need a pretty big sample to unveil the useful relation needed to predict and throw away things which are not useful in the data.

Model/learning algorithm

Not any model is appropriate to express any true model of the signal you learn. For example if your true signal resembles a second degree polynomial would be impossible to fit properly with a linear model, other than some particular cases. So there is a complexity in the model too, which could be compared with the complexity of the conditional probability you want to estimate during learning. Even if you know the true model and you learning model is able to describe it, sometimes you need more data to make the model able to fit. As another example consider a random forest which estimates a simple line. Random forest is very flexible since the underlying statistical model is basically a constant given a local region in the input space. Considering that, even if the model would be capable of estimating the true model, since the model is a local approximation, you need plenty of data in every useful region of the space, to learn a good approximation.

Conclusion

We considered the individual component comparisons with probability you want to estimate. But you have both. This makes even harder to understand what is happening behind the walls of learning. Thus there are no universal ways of telling when data is enough for a given model. So this is why is often the case that one algorithm can have different accuracies for different training set size and for different algorithms the required training set size to have approximate equal accuracies.

One thing I tried often in practice is given a learning model to check how accuracy evolves as the learning sample size increase. If your training sample is large enough you have typically a region in a small sample size where error is large due to not enough data. After that you would have a region where errors stays approximately the same and this perhaps is where your model do it's best. Also is possible for even larger sample sizes to have a decrease in performance for some models, maybe do to inability of the model to describe what is there or due to overfitting or some other cases.

You can trace this kind of behavior using some sort of bootstrap validation, where the sample used for training is taken repeatedly for increasing lengths. Something like 20 samples with 5% size, 20 samples with 10% size, and so on. This kind of information can give you an idea between the relation of the sample size with your learning problem for a given algorithm.


The problem with Sankey diagram in your case is that you will duplicate all the nodes (on the left, and on the right), that is messy.

Networks are better, but nodes are not well structured.

I suggest to try chord diagrams for such data.

One of the greatest examples of chord diagram was build with d3.js, and based on migration flows dataset. Here is an R wrapper for d3.js chords. Or you can try to reproduce this manual.


Comment above to SO post is spot on. A custom callback, as provided in that post, is the solution and the term 'baseline' is not meant to be interpreted as a threshold.


PCA scikit-learn - ValueError: array must not contain infs or NaNs

My guess is the issue is a combination of whiten=True and the largest value equal to the largest possible value of a float64.

From scikit-learn's PCA docs:

  When True (False by default) the components_ vectors are multiplied by
  the square root of n_samples…

That creates an overflow issue which results in the ValueError exception.


What models are used to get the Next Best Action to convert a physician from a non writer to a write?

Expanding on my comment, the simplest predictive model would be to just compute the conversion rates Pr(conversion | action) for each action {A,B,C,D, ... }.

A solution in R:

library(dplyr)
library(tidyr)

set.seed(100) # for reproducibility
action <- sample(letters[1:5], 100, replace = TRUE) # dummy up sales actions (independent variable)
converted <- as.logical(rbinom(100, 1, prob = .5))  # dummy up physician conversion (dependent variable)

(df <- data.frame(action = action, converted = converted))

# Compute conversion rates for each action
conv_df <- df %>%
  group_by(action, converted) %>% # unique combinations of action by converted
  summarize(freq = n()) %>% # compute freq of unique combinations
  spread(converted, freq) %>% # spread rows to cols
  mutate(rate = `TRUE`/sum(`TRUE`,`FALSE`)) # compute conversion rate

conv_df[order(-conv_df$rate),] #reverse sort

##Source: local data frame [5 x 4]
##Groups: action [5]
##
##  action FALSE  TRUE      rate
##  (fctr) (int) (int)     (dbl)
##1      d     8    13 0.6190476
##2      e     7    11 0.6111111
##3      a     5     6 0.5454545
##4      c    13    10 0.4347826
##5      b    17    10 0.3703704

The solution above assumes the application is to be some sort of guide for sales reps... if you are wanting to model the distribution of actions in sales contexts, you would need to compute the prevalence of each action as well.


Resources for data science applications in finance/banking

Take a look at O'Reilly free Ebooks There are a couple of resources for banking/finance/fintech.

There are some sites from which you can work on for learning more about predictive modelling in this sector:

1.) https://inclass.kaggle.com/c/name-that-loan-open/data - Kaggle dataset   for prediction of interest rates

2.) https://datahack.analyticsvidhya.com/contest/practice-problem-loan-prediction-iii/ - Dataset on Analytics Vidhya for loan prediction

3.) There is also a twitter handle with the name @StatCan_eng posting datasets related to Canada specifically.


Training a Graph model like an Artificial Neural Network

First, a note: don't let the graph structure make you think that this can be addressed with neural networks; this structure only suggests that this is a hierarchical model.

Second, let's take into account the following:

In your first figure, you don't connect A, B or C to the output. I assume that there is a relationship from A,B,C to output.
You mention that you have expert a priori knowledge on the relationships from A to B and from A to C.
I also assume that A, B, C and the output are numeric variables.
We don't know whether A, B, C and the output can be observed or not.
We don't know why there are 3 lines from A to C and 2 lines from A to B, so I will not take this into account.

You may want to provide more information if any of the assumptions above is not correct.

Now:

If only A and the output are observable, we are talking about a latent variable model. Latent variables are best suited for Hierarchical Bayesian methods. If the relations between variables are linear, you can model this as a bayesian linear model, e.g. hierarchical bayesian regression to model your variables and inject your prior knowledge as prior distributions over the weights. Here you can see the application of hierarchical bayesian regression to a latent variable model. This kind of methods are simple and interpretable, they handle prior knowledge graciously and they handle uncertainty.

If all variables are observable, you can define a combination of different extremely simple "neural network" models to approach your problem: Network 1 would receive A and output C; Network 2 would receive A and output B; Network 3 would receive A, B and C and generate the output. If the relationships among variables are linear, Network 1 and Network 2 are simple multiplications. You can then initialize their weights with your prior knowledge. The training would adjust the weights for everything to fit, but will not give you insight about the relationships except the fitted weights.

I suggest you think about whether bayesian hierarchical models can fit your problem.


Lower Variance vs. Higher Validation Scores

It seems like both models are on par in terms of performance. It will be interesting to see what would happen if you combine predictions from both models via a simple average. In many cases an ensemble of models has shown to yield better performance than any single model.
So maybe it turns out you want to keep the best of both worlds by averaging.


Limitations on the number of items to use in apriori algorithm?

A first count on items can prune some of them. If you have only 20 records you can simply count the occurrence of items in dataset and prune those items which did not happen enough because their supersets also do not happen frequently and them make item-sets based on the rest of items.


Deep Neural Network: Output a Magnitude, not merely a Category

You simply need to make your last layer have 1 neuron and no activation function, so that the output of the network is a single number.

Other than that make sure that you select a loss function for regression (e.g. mean absolute error, mean squared error, etc.)


Unable to immediately continue Jupyer Notebook after closing then reopening the project

If you

run a jupyter server
open a new notebook with one cell: x=1
close the notebook
re-open the notebook
add another cell under the 1st: x+1

it would output 2, showing that the variable you had set is still in memory in the kernel

But, if you completely shutdown the jupyter server, or if you shutdown the kernel of your notebook, then you'll need to re-run the whole thing.

EDIT: JupyterLab is now in Beta and worth trying out as recommended here


Anomaly detection using clustering of highly correlated Categorical data

Your problem is actually a regression problem rather than general clustering, you look for the values far away from the regression line, outliers in the sense of regression. Therefore fit the regression line and filter the values with the largest residual errors which are your "bad" values in the sense of not following the correlation structure given by your two variables.


Effects that Empty cells have in Unsupervised Machine Learning

Empty cells can be considered NaN of missing values. There are several ways to work with missing values. You can check this source:

Encode NAs as -1 or -9999. This works reasonably well for numerical features that are predominantly positive in value, and for tree-based models in general. This used to be a more common method in the past when the out-of-the box machine learning libraries and algorithms were not very adept at working with missing data.
Casewise deletion of missing data. Here you simply drop all cases/rows from the dataset that contain missing values. In the case of a very large dataset with very few missing values, this approach could potentially work really well. However, if the missing values are in cases that are also otherwise statistically distinct, this method may seriously skew the predictive model for which this data is used.
Another major problem with this approach is that it will be unable to process any future data that contains missing values. If your predictive model is designed for production, this could create serious issues in deployment.
Replace missing values with the mean/median value of the feature in which they occur. This works for numerical features. The choice of median/mean is often related to the form of distribution that the data has. For imbalanced data, the median may be more appropriate, while for symmetrical and more normally distributed data, the mean could be a better choice.
Label encode NAs as another level of a categorical variable. This works with tree-based models and other models if the feature can be numerically transformed (one-hot encoding, frequency encoding, etc.). This technique does not work well with logistic regression.
Run predictive models that impute the missing data. This should be done in conjunction with some kind of cross-validation scheme in order to avoid leakage. This can be very effective and can help with the final model.
Use the number of missing values in a given row to create a new engineered feature. As mentioned above, missing data can often have lots of useful signal in its own right, and this is a good way to encode that information.


Could someone explain to me how back-prop is done for the generator in a GAN?

There is really nothing special about the backpropagation algorithm in a generative adversarial network (GAN). It is the same as that of a convolutional neural network (CNN), as CNNs are usually what the generator and discriminator of the GAN are made of. I will assume the MNIST toy example for the explanation and I will provide code to get a GAN working below.

The GAN

A GAN is composed of a discriminator and a generator. Each of these are held constant while training the other. We will thus alternate between training the discriminator and the generator. This is done separately. Training the discriminator is much easier so lets look at that, then we will look at training the generator as you asked in your question.

Training the discriminator

The discriminator has two output nodes and is used to distinguish real instances from artificial instances. To train the discriminator we will generate $m$ instances using forward passes from the generator, these are the artificial instances, their label will be $y = 0$. To generate these we simply pass a noise vector as the input to the model. We will also use $m$ instances from the real data these will have labels $y = 1$.

We can then see that the discriminator is trained exactly the same way as a basic classification CNN with 2 output nodes. I will describe the training process of a CNN below.

Training the generator

When we train the generator we will keep the discriminator fixed, this is necessary as to not saturate our parameters and make the discriminator too strong to ever beat. So what we essentially have is a CNN (the generator) connected to another CNN (the discriminator). The connecting nodes between these two models is going to be output which will generate the desired images once trained. Do note that the generator wants the instances it will produce in this case to be classified by the discriminator as being from the real distribution, so they will have labels $y = 1$.

All together this is just a CNN and the backpropagation will be computed in the exact same way. First we pass through a noise vector, it goes through the generator, some random image gets produced at its output, that then goes through the discriminator and gets classified as $artificial$. But, we are expecting the discriminator to be fooled in this case, so this is an error, it should have been labeled as $real$. We then use backpropagation to get the error contribution of each model parameter. We will then use gradient descent to update all the parameters associated with the generator.

Backpropagation

This is a method used to compute the contribution of each parameter on the error term. We then use gradient descent to update these parameters such that the next pass through should result in a lower loss rate. Picking the right loss function is essential for this process. For classification tasks, as is the case with a GAN, we typically choose binary cross entropy as defined by

$L = - ylog(\hat{y}) - (1-y)log(1-\hat{y})$

and over $N$ instances as is typically the case for stochastic gradient descent the loss function is

$L(w) = - \frac{1}{N} \sum_{n = 1}^N \big[ y_n log(\hat{y}_n) + (1-y_n)log(1-\hat{y}_n) \big] $

where $y$ is the true label and $\hat{y}$ is the predicted label.

Backpropagation in deep neural networks

Take a look at this answer here which describes the process of using backpropagation and gradient descent to train a single neuron perceptron, and then a multi-layered network.

The only difference is we are using the binary entropy loss function here which has a different derivative with respect to $\hat{y}$. This becomes

$\frac{\partial L}{\partial \hat{y}} = - \frac{1}{N} \sum_{n = 1}^N \Big[ \frac{y}{\hat{y}} - \frac{1-y}{1-\hat{y}} \Big]$

You will then backpropagate this loss through the network by using the chain rule with the activation functions you selected at each layer.

Backpropagation in a CNN

Please refer to this answer for extensive details and a derivation of backpropagation for a CNN. The process is very similar to that for a deep neural network. However, the CNN uses the cross-correlation function at each layer, so you need to backpropagate the loss function through the derivative of this function. That question asks about the inner working of a CNN with two outputs very much like our discriminator.

Finally, in order to train the generator, just imagine the same process with more convolutional layers ahead of it. When we have the associated gradient $\nabla L(w)$ for each parameters, only apply the gradient descent algorithm to the parameters that are a part of the generator model. I am sure that through these derivations you will see that the number of intermediate nodes between layers does not affect the backpropagation algorithm. It remains the same process. You should also be convinced that for a non-human the intermediate nodes that are the generated image from the GAN, are no different from any intermediate nodes in the model. We simply train these intermediate nodes in such a way that we can perceive some meaning, such as generating instances of the MNIST dataset.


Is $R^2$ an appropriate evaluation metric for k-Nearest Neighbors?

$R^{2}$ is a cursory measure of goodness of fit of a linear model to the data and it is used in regression analysis. It appears to be a popular choice when deciding between linear and non-linear regression models.

It seems you intend to use kNN for classification, which has different evaluation metrics than regression. Scikit-learn provides 'accuracy', 'true-positive', 'false-positive', etc (TP,FP,TN,FN), 'precision', 'recall', 'F1 score', etc. for evaluating performance of a classifier.

bonus: kNN are simple classifiers that are used when data shows local structure but not global structure, i.e. data with same label are found in multiple localized clusters in the data space. The key parameter to tune is 'k', which should be based on the size of these localized clusters as you would stand to achieve considerably different results with different values of 'k'. You can do a grid-search (also in scikit-learn) to tune your parameters (including 'k' of course).

evaluation metric: accuracy or ROC or mean Average Precision or F1-score: There are several metrics to choose from and the choice is based on the task you are performing and what your priorities are. (you can look up these metrics for more details) but you can begin with accuracy for starters.


Data science / machine learning books for mathematicians

First of all, data only comes in so many forms that it might make sense to stick to a more "concrete definition". Data Science is necessarily practical. But here are a few other books with a more theoretical grounding. Others will certainly know many more...

A probabilistic theory of pattern recognition by Devroye, Györfi, Lugosi
An Introduction to Computational Learning Theory by Kearns
Information theory, inference and learning algorithms by MacKay
Machine learning: a probabilistic perspective by Murphy
Understanding machine learning by Shalev-Shwartz, Ben-David

However, research in machine learning is mostly found in journals and papers. It will be hard to find one or a few books that cover everything you want to know.


What is the difference between shuffle in fit_generator and shuffle in flow_from_directory?

From fit_generator() documentation:

  shuffle: Boolean. Whether to shuffle the order of the batches at the beginning of each epoch. Only used with instances of Sequence
  (keras.utils.Sequence). Has no effect when steps_per_epoch is not
  None.

So if you are using a generator and set steps_per_epoch it would have no effect. In case of using a Sequence generator, it would get the batches in different order at each epoch. For example, in first epoch it might get my_seq[0] and then my_seq[1] and then my_seq[2] (and so on) and in the second epoch it might get my_seq[2] and then my_seq[0] and then my_seq[1] and so on for the next epochs (i.e. note that my_seq[i] is the i-th batch generated by the Sequence generator we have defined).

From flow_from_directory() documentation:

  shuffle: Whether to shuffle the data (default: True)

It is not clear when and how shuffling is done. So we must take a look at the source code. By doing so, we find out that flow_from_directory() method returns an instance of DirectoryIterator class which in its docstring we can see the following:

  shuffle: Boolean, whether to shuffle the data between epochs.

So it would shuffle all of the data (i.e. list of all the training images to be read at each epoch) at the beginning of each epoch.


Do CNN convolution and pooling layers get backpropogated?

All layers of a neural network take part in the back-propagation process.
This includes the convolutional layers and the pooling layers. In general, every step of the network that the input has to go thru, the back propagation goes thru as well (in reverse order).

However, not all layers contain trainable parameters. For example standard pooling layers (max-pooling, average-pooling) and standard activation layers (sigmoid, ReLU, softmax) don't have any parameters to adjust. They still take part in the back propagation, contributing their partial derivatives, but they just have no weights that can be updated.

The convolutional layers do contain weights that are updated during the process (the parameters of the filter and their bias).

  Note: I assume that what you refer to as "feed forward part", are the
  fully-connected layers that are usually placed as the final layers of
  a network. In standard CNNs, all the network is a "feed forward part", (including convolutional layers)
  it just means that the input goes thru a sequential pipeline until
  becoming the final output.


Does high accuracy metrics with small (but equally sampled) dataset means a good model?

You can do a crossvalidation to be sure your testing set is not just very easy to classify.

If it is possible, you could try to augment the size of your training set by doing some rotation, shift, flip ... If you are using Keras, you can read this blog.


Confusion-matrix clarification from Python

it's the first one

0   [[724258    438]
1   [ 25396    302]]
       0         1

According to the documentation

sklearn.metrics.confusion_matrix(y_true, y_pred, labels=None, sample_weight=None)

  labels : array, shape = [n_classes], optional List of labels to index
  the matrix. This may be used to reorder or select a subset of labels.
  If none is given, those that appear at least once in y_true or y_pred
  are used in sorted order.


Is ARIMA appropriate for time series prediction involving a mix of explanatory and independent variables?

The correct name of what you are looking for is: ARIMAX, the ARIMA model works without covariables, the X (exogenous variables) include the possibility of having other explanatory variables.


I get asked this question all the time, so earlier this year I wrote an article (What is Data Science?) based on a presentation I've given a few times. Here's the gist...

First, a few definitions of data science offered by others:

Josh Wills from Cloudera says a data scientist is someone "who is better at statistics than any software engineer and better at software engineering than any statistician."

A frequently-heard joke is that a "Data Scientist" is a Data Analyst who lives in California.

According to Big Data Borat, Data Science is statistics on a Mac.

In Drew Conway's famous Data Science Venn Diagram, it's the intersection of Hacking Skills, Math & Statistics Knowledge, and Substantive Expertise.

Here's another good definition I found on the ITProPortal blog:

  "A data scientist is someone who understands the domains of programming, machine learning, data mining, statistics, and hacking"

Here's how we define Data Science at Altamira (my current employer):

The bottom four rows are the table stakes -- the cost of admission just to play the game. These are foundational skills that all aspiring data scientists must obtain. Every data scientist must be a competent programmer. He or she must also have a solid grasp of math, statistics, and analytic methodology. Data science and "big data" go hand-in-hand, so all data scientists need to be familiar with frameworks for distributed computing. Finally, data scientists must have a basic understanding of the domains in which they operate, as well as excellent communications skills and the ability to tell a good story with data.

With these basics covered, the next step is to develop deep expertise in one or more of the vertical areas. "Data Science" is really an umbrella term for a collection of interrelated techniques and approaches taken from a variety of disciplines, including mathematics, statistics, computer science, and software engineering. The goal of these diverse methods is to extract actionable intelligence from data of all kinds, enabling clients to make better data-driven decisions. No one person can ever possibly master all aspects of data science; doing so would require multiple lifetimes of training and experience. The best data scientists are therefore "T-shaped" individuals -- that is, they possess a breadth of knowledge across all areas of data science, along with deep expertise in at least one. Accordingly, the best data science teams bring together a set of individuals with complementary skillsets spanning the entire spectrum.


Explanation of random forest performance difference to when using categories and when using dummy variables

It should work: the variable is ordinal so using numerical values makes sense.
So there's a bug somewhere, here are a few suggestions of things to look at:

Possibly a type conversion error somewhere: make sure the variable is interpreted as numerical.
Check whether the model actually uses the variable: if not then it's likely some type error; if yes then I would investigate what goes wrong: for example it might help to plot this variable vs. target in the two cases where the variable is categorical or numerical.
Maybe some difference between the preprocessing of the training and test set: apply the model on the training set, if the performance is good then it's likely that there's something wrong in the preprocessing of the test set.


Neural Network Golf: smallest network for a certain level of performance

You might be interested in this paper that explores a few of the questions you are asking: http://arxiv.org/pdf/1312.6184.pdf. It is aptly titled: "Do Deep Networks Really Need to Be Deep?"

The crux of the matter is that deep networks allow for a LOT of non-linearity in the data that is being described. For CIFAR-10, I suspect that something similar to what works well for MNIST will work well. Yan LeCunn's page about MNIST results gives a lot of clues about models with few parameters: http://yann.lecun.com/exdb/mnist/

The double-problem of image classification is that in addition to the classification you need to extract features somehow. Often the parameters in deep networks go towards feature extraction rather than the classification itself, which is usually a softmax multi-class logistic regression classifier.


Building a time-series demand forecasting model

Time series forecasting with exogenous variables (a.k.a. external regressors, like GDP you mentioned) can be complex. I'd suggest starting with an ARIMA (autoregressive integrated moving average) model that includes exogenous variables, like arima in R or sarimax from statsmodels in Python.


Good books for Hadoop, Spark, and Spark Streaming

There's such an overwhelming amount of literature that with programming, databases, and Big Data I like to stick to the O'reilly series as my go-to source. O'reilly books are extremely popular in the industry and I've been very satisfied.

A current version of

Hadoop: The Definitive Guide,
MapReduce Design Patterns, and
Learning Spark

might suit your needs by providing high quality, immediately useful information and avoiding information overload -- all are published by O'reilly.

Spark Streaming is covered in Chapter 13 of "Learning Spark".


Detecting low-quality, user-created text content

There might not be a off-the-shelf package for detecting "spammy" or "low quality" because is it is relative to the context (as you already recognized).
One option is to use rules-based approach. Have a list of spam keywords. If any of them appear then stop the text. This is simple but also a limited approach.
Another option is to use machine learning learning to train a system to detect spam. The first step is collect thousands of human-labeled examples of both spam and not spam. Then apply natural language processing text classifier, naive Bayes classifier is a good baseline.


Thank you for providing a good reproducible code, I can't resist answering the question :)
Hope the following code helps:
data <- read.table(text = "0    1   2   3   4   5
MR  155 211 64  14  1   1
Mob 0   393 51  2   0   0
SC  0   427 12  7   0   0
Act 0   386 45  15  0   0
Pain    0   379 62  5   0   0
Anx 0   355 73  18  0   0", header = TRUE)

#data$row <- seq_len(nrow(data))
data$row <- row.names(data)
data2 <- melt(data, id.vars ="row")
data2$variable <- sub("X",as.character(data2$variable),replacement="",fixed=TRUE)

ggplot(data2, aes(x = variable, y = value, fill = row)) +
  geom_bar(stat = "identity") +
  xlab("HealthState") +
  ylab("Count") +
  theme_bw()


Reduce the size e.g. using cv2.resize()
Compress the image (it is not lossless) e.g. cv2.imencode()
Lower the frame rate
Use lower precision - images are uint8 when loaded, but the deep learning frameworks use float32 by default. You could try float16 or mixed precision.

Using JPEG compression has been shown to be fairly good in terms of the reduction in memory and minimal loss of performance. Have a look a this research.

You could also drop the frame rate, so say 10 FPS. The actually values could be computed based on the expected velocity of the moving objects -> do you really require 24 FPS for the task?

Otherwise, the hardware you are using will determine which steps to take afterwards. Memory, number of operations, inference speed etc. will change how you optimise the process.

You mentioned "dataframe", so I will just point out that using Pandas Dataframes to hold raw image data, whilst looking easy, it generally very inefficient due to the number of data-points involved (pixels), and the fact that Pandas DataFrames are essentially annotated NumPy arrays - the annotations take a lot of space. Better to load into pure numpy arrays and use OpenCV for things suchs as making gray-scale (black and white) images from RGB, resizing them, normalising pixel values, and so on.


How to deal with variable number of permutation invariant features?

Technically your problem is not about a variable number of features, since you can have a finite list of all the possible features. The standard case is just to use all these features, even if only a few of them are "active" for a particular instance (your first option). If the number of features is too high, then you need dimensionality reduction.
The advanced option is to use a feature extraction method: an unsupervised method which "groups" similar features together, the goal being to reduce dimensionality while preserving the information contained in the features. By definition this method modifies the set of features: the "new features" are not directly interpretable, as opposed to the original ones.
Note that the other way to reduce dimensionality is feature selection: these methods don't modify the features, but they discard the least informative ones. Feature selection is supervised (as opposed to feature extraction) because informativeness is measured with respect to the response variable.


Is my dataset unlearnable, or is my LSTM model not smart enough?

An LSTM uses the preceding sequence of bitrates to produce a label. If the label can be predicted from those bitrates, then your problem is learnable with an LSTM.
From your comment: The label is the "stage of the video": Running, walking, etc. The question is if this can be derived from the bitrate? Walking with a busy background might yield a higher bitrate than running. Judging your example by eye, I suspect it cannot. You need to get more features from the video than just the bitrate, I think.


From most frequent words how to extract technical skill words

From what I understand, you need more than 1-word terms. Thus, it's better to go for n-grams.

Start with creating n-grams

import re
from nltk.util import ngrams

s = s.lower()
s = re.sub(r'[^a-zA-Z0-9\s]', ' ', s)
tokens = [token for token in s.split(" ") if token != ""]
output = list(ngrams(tokens, 2))

You should get 1-gram, 2-grams and 3-grams at least to cover all possible terms.

Then you can use a Computer Science Ontology (CSO) which includes about 14k technical terms.

An alternative would be to use their own Classifier that gets a text as input and annotate terms on it from the same ontology. You can find a demo here https://cso.kmi.open.ac.uk/classify/

When I try to classify the abstract of Machine Learning from the Wikipedia article, I get the following results

  Machine learning (ML) is the scientific study of algorithms and
  statistical models that computer systems use to effectively perform a
  specific task without using explicit instructions, relying on patterns
  and inference instead. It is seen as a subset of artificial
  intelligence. Machine learning algorithms build a mathematical model
  based on sample data, known as "training data", in order to make
  predictions or decisions without being explicitly programmed to
  perform the task.1:2 Machine learning algorithms are used in a
  wide variety of applications, such as email filtering, and computer
  vision, where it is infeasible to develop an algorithm of specific
  instructions for performing the task. Machine learning is closely
  related to computational statistics, which focuses on making
  predictions using computers. The study of mathematical optimization
  delivers methods, theory and application domains to the field of
  machine learning. Data mining is a field of study within machine
  learning, and focuses on exploratory data analysis through
  unsupervised learning.[3][4] In its application across business
  problems, machine learning is also referred to as predictive
  analytics.

artificial intelligence
computer systems
computer vision
correlation
analysis
data mining
email
inference
machine learning
optimization
unsupervised learning


I think your process is not really a cluster analysis problem, but instead a time series analysis problem. You have some process that is measuring a value ($Y$ variable) at different points in time ($X$ variable). I would suggest using a Shewhart Control Chart or something similar to understand the process that you have. You should also do analysis on the distribution to ensure it is normal, or use the CLT to enable the data to move towards normality.


how to disable query from beeline results


Making bigram features from a particular dataset

Bigram is better to be used with sentences. In your case, files contain a list of words, as I could understand. Therefore using bigrams in your project might not yield expecting results. However, if you are still willing to do that, this is how you calculate bigrams:

Take the list of words and count the frequencies of adjacent words.
Ex:

(madvise, write) - 1

(write, write) -  3

(write, read) -  1

(read, read) -  1

(read, madvise) -  1

.

.

.

.

(sendto, epoll_pwait) -  1


What is the state of the art in the field of NLP?

You are probably aware that deep learning is all the rage these days, and it has touched NLP too. There is a tutorial on it from a recent conference: Deep Learning for Natural Language Processing (without Magic) by Richard Socher and Christopher Manning, who are from Stanford.


How to handle continuous values and a binary target?

I am expecting this question is for a supervised learning problem where you have a mixture of continuous and categorical features as independent features and your dependent or target feature is a binary class feature. If that is so please follow the below advice.

There might be a much better solutions but this worked for me. I had more than 200 features and a categorical feature like pin code.

Target Feature as 1/0

I am assuming this is a supervised learning problem and the best way to go about will be by starting with a basic logisitic regression model.
If you are not impressed by the performance then you can even try some advanced classification algorithms like Naive Bayes, KNN, SVM etc.

Categorical Feature

You can use pandas one hot encoding for this

I kept a threshold, and used one hot encoding only on those unique categories which occurred more than this threshold
The ones which were less than the threshold can be dropped, but I used a special value to encode them just in case to not to loose them.
You can follow here to know how to perform one-hot encoding

I hope I answered at least to a certain extent. Again, I used this solution for my issue and it worked pretty well and hope it works for you too.


tensorflow: is there a way to specify XLA_GPU with tensorflow?

Check that the device is there first by examining the device names in the output from the following:

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

Once you've verified that 'XLA_GPU:0' is a device on your system use something like

with tf.device('/device:XLA_GPU:0'):

Obviously you can change the names.


The predict function will work on the new data.  It has some options for how to handle entries that don't appear in the original data's labels.

https://rdrr.io/cran/caret/man/dummyVars.html


Using KNN to categorise inventory (physical stock items) - is it the best way?

So your question is on the effectiveness of KNN to categories items based on features you have listed above.
As you might already know, KNN is a unsupervised clustering algorithm which creates K clusters with a minimal intra-cluster variation. This is method can be particularly use for when you know what the number of groups K you need. Also, it is particularly handy if you do not have any labels for categories for all examples.
At the same time, this method isn’t deterministic, which means that groupings do vary after each execution.
From this information, you might get a better idea for yourself as to whether KNN would be useful for this task.


How to group by one column and count frequency from other column for each item in the previous column in python?

This simple Code worked:

Count_sequence = df.groupby(['ID','Sequence']).count()

For obtaining the output in an excel sheet:

Count_sequence.to_excel('sequence_count.xlsx)


How to change a Pandas dataframe into feature vector?

If you have your dataframe loaded as the variable df, you can simply use this

X = df[['A','B','C']]
y = df['Z']

where A, B and C are your independent variables and Z is your dependent variable.


Error calculation in Logistic Regression

The problem here is that you are comparing a regression problem with a classification problem. Classifying MNIST digits is treated as a classification task because it is assumed that predicting the wrong digit is always bad, regardless of how "close" you are to the right answer. One could even argue that predicting a 9 instead of a 3 is a better guess than predicting 5 for instance.

If you want really want to compare the values, I would simply pick the class with the highest value and use this as the regression prediction.


what machine/deep learning/ nlp techniques are used to classify a given words as name, mobile number, address, email, state, county, city etc

You could apply character grams - Intuitively, there might be a huge difference in character set between a phone number and an email address. and then pass the character gram vector to SVM to make a prediction. You could implement this using in sklearn using the below feature extractors.

TfIdfVectorizer(analyzer='character')
CountVectorizer(analyzer='character')

Cross validate on the ngram range and slack variables of SVM to fine tune your model.


Use test data as train: does it make sense?

This idea will most likely increase the bias in the model. Let's assume that the model has non-zero bias in the model. In this case, when it assumes its predictions to be true, without confirmation from an Oracle as in active learning, the bias of the model increases. In common terms, if the model has some amount of bias in its predictions, and it uses its predictions to learn on, the bias in the model can only increase. This issue does not arise when there is 0 bias in the model to begin with, however, in that case, there is no need to learn any further!

Note that this is a highly intuitive answer but I cannot think of an argument against the intuition :-) I will appreciate any feedback on this.


How to gauge the Complexity of Pre trained Neural Networks?

It can mean both, depending on the context. In order to improve prediction, a Network might need either more parameters or more depth, but these features improve models in different ways. For example, it's true that a Network with too few parameters won't be able to learn much; there is a minimal amount of parameters required simply to transform and represent signals in a sufficiently sofisticated way. On the other side, depth is fundamental in order to make your model generate more complex abstractions that will make it superior to other ML algorithms.

In other words: the number of parameters overall tells you how many things your network can learn. Its depth tells you how complex and sofisticated these things can be.

Deep Neural Network complexity is a multifaceted thing, it can't be represented on a single dimension.


I think the analysis which you have done was good.

Regarding the Survival Analysis procedure, I think using it in your scenario is good enough. Even it might take time but the results from that are good and very insightful.

Since you have applied survival analysis on the data, you need to make sure that these assumptions are met:

There are several different ways to estimate a survival function or
a survival curve. There are a number of popular parametric methods
that are used to model survival data, and they differ in terms of
the assumptions that are made about the distribution of survival
times in the population. Some popular distributions include the
exponential, Weibull, Gompertz and log-normal distributions.
Perhaps the most popular is the exponential distribution, which
    assumes that a participant's likelihood of suffering the event of
    interest is independent of how long that person has been event-free.
    Other distributions make different assumptions about the probability
    of an individual developing an event (i.e., it may increase,
    decrease or change over time). More details on parametric methods
    for survival analysis can be found in Hosmer and Lemeshow and Lee
    and Wang1.
Here on two nonparametric methods, which make no assumptions about
how the probability that a person develops the event changes over
time. Using nonparametric methods, we estimate and plot the survival
distribution or the survival curve. Survival curves are often
plotted as step functions, as shown in the figure below. Time is
shown on the X-axis and survival (proportion of people at risk) is
shown on the Y-axis. Note that the percentage of participants
surviving does not always represent the percentage who are alive
(which assumes that the outcome of interest is death). "Survival"
can also refer to the proportion who are free of another outcome
event (e.g., percentage free of MI or cardiovascular disease), or it
can also represent the percentage who do not experience a healthy
outcome (e.g., cancer remission).

You can go through this link for better understanding.

Regarding Poisson Distribution, Did you plot and check whether the data is following Poisson Distribution like:

The Poisson distribution is an appropriate model if the following assumptions are true.

k is the number of times an event occurs in an interval and k can
take values 0, 1, 2, ….
The occurrence of one event does not affect the probability that a
second event will occur. That is, events occur independently.
The rate at which events occur is constant. The rate cannot be higher
in some intervals and lower in other intervals.
Two events cannot occur at exactly the same instant; instead, at each
very small sub-interval exactly one event either occurs or does not
occur.
The probability of an event in a small sub-interval is proportional
to the length of the sub-interval.

Or

The actual probability distribution is given by a binomial
distribution and the number of trials is sufficiently bigger than the
number of successes one is asking about

If these conditions are met then you can use Poisson Model, go through this link

Implementation of this in R, Python.

Finally, to address your 2 questions:

Your approach is Correct there is no problem with using that method, to improve your results you need to work on feature engg(deriving new variables).Since it you are considering the duration as a continuous variable(did you perform that log transformation, which you have stated in the beginning?)
In your scenario I think Survival and Poisson gives you better result, if you think these take more time then try getting sample of data and get your work done. If you are considering the out-come as a continuous variable then you can use Random Forest,XGBoost , all methods which are used for predicting a continuous variable(but if were you I would spend more time in fitting Survival and Poisson and then shift to other prediction techniques)

Let me know if you have any issues!


The sum of multi-class prediction is not 1 using tensorflow and keras?

To get the summation in the last layer to be one, you need to use Softmax activation not Sigmoid. Often Sigmoid is used in a special case when there is a binary classification problem.


You can take a look at here. As you can read from there:

  Download and unpack hiddenDomains

  If you haven't already done this, download the latest version of hiddenDomains from the Sourceforge website

  Now unpack it

shell$ tar -xzvf hiddenDomains.VERSION.NUMBER.tar.gz

  Where VERSION and NUMBER represent the release that you downloaded.

  Install R and required R packages (if necessary)
  Download and install R if you don't already have it.

  If you don't already have them, you will need to install two hidden Markov model libraries:

  depmixS4
  HiddenMarkov
  You can do this by starting R on the command line:

shell$ R

  Or, if you prefer RStudio, you can use that.

  Regardless of how you started R, type the following commands to install the packages.

> install.packages("depmixS4")
> install.packages("HiddenMarkov")

Here and here may also be helpful for knowing how to use it.


should I shift a dataset to use it for Time series regression with RNN/LSTM?

Yes, you are making prediction, which means using historical features(such as at time t) to predict the target in the future(say t+1). In many cases, you could use past few timestamps' features(say t-n,t-n+1,...t) to predict. Preprocess your data in the way (X_historical,y_future) in case of data leakage.


If there are no missing values in our training set, should we accommodate missing values in an unseen test set?

First, we must understand about a common statistical term called population. Given a population say X, a random sample is drawn (in the ideal conditions). Now suppose you are asked to build a predictive model based on this random sample. So, you split the sample into train, test and validation sets. And you start to build the model on the train set. You begin with the initial data cleaning activities, and you find there is no missing data in it.
With this brief background, now to answer your Q literally forces me to rather ask you a question;
Q. Did you collect the data or was it given to you?

If your response to the former part of my Q is yes then by all means do whatever you want with the data. And if your response to the latter part of my Q is yes then you should not make any attempt to pollute it. Nor should you make any attempt to peek into the holdout dataset, because then subconsciously the predictive model you have built will be sabotaged.
Finally, remember the concept of population and sample. It holds the key. Build your model such that it accounts for all initial data preprocessing activities. If a particular step does not fulfill the dataset, then code can be written to avoid it
Edit 1
Basis of the OP suggesting the dataset was given to them, I'm revising the answer further;
i think your getting confused between the population data and new data. As per my answer, models are built basis of the population data. The new data should have the same attributes and properties as the population data. However, if for some reason unknown to you, the new data has missing values but the original data does not, then there are a couple of options, namely;
a. Determine the missing data pattern,
i. if its missing completely at random (MCAR), means there is no relationship between the missingness of the data and any values, observed or missing data. In other words, no systematic differences exist between participants with missing data and those with complete data. In these instances, the missing data reduce the analyzable population of the study and consequently, the statistical power, but do not introduce bias: when data are MCAR, the data which remain can be considered a simple random sample of the full data set of interest.
ii. Missing at random (MAR). When data are MAR, the fact that the data are missing is systematically related to the observed but not the unobserved data.
iii. Missing not at random (MNAR). When data are MNAR, the fact that the data are missing is systematically related to the unobserved data, that is, the missingness is related to events or factors which are not measured by the researcher.
Once you have determined the nature of missingness, then you should determine if the missing data can be imputed or not.
In conclusion, if the new data has missing values then you can treat them or else remove them. The choice is yours. My suggestion will be to follow the middle path, in which you can build 2 models; first model without the missing data and second model with the imputed missing data. Evaluate and validate both the model performance and choose the one which closely matches the desired business/research outcome.


Why don't different output weights break symmetry?

It is fine if a hidden node has identical initial weights with nodes in a different layer, which is what I assume you mean by output weights. The problem with weight-symmetry arises when nodes within the same layer that are connected to the same inputs with the same activation function are initialized identically.

To see this, the output of a node $i$ within a hidden layer is given by
$$\alpha_i = \sigma(W_i^{T}x + b) $$
where $\sigma$ is the activation function, $W$ is the weight matrix, $x$ is input, $b$ is bias.

If the weights $W_{i}=W_{j}$ are identical for nodes $i,j$ (note that bias is typically initialized to 0), then $\alpha_i = \alpha_j$ and the backpropagation pass will update both nodes identically.


Orange, K-means clustering, memory error

Only 32-bit Orange is currently available for Windows (the filename says win32, if you look). So your per-process RAM is limited to 4 GB. The exception says you ran out of RAM.

Use 64-bit Anaconda installer to get 64-bit Python and libraries on Windows, and then install Orange 3 there.


By downloading the Free Wolfram Engine for Developers you may use Wolfram Language.  If you are using Python then use the Wolfram Client Library for Python to access the engine in Python.

You may use FindTextualAnswer.

FindTextualAnswer["Person Jane Doe found guilty in case, Judge John Dude to give final verdict on it tomorrow.",
 "Who was found guilty?",
 TargetDevice -> "GPU"]

"Jane Doe"

FindTextualAnswer["Person Jane Doe found guilty in case, Judge John Dude to give final verdict on it tomorrow.",
 "Who was the judge?",
 TargetDevice -> "GPU"]

"John Dude"

Hope this helps.


Problem to display decision tree: InvocationException: GraphViz's executables not found in Python scikit-learn?

You need to add the graphviz/bin folder to PATH. See the tutorial here.


Time series forecast: when should I use the additive or the multiplicative method?

You say you have managed to make your data stationary, so I would probably say an additive model is your best starting point. You could simply plot your stationary data and check that the variance doesn't increase with the nominal values. High variance will mean higher errors for a linear regression.

When we have a basic regression model, like the following:

$$
y = \beta_1x_1 + \beta_2x_2 + \epsilon
$$

the residual error $\epsilon$ is hypothesized to be constant (assuming the model itself is accurate). $\epsilon$ should not get larger when there are larger values for the covariates $x_1$ $x_2$. In other words, you expect homoscedasticity: that the error term is the same across all values of the model covariates. This is what you will easily spot on the plot of your processed (stationary) data.

If you made you time series stationary by taking the logarithms (a.k.a differencing), then an additive model of the log-ed variables would almost correspond to a multiplicative model.

Just to be clear, if you still seem to have heteroscedasticity with $\epsilon$ varying greatly, this might imply that your model itself is ill-formed e.g. that an important factor is missing.


Software for automated database processing

Do you consider SQL to be programming? Because at the very least you're going to need to do some SQL manipulations to solve this. There's no visual tool that I know of that will do this for you (especially for OSX!)

I don't know why you have a barrier for a new language; if you were willing to do this in python it could be solved relatively quickly.


Did you use your machine GPU?
You can use batch processing, and train you're data chunk by chunk, it will take some time to go through all of your 10GB, but it will eventually gives you the result without paying extra.
You can also create a free account on GCP and they will give a 300$ worth of credits and try to execute your models...
The same with Amazon Web Serives, 100USD promotional credits for students, 150USD for educators, 30USD for other occupations AWS
Microsoft Azure give 200USD for free too Azure


Transposed convolution as umpsampling in DCGAN

This checkerboard effect arises due to taking sum of the overlapping regions during the transpose-convolution operation. Post convolution, in the output, the overlapping pixels have a higher magnitude than the surrounding pixels.
Try using a filter size of 4x4 along with a stride 2 transpose convolution. It may help to alleviate this problem.

For more information, watch this lecture from 30th minute.


PyTorch: How to use pytorch pretrained for single channel image

I came across a code where the user had this very innovative method to tackle this problem. Here is the small trick to convert any pre-trained network to accept 1 channel images without loosing pertained weights.

arch = models.resnet50(num_classes=1000, pretrained=True)
arch = list(arch.children())
w = arch[0].weight
arch[0] = nn.Conv2d(1, 64, kernel_size=7, stride=2, padding=2, bias=False)
arch[0].weight = nn.Parameter(torch.mean(w, dim=1, keepdim=True))
arch = nn.Sequential(*arch)

Basically here, weights of the first Conv2d is taken and stored in w. Afterwards, we are creating new Conv2d which has 1 channel and replacing its parameter with w for which we take mean.
I am pretty sure this can be achieved in keras or tenserflow too.

Let me know if you happen to try it.


How to interpret predicted data from a keras model

you have 99 leaf species and 594 test records. Also the output is (594,). Here each value represents corresponding leaf species columns index.
 check the species data you would have received after One-HotEncoder/get_dummies.
each value of "computed_predictions" corresponds to their respective column number.
you can export species column_name to a list(of 99 labels) and get the labels using list index(i.e. computed_predictions respective value)


Training the network with some batch size - code

That part of the code will select the samples that belong to a specific batch. The for loop first loops over the data in train_X in steps of BATCH_SIZE, which means that the variable i holds the first index for each batch in the training dataset. The rest of the samples for the batch are then the ones after that index up to the sample which completes the batch. This is done using train_X[i:i+BATCH_SIZE].


to include first single word in bigram or not?

What you describe is called padding and is indeed used frequently in language modeling. For instance if one represents the sequence "A B C" with trigrams:

# # A
# A B
A B C
B C #
C # #

The advantages of padding:

it makes every word/symbol appear the same number of times whether it appears in the middle of the sequence or not.
it marks the beginning and end of a sentence/text, so that the model can represent the probability to start/end with a particular word.


If you are using TensorFlow to write your architecture,

You can create 3 training datasets( one for one class) using tf.data and then you can use tf.data.experimental.sample_from_datasets with the same weightage to generate the batch data. Check weights parameter in the documentation.

You can initialize well in the final layer. Please check this blog from Andrej Karpathy.

You can add the class_weight parameter while training.


feature extraction for a pretrained model in keras

The features variable contains the outputs of the final convolutional layers of your network. The final convolutional layer of VGG16 outputs 512 7x7 feature maps. All you need to do in order to use these features in a logistic regression model (or any other model) is reshape it to a 2D tensor, as you say.

reshaped_features = features.reshape(100, 512*7*7)

This will flatten out the feature maps to a long one-dimensional vector for each instance.

Tip: If you can't be bothered working out the actual dimensions for your reshape, you can replace 512*7*7 with -1 and numpy will figure out how big the final dimension should be.


how does splitting occur at a node in a decision-tree with non-categorical data?

No, I don't think values according to which the branches are seperated are chosen at random. Instead, weighted average is calculated for each category and the category with the highest weighted average is chosen as the root node. This is also referred as Information gain
Consider this dataset

.

Consider the above picture, Here the outlook is chosen as Root node, And how is outlook chosen as root node?

First, We calculate the total entropy of the data. Lets say its 0.95. Now inorder the pick the right root node, We will find weighted averages of all the subcategories. There are 4 four categories here, So we will obtain 4 weighted entropy averages. Lets say they are 0.3, 0.2, 0.4, 0.8. Now we will subtract the induvidual weighted entropy averages from the total entropy. So we will get (0.95-0.3), (0.95-0.2), (0.95-0.4), (0.95-0.8). Among all the three which ever category has the highest value that category will be chosen as the root node. These 4 values are the information gain of each of the categories i.e Whichever category has the highest information gain, we will pick it as the root node. In our case, its the outlook category/feature .Hope it helps

Check this for more clarity


(Labeled, if possible) time-series datasets for anomaly detection

Kaggle's NAB: a variety of sources such as AWS server metrics, Twitter volume, advertisement clicking metrics, traffic data, and more. Data is labeled.
Kaggle's Wafer: manufacturing data, 2K datapoints, 143 labeled anomalies. Measures are taken every 10 milliseconds.


Difference between Convolution and Pooling?

We use filters mostly to get different features(characteristics) about the object(e.g. image). And pooling we're using to reduce the size and at the same time to save the most significant information of each feature map.


Loss function returns nan on time series dataset using tensorflow

This is because the the input values are not normalised to a standard scale. X consists of values ranging from 0 to 9999. This would make the training unstable. If the idea is to train the net to predict the sequence that you described, an easy fix is to feed it smaller values in the training data. For instance, feed it the input,

output = split_sequence(range(10),n_steps)

Along with a batch size of say, 5. It will learn to generalize to higher numbers as well.

With the changes made and the following for loop, the output is as expected.

for epoch in range(n_epochs):
    for X_batch, y_batch in generate_batch(input, output, batch_size):
        # print(X_batch,y_batch)
        mse_val, _ = session.run([mse, training_op], feed_dict={
                                 X: X_batch, y: y_batch})

    if epoch % 100 == 0:
        print('epoch', epoch, 'MSE=', mse_val)
        error_list.append(mse_val)

X_test = np.array([[45, 46, 47], [57, 58, 59], [1000, 1001, 1002]])
y_test = session.run(y_predictions, feed_dict={X:X_test})

print(y_test) # Should be 48, 60, 1003

plt.plot(error_list)
plt.show()

Final y_test is

[[  47.997036]
 [  59.996166]
 [1002.9279  ]]

If not this change, another change that you can make is to use the Adam Optimiser instead of SGD. It will make the learning more stable and it works even with bigger values.


Very low probability in naive Bayes classifier

I can't tell you for sure without you describing your calculation more or showing code, but my guess is you're not actually calculating the posterior probability here. I bet this is just the conditional likelihood, or at best the unnormalized posterior. Remember: the posterior calculation has a division component. Does yours? You're probably forgetting to divide by the "evidence".


In general, a network with CNN with no Fully connected layers is termed as Fully Convolutional Network(FCN). It can include any type of pooling layers, batch norm, dropouts etc.


Your initial intuition seems pretty good to me. A pretrained image classifier like VGG19 or ResNet, as included in the Keras library will yield simple vectors if the include_top parameter is set to False upon initialization. You can then use a method like PCA to reduce the dimensionality to 255, or whatever number your algorithm can handle. Averaging the vectors before or after this step will allow you to merge the photos. You will need to test which works best for your application.


What are the state-of-the-art models for identifying objects in photos?

EDIT : Deep Face Recognition: A Survey New on arxiv 4/18/2018 looks like best survey of methods over face related tasks :).

Beyond Facenet, there are a few approaches which may be good to look at how many faces do you intend to have your system know about - aka netowrks that have a network to directly output which face it is (~ <10K), vs a feature map for clustering (~ 10k to 100K), or comparing any 2 faces (~ >100K) - below are examples of approaches to each...

This paper just came out:
Exploring Disentangled Feature Representation Beyond Face Identification- 2018 - Reported Accuracy 99.816 . Use an encoder-decoder like scheme to compute features of a face. Then given all the faces you computed this on, do clustering to find which ones are the same face (TSNE - distance in feature space). This paper is cool since it also gives features of each face like 'smiling', and these are used to augment the search. Along similar line is this

Before that (other than Facenet) - DeepFace - Accuracy 97.35. Its the facebook lib. If its state-of-the-art enough for them, its state of the art enough for me. Approach is given two images, put them into siamese network, for first detect, then 3d model the face, then project to 2d featuremap, which then combine to label saying whether they are same person or not.

Robust Face Recognition via Multimodal Deep
Face Representation - 2016, Reported accuracy 98.43. This is interesting because they trained on a relatively small dataset (CASIA WebFace). However this has the last layer being the number of identities in the dataset - so this could be a llimiting factor if you want to recognize millions of identities like facebook does. Otherwise, this looks easiest to implement/mess with.

Patch-based Face Recognition using a Hierarchical
Multi-label Matcher - not sure what is going on here, but looks interesting.

I would think another limiting factor for you is how many examples do you have per face - eg do you have 4K identities and 4mil images like the facebok dataset, or 10k identities and .5mil images (CASIA WebFace), or LFW with like ~5K identities and ~15k images.


What is the advantage of using Dunn index over other metrics for evaluating clustering algorithm?

They will often give the same preferences.

Do not forget that these are largely heuristics. They won't have much advantages over one another. That is why there are so many.

As a guideline, look at the definitions. Choose that index, whose equation is most relevant for your problem. (Yes, you do need to understand what they do. Clustering is hard, it is easy to get meaningless results by just looking at the code and scores and forgetting the underlying math.)


Marginal contribution of a text document

From an NLP perspective, the main issue is to identify and extract the terms/relations of interest from the text.
It may be easy if the sentences always appear like these simple examples: one can use pattern matching "the <entity> is <property1> [and <property2>]" (no need for ML).
However with general text it's a quite complex problem which would probably require training an ad-hoc model from annotated data. This would generally involve the tasks of Named Entity Recognition and Relation Extraction.


Find 10 most similar data points from 100?

That is often called nearest-neighbor search.
The most common methods require a distance metric. Given the features of battery pack, how close to each other are they?


Transfer value of one column to another column into a new column based on condition

This can be solved using a number of methods. One of the method is:

df['new_col']=df['Bezeichnung'][df['Artikelgruppe']==0]

This would result in a new column with the values of column Bezeichnung where values of column Artikelgruppe are 0 and the other values will be NaN. The NaN values could be easily replaced at any time of point.

+-------------+---------------+---------+
| Bezeichnung | Artikelgruppe | new_col |
+-------------+---------------+---------+
|     A       |       1       |    NaN  |
|     B       |       2       |    NaN  |
|     C       |       0       |     C   |
|     D       |       4       |    Nan  |
+-------------+---------------+---------+


Why Logistic regression into Spark Mllib does not use Maximum likelihood estimation?

I think you're confused. Maximum likelihood is a general technique for giving the most likely parameter estimation. There is no closed solution for maximum likelihood for logistic regression, so both R and Spark must numerically estimate it.

How exactly the likelihood is estimated could be slightly different and might depends on the implementation. For example, Spark prefers to add regularization, R might like to use something else (you'll need to check the documentation).

Summary: Both R and Spark try to estimate ML for you. Please check the R documentation on how R do it.


Match users based on the content of their articles

One way could be to apply word-embeddings for semantic similarity checking. word2vec model generates feature vectors which could capture semantic similarity. For example, the closest vector to car will be honda, ferrari, vehicle, bike. Train a model using large amount of data from wikipedia dumps or the one released by google. It has fine quality vectors. Gensim has a nice implementation of word2vec

For each blog articles, pre-process the data by removing the stop-words and stemming them. From the resulting words, collect the more frequent words. Do this for all the articles and check for the similarity among the frequent words in other articles as well. So that one article with frequent words car, race, tournament, ferrari, F1 will have more closer vectors in article with frequent words bike, honda, racer.

Or other way is to look for similar vectors in tags itself. It is good to play with it for sometime, so that you get to know which features work better for the dataset you have.


Model comparison with CV using standard error

It is possible, however, this is usually not of great concern. If you would like to take into account the standard error, one possibility is the following:

You compute the standard error of the best performing model (using your amelioration metric)
Consider all models that perform within one standard error (or less if you prefer)
Select the model with the simplest decision boundary

This is a heuristic(!) based on Occam's razor that simpler models tend to generalize better. However, keep in mind that for complicated problems simpler models are probably just that: simpler. They don't have to be more accurate.

Alternatively, instead of 3. you can select the model with the smallest standard error, if your main goal is to limit your exposure to this kind of variability.

Also keep in mind that there is No Unbiased Estimator of the Variance of K-Fold Cross-Validation, so this method brings with it its own uncertainty.

In general, I would just keep an eye on the standard error and if it's not too concerning just go with the numerically best-performing model.


Find the best interpolation method for missing observations

The most basic method that springs to mind is split of a test set:
Take the data where you have recorded all variables which you might need to extrapolate in another set, and split of a percentage of that and "mask" or hide the variable you wish to interpolate in this split (maybe using the data from the other part of the split if you're using some sort of trained interpolation).
Compare the results of the different interpolation methods you are using with the actual values (that you've taken out) on a metric that suits your purpose for the data best (e.g. mean squared error, mean absolute error, logistic loss, or maybe even the outcome of some machine learning method trained on the dataset).
That way, you'll find the interpolation method that best suits your data + problem.
One thing to keep in mind is that your masking should follow the same (if any) patterns that your actual missing data has: e.g. if it only happens on certain time periods, your masking method should try to follow that pattern if possible.


How to deal with with rows with zero in every feature while clustering?

It's a matter of data quality so it depends how the dataset was built:

Either these instances are meaningful, i.e. it makes sense that an observation would have zeros for all the features and that it would happen that often.
Or these are the result of an error, typically the complete absence of measurement for these observations.

Naturally one wants to keep the instances in the data in the former case but (usually) not in the later case, because the values don't represent an actual data point so they would introduce a massive bias for the clustering algorithm.


Criteria used to create and select leaf nodes in sklearn

Pre-pruning is handled by a variety of parameters:
max_depth, min_samples_split, min_samples_leaf, min_weight_fraction_leaf, max_leaf_nodes, and min_impurity_decrease.
Post-pruning is relatively new to sklearn, and is accomplished with minimal cost-complexity pruning, parameter ccp_alpha.


This may be too simple for what you had in mind, but perhaps it will help:

Example data

library(tidyverse); library(magrittr) # load R libraries
sample_data = data.frame(Customer = 1:100, A = 0, B = rep(c(10,NA), c(25,75)), C = rep(c(NA,25), c(25,75)))

Bar chart

sample_data %>% gather("Product", "Time", -Customer) %>% ggplot()+geom_bar(aes(x=Time, fill=Product))+geom_label(aes(x=Time, label=Product), y=-Inf, vjust=0)

Point plot

The use of this is that you can map the customers (since the y-axis is not the count but the Customer ID), i.e., you can add lines connecting them but they would be too many, so I haven't (they can be grouped though, for A->B, B->C, A->C, etc)

sample_data %>% gather("Product", "Time", -Customer) %>% ggplot()+geom_point(aes(x=Time, y=Customer, color=Product))+geom_label(aes(x=Time, label=Product), y=-Inf, vjust=0)


Training the document page layout and classifying good/bad layouts

When you're talking about layout, I am assuming you are talking about the way elements are arranged in the page. In that case, dividing your page into grids and having each element represented into grid numbers should solve your problem. Let's assume your page is divided into 9 x 9 grids, then you can have this data frame as an input. Grids can be replaced with your co-ordinates. You can add in more features like font-size, font-style, colour, etc.,

number header1 header2 header3 paragraph1 font-size-h1 font-size-h2 target
1      (2,3)      4     (4,2)     3           12           8           0

The tuple represents the co-ordinates and the individual number represents the grid number. The font-size can be added for each element which will increase  the dimensions of the dataset. May be try running a simpler algorithm like Random Forest first and then move onto deep learning techniques. Sometimes, simpler algorithms work better than complex algorithms.

Aesthetic Value of a Webpage, Layout Classification


Why does ada (adaboost) in R return different training error graphs and variable importance plots when running the same function multiple times?

Boosting, together with bagging, falls into the realm of so cold ensemble models: you randomly draw a sample from the data, fit a model, adjust your predictions, sample once again. Unless your samples are fixed, every time you run the algo you'll get slightly different results.


Regex-style pattern-matching for time series

If you need optional parts in the pattern then regular expressions were specifically built for those kind of problems. You could probably speed up regular expressions by using loops in Cython, but the time spent programming it is not really worth it.

If your pattern is fixed then there are faster ways to do pattern matching. OpenCV uses Descrete Fourier Transformation to match a template. It is very fast and is available for Python and C++. It is optimized to work with 2D images, and can also work with 32 bit floats. How DFT works

Documentation for template matching in OpenCV


Detect sensitive data from unstructured text documents

Welcome to the site! Assuming that I understand your problem correctly, I think you can achieve a working model.

If I was in your position I would:

Obtain the cleanest data possible from the documents. For example, you don't state if the docs are already in simple text or if you need to do something like OCR or whatnot. Having the cleanest set possible will be key for this.
Make sure you have a consistent marker for the sensitive data. You mention four dots - is that the case for ALL instances? If not, clean that data now
You're going to need to do standard NLP cleansing stuff like removing punctuation but you may or may not want to keep stop words (this will be part of your model testing). Also, this is key, be 100% certain that the four dots are viewed as a single work in your tokenization process -  you should be able to verify this prior to committing to your tokenization file.
I would take all my documents and create 3 word ngrams. I would then separate out ngrams that contain sensitive data and not sensitive data. That, essentially, becomes your labeled dataset and you should label them accordingly.
My base model would use all entries that contain sensitive data in the second position of the ngram (the middle of the three words). I would train a neural network on that and see what kind of results I achieve with that. NOTE that your four dots will not be an input, only the word previous and after will be your inputs. You could almost treat this as a binary classification model - the middle word is either sensitive or it's not.
Future iterations of my model would maybe use a multi-classification approach with something like (1) No sensitive data (2) sensitive data in first position (3) sensitive data in second position and (3) sensitive data in third position and so on and so on.
From there, you can play with variations on the size of the ngram since the immediate words may or may not actually have an effect on the predictions. There's no limit to how crazy you can get with this - you won't know until you start modeling.

Finally, your entire project becomes even more interesting when you go to the prediction phase with new data. You will do the same and break down your document into ngrams and create a prediction for each one and output the result. In other words, you will need to break down your document only to turn around and build it up again - that should be a fun script to write! Good luck with this, let us know how it turns out.


predict gives the same output value for every image (Keras)

When all the predictions are giving exact the same value you know that your model is not learning thus something is wrong!

In your case the problem is having the last dense layer with the softmax AND the sigmoid activation.

model.add(keras.layers.Dense(1, activation=tf.nn.softmax))
model.add(keras.layers.Activation('sigmoid'))

This is creating a conflict where the softmax is outputting a 1 (since there is only one node) and the sigmoid takes this 1 and computing its sigmoid value gives:

  1/(1+exp(-1)) = 0.731058

And there is our friend!

To solve this, you just need to remove the last activation layer, and change the softmax for a sigmoid since your output is binary:

model = keras.Sequential()
model.add(keras.layers.Conv2D(16, [3,3], activation='relu', padding='same'))
model.add(keras.layers.Conv2D(32, [3,3], activation='relu', padding='same'))
model.add(keras.layers.Conv2D(64, [3,3], activation='relu', padding='same'))

model.add(keras.layers.BatchNormalization())
model.add(keras.layers.Dropout(0.15))
model.add(keras.layers.Activation('relu'))
model.add(keras.layers.Flatten())
model.add(keras.layers.Dense(50))
model.add(keras.layers.Dense(1, activation=tf.nn.sigmoid))
#model.add(keras.layers.Activation('sigmoid'))

This should work!


How can I perform weighted addition of three layers in keras?

I solved the problem using subclassing in keras. The code is shown below:
class Wt_Add(keras.layers.Layer):
def __init__(self, units=1, input_dim=1):
    super(Wt_Add, self).__init__()
    w_init = tf.random_normal_initializer()
    self.w1 = tf.Variable(
        initial_value=w_init(shape=(input_dim, units), dtype="float32"),
        trainable=True,
    )
    self.w2 = tf.Variable(
        initial_value=w_init(shape=(input_dim, units), dtype="float32"),
        trainable=True,
    )
    self.w3 = tf.Variable(
        initial_value=w_init(shape=(input_dim, units), dtype="float32"),
        trainable=True,
    )

def call(self, input1, input2, input3):
    return tf.multiply(input1,self.w1) + tf.multiply(input2, self.w2) + tf.multiply(input3, self.w3)

Usage:
wt_add = Wt_Add(1,1)
sum_layer = wt_add(input1, input2, input3)


How to select a model based on statistical analyses?

This is a very general question, since you are not providing any statistics, that one can comment on. But in general: yes, this can be the case. However, there is an interesting paper on comparing classification models with statistical tests written by Demšar (2006). He shows a way to vizualize the results of different models that do not significantly differ in quality.


Why my model can't recognise my own hand written digit?

You have to remember that machine learning model do not understand any concepts as we do, humans. It cannot generalize something it hasn't seen. And yours hasn't seen black digits on white background, so it has no way of predicting a digit right.

The only two things you can do is :

Train your model from scratch with both datas : black digits on white background and white digits on black background. These datas have to be balanced (as much as possible). Maybe the model need to be more complex, maybe you need more data, and maybe your accuracy will decrease. You can then predict both type of datas.
Uses a test dataset only with similar datas of the train set, white digits on black background.

You can also do a data augmentation with your previous train dataset :
as the digits are white and background black, you can reverse images color, then you will have black digits on white background. That way, you have your train set doubled in size, without writing any more digits by yourself !


Implementation of BERT using Tensorflow vs PyTorch

There are not only 2, but many implementations of BERT. Most are basically equivalent.

The implementations that you mentioned are:

The original code by Google, in Tensorflow. https://github.com/google-research/bert
Implementation by Huggingface, in Pytorch and Tensorflow, that reproduces the same results as the original implementation and uses the same checkpoints as the original BERT article. https://github.com/huggingface/transformers

These are the differences regarding different aspects:

In terms of results, there is no difference in using one or the other, as they both use the same checkpoints (same weights) and their results have been checked to be equal.
In terms of reusability, HuggingFace library is probably more reusable, as it is designed specifically for that. Also, it gives you the freedom of choosing TensorFlow or Pytorch as deep learning framework.
In terms of performance, they should be the same.
In terms of community support (e.g. asking questions in github or stackoverflow about them), HuggingFace library is better suited, as there are a lot of people using it.

Apart from BERT, the transformers library by HuggingFace has implementations for lots of models: OpenAI GPT-2, RoBERTa, ELECTRA, ...


Replace part column value with value from another column of same dataframe

Your solution is close
Maybe just needed to add an apply.
Try:
df = pd.DataFrame({"Name":["Name1", "Name2", "Name#DATE#"], "Date":[20200126, 20200127, 20200210]})

df["NewColumn"] = df.apply(lambda row: row["Name"].replace("#DATE#", str(row["Date"])), axis = 1)

Outputs:


Yes, there are characteristics. You can use a correlogram to inform you as to the error structure in your data. That will tell you whether or not your data needs to account for AR and/or MA terms. Also check for unit roots to tell you whether you need to difference the time series.

This link has a good introduction to analyzing the correlogram that shows the pattern for AR(1) process. It is charecterized by a declining or oscillating but declining values. Depending on whether or not you have positive or negative autocorrelation.

The ACF for an MA(1) process is below. It is characterized by one significant value and then non-significant oscillating values thereafter.

To tell if you need to do differencing you should use a test like the augmented dickey-fuller test to check for the unit roots (i.e. your data is integrated).


I suggest you try to remove the trend (growing) from your data then try to model it. Then difference with model could be your outlier and alarm

see this:https://anomaly.io/seasonal-trend-decomposition-in-r/


Large action space for deep reinforcement learning

I am wondering why only a single Q value is learned?

It is not a factor here, but it matches the Q-learning theory as written better to model $\hat{q}(s,a,\theta) \approx Q(s,a)$.

It is not numerically superior, and often less efficient than modelling a single network with multiple action outputs. However, it is clearly valid to approximate the action value function directly.

If the policy is separate to Q values, and you are using Q-learning to predict the values of that policy (as opposed to using Q-learning to control and find an optimal policy) then a single action value can be more efficient.

  If this is the case, how do we determine the action for the next step?

If you want to drive a best guess at an optimal policy from action values $Q(s,a)$, then typically you calculate

$$\pi(s) = \text{argmax}_a Q(s,a)$$

This rule is not dependent on a neural network architecture, but the implementation does vary:

If your neural network outputs all action values at once from the state, $f_{nn}(s) \rightarrow [\hat{q}(s,a_0), \hat{q}(s,a_1), \hat{q}(s,a_2)...]$ then you perform a single forward pass of the network and find the maximising action inside a single output vector.
If your neural network outputs a single action value from a state, action $f_{nn}(s,a) \rightarrow \hat{q}(s,a)$ then you must run it for each possible action (typically in a minibatch) and find the maximising action across all outputs.

Unless you have some other way to generate the policies (e.g. you are using a policy network and policy gradients, the Q value is then for a baseline in something like an Actor-Critic agent), then you must collect all action values from each state in order to find the maximising action. There is no easy way around this, and the paper you link does not have a clever solution to it.

  It seems that people think that make action as input is an effective way to ease the large action space problem. [From comments]

It can be, but not in the way you suppose.

Instead, the nature of the action representation is critical. In your question, you said "you can ignore this but each action is a combination of the vector $c_t^1$ to $c_t^3$" (emphasis mine). However, this is not an ignorable detail, and is an important part of the paper.

By compressing the action representation into a small number of scalar traits, the authors allow the neural network to generalise between similar actions. For example if one action is represented by $c_t^1 = 0.5, c_t^2 = -0.3, c_t^3 = 0.25$ and another action is represented by $c_t^1 = 0.7, c_t^2 = -0.3, c_t^3 = 0.25$, then an
accurate value for the first action may result in at least an approximately accurate value for the second action, even if it has never been taken before in the current state.

Caveat: whether or not this is true or useful depends on the specifics of the problem being solved. It will not always be true, or be useful to transform the action space in this way. Actions with similar vectors need to be similar in some way that affects the outcome.

However, assuming it is true, the network design gives you an advantage in learning rate. Things that the agent learns about action values will be generalised more efficiently than a simpler network that enumerates each possible action. That makes the agent more sample efficient, it will need less experience to reach near optimal behaviour. It is this sample efficiency that the paper you linked is referring as an improvement to original DQN.

None of this changes the need to iterate over all possible actions when you want to evaluate the policy using DQN in this case.

TL;DR: The agent in the paper still has to evaluate all actions in each state in order to choose the best one. However, it does not have to try them all in order to discover which is best in the long term.


Is there a way to make the window in df.rolling dynamic depending on which row it is calculating for?

simply use .rolling(365, min_periods=1) no need of for loop
data['52wkLow'] = data['Low']['GME'].rolling(365,min_periods=1).min()