what is the training phase in N-gram model?

I will start with an advice -  just google "n gram language model" and you will find a lot of good detailed explanations.
With that being said I will give a short explanation about the "training phase" of n-gram language models (answer to question 2). The simplest way to build an N-gram language model strats with finding a big corpus - a set of many sentences. the words of the model will be the words that appear at least once in the corpus. The probability of the word xn given a past context of the words x1,x2,...,xn-1 will be the number of occurrences of the sequence x1,x2,...xn-1,xn in the corpus / the number of occurrences of the sequence x1,x2,...,xn-1 in the corpus.
This is the simplest way and it has problems, especially What happens if the sequence x1,x2,...,xn does not appear in the corpus? It will always get propability zero. Therefore there are smoothing techniques to handle this problem (read about it).
And now for question 1 - In the simplest case, without smoothing, the candidates are the words that appear in the corpus. In models with smoothing the candidates may be all of the words in the sense that every word might get a positive probability.


Compare two tends with big difference in absolute value

I think it would be better to use a standard scaler that removes the mean and divides by the standard deviation. See here for more info and an implementation using sklearn.
Why?
At least you should be aware that dividing by the maximum could hide smaller effects. In the case you have an outlier that has a very high value, you would loose the small changes in the corresponding curve. Moreover, you might not compare the same changes between all the curves.
Edit
On the question when to use standard scaler vs minmax scaler, I think a good start is the sklearn preprocessing page that deeply explains both. Then in this post, @Sammy pointed "Python Machine Learning" book by Raschka. The author provides some guidance on page 111 when to normalize (min-max scale) and when to standardize data that I requote here:

Although normalization via min-max scaling is a commonly used technique that is useful when we need values in a bounded interval, standardization can be more practical for many machine learning algorithms. The reason is that many linear models, such as the logistic regression and SVM, [...] initialize the weights to 0 or small random values close to 0. Using standardization, we center the feature columns at mean 0 with standard deviation 1 so that the feature columns take the form of a normal distribution, which makes it easier to learn the weights. Furthermore, standardization maintains useful information about outliers and makes the algorithm less sensitive to them in contrast to min-max scaling, which scales the data to a limited range of values.

Here are some pictures to go with the Why? section above.


Machine Learning model to find items that are frequently bought together using Hadoop Spark

I don't know about learnable evolution models, but Spark ML has a module for collaborative filtering. This can be used to find objects that are similar/often bought together etc. Amazon uses it to show you the "People who bought this also bought these items" feature on their website.


Machine Learning Identification and Classification, based on string contents: General advice

If the content/information is lengthy, I'd suggest you to use some NLP tasks for starters. I would suggest you to use some basic NLP based preprocessing because it makes our model perform better. So, the basic feature extraction can be used for this. Example, using Porter Stemmer, Lemmatizer to clean the data or removing stop words and then using ngrams for features seem to be a basic idea and a good start. There are various vectorizers which can be used to extract features the documents. For example, TfidfVectorizer calculates the frequency of a word in a document and also frequency across documents. This can be more useful than a naive Bag of words approach. Then, on top of this there are various classifiers which can be used like OneVsRestClassifier or others.

A simple approach could be selecting the input and target first. Select the parameters which are to be passed as input and the desired output. Then, decide to clean the input or not based on some NLP APIs(you can use nltk). Then decide on a classifier. You can then predict the values. Test on validation set and
try various classifiers for starters.

As for terminology, I can think of Multiclass Classification only now.


Will the performance of my NER model improve?

More gold data of any sort (especially at this small scale) usually leads to improvement because the model improves after seeing more examples in different contexts, but you especially want to add cases that the model got wrong (after correcting the annotation, of course) to see improvement.


In machine learning, the vanishing gradient problem is a difficulty
  found in training artificial neural networks with gradient-based
  learning methods and backpropagation. In such methods, each of the
  neural network's weights receives an update proportional to the
  partial derivative of the error function with respect to the current
  weight in each iteration of training. The problem is that in some
  cases, the gradient will be vanishingly small, effectively preventing
  the weight from changing its value. In the worst case, this may
  completely stop the neural network from further training.

Source :: https://en.wikipedia.org/wiki/Vanishing_gradient_problem

Thus, gradient is vanishing till it reaches initial layer of neural network and in turn very little change in weights.


R contains some standard functions for data manipulation, which can be used for data cleaning, in its base package (gsub, transform, etc.), as well as in various third-party packages, such as stringr, reshape/reshape2, and plyr/dplyr. Examples and best practices of usage for these packages and their functions are described in the following paper: http://vita.had.co.nz/papers/tidy-data.pdf.

Additionally, R offers some packages specifically focused on data cleaning and transformation:

editrules (http://cran.r-project.org/web/packages/editrules/index.html)
deducorrect (http://cran.r-project.org/web/packages/deducorrect/index.html)
StatMatch (http://cran.r-project.org/web/packages/StatMatch/index.html)
MatchIt (http://cran.r-project.org/web/packages/MatchIt/index.html)
DataCombine (http://cran.r-project.org/web/packages/DataCombine)
data.table (http://cran.r-project.org/web/packages/data.table)

A comprehensive and coherent approach to data cleaning in R, including examples and use of editrules and deducorrect packages, as well as a description of workflow (framework) of data cleaning in R, is presented in the following paper, which I highly recommend: http://cran.r-project.org/doc/contrib/de_Jonge+van_der_Loo-Introduction_to_data_cleaning_with_R.pdf.


Clustering of Weekday Weekend Time Series Data

As you don't do any alignments you can simply concatenate the two vectors.

KMeans will then minimize variance in both weekdays and weekends.


ML Approach for Getting List of Observations with Similar Features (Discrete+Continuous)

With mixed variables, weighting is extremely important.

How you seem to have labeled training data of what should be similar. Hence, you should implement some metric learning approach yourself, where the objective is to learn a similarity metric.

I don't think there is a library that you can just use, but you are better off understanding how this works and writing the code yourself.


Anomaly Detection for Large Time Series Data

Following J.Tukey, you should plot, draw graphs, visualize, etc... until you have a solid pack of examples.

Then make Tukey' fences on each of the 30 parameters. Let $q_1$ and $q_3$ be the 1st and 3rd quartiles, $d=q_3-q_1$ the inter-quartile distance, and define as outlier any observation outside the interval $q_1-k\cdot d < x < q_3+k\cdot d$, where $k$ is a constant. Traditionally, $k=1.5$ indicates an outlier and $k=3$ indicates the data is far out. However, the real value of $k$ should be tested against your examples.

Then make a cluster analysis (with a k-nearest neighbor) and define as outlier any point isolated in one cluster. Again, use your example to test various values of $k$.


Can i find similar players using a clustering method like the k-mean algorithm?

For finding similar objects, k-means does not make much sense.

k-means is based on similar objects. If squared deviations don't work for your data then k-means will not work either.

Thus, instead of using k-means, just use a nearest neighbor search without k-means.


First two principal components explain 100% variance of data set with 300 features

So the question is asking why the first two principal components of your encoded text data is encapsulating all of the variation in the data.
One potential issue could be the averaging over word vectors.
Suppose for a particular feature across word vectors for a particular post f, there could be an array of positive and negative values. When we then apply an average over f we could zero out the dimension and thus cause greater data sparsity, which could explain for what you are seeing (this zero value will exist regardless of whether you multiply this average with the td-idf or not). It could be the case that this sort of thing is happening across multiple dimensions in your text embeddings / feature vectors.
With this, you might need to think of another way of deriving a text embedding, maybe used Doc2Vec instead, which follows the same principles as Word2Vec, but instead derives document embeddings, which encapsulates the meaning of a section of text instead of word embeddings, which encapsulates the meaning of an individual word within a section of text.


Training Doc2Vec and Word2Vec at the same time

You need to be careful with the assumptions you make about the doc2vec implementation. Here are some useful concepts:

Word2vec has two different model implementations (Skip-gram and Continuous-bag-of-words) and Doc2vec has analogous PV-DM and CBOW models:

Word2vec

Continuous-bag-of-words (CBOW)
Skip-gram

Doc2vec (Paragraph Vector)

Distributed Memory (PV-DM)
Distributed Bag-of-words (PV-DBOW)

In skip-gram the inputs are pairs of words generated by a moving window of size n trough the data where we use one word to predict the other, whereas in CBOW the task is predicting a center word from the surrounding words. In the second case the context word vectors are typically averaged.

The Doc2vec extension works analogously. The DBOW model is analog to skip-gram and what it does is calculating the probability of words in a paragraph given a randomly selected word from that paragraph. The DM however, tries to predict the central word based on a context of words and the context paragraph.

As you can see, not necessarily the doc2vec models need to calculate word embeddings first.  In fact, in the gensim doc2vec function there is an parameter for the dbow model that says:

  "dbow_words (int {1,0}) – If set to 1 trains word-vectors (in
  skip-gram fashion) simultaneous with DBOW doc-vector training; If 0,
  only trains doc-vectors (faster)."

Meaning that during the training phase not even the dbow requires producing the word vectors.

There is a great notebook from rare-technologies that gives a lot of insights about how these models are trained.

Regarding your specific questions, you can train a word2vec and doc2vec model and use the results to compare words and paragraphs (look at this paper). But take into account that doc2vec is not training words and then doing some fancy stuff with them. The training process involves calculating paragraphs directly.


CNN: How do I handle Blurred images in the dataset?

I will suggest using data augmentation approaches to even out your data distributions. It will make your blurred images more usable to the model
The data distribution of 30% of your images deviates from the rest because they are blurred. Experiment with training using random blur with appropriate min-max ranges in the data augmentation pipeline (on the images that aren't blurred). This will help the model to smoothly generalize across blurred images. If you don't have labels of which images are blurred, use blur detection algorithms to determine a threshold after which you want to augment.
After doing this, it may be important that you do test-time data augmentation as well.


Correct way to set Spark variables in jupyter notebook

When you run Spark in the shell the SparkConf object is already created for you. As stated in the documentation once a SparkConf object is passed to Spark, it  can no longer be modified by the user. So stopping it and creating a new one is actually the right way to do it.

However, this should now be possible for Spark 2.0 and higher.


How can I deal with data that is on the format "Image + single number"?

After the convolutional part you will need to add a normal, dense layer. Concatenate it to this layer and add some more layers if necessary, to add more interactions between the temperature and the image. This wouldn't necessarily need to be too deep because it can learn to represent the image features in a way that it will combine nicely with the temperature already, hopefully.


In this case you are running a RandomizedSearchCV which is running 100 iterations.
If you consider the fact that for every run of your 30K rows worth of data with youe 300 features (which is a fair amount), you would be looking at an average run time of ~ 1.2 minutes per run.

You could however speed this if you were running thia via GPUs instead of CPUs as you could do more rapid calculations.

So to answer your question the issue is not with your machine or your Jupyter Notebook.
Rather it is with how many iterations you have had with your RF Randomized Search Algorithm. If you reduce the iterations, you will also see a reduction in the run time.


Replacing dataloader samples in training pytorch

Process per sample
Usually, you would process data at the sample level by creating your own class inheriting torch.utils.data.Dataset and do the processing inside __getitem__ method.
from torch.utils.data import Dataset
class MyDataset(Dataset):
  def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)

  def __getitem__(self, i):
    # Call the __getitem__ from Dataset class
    sample = super().__getitem__(i)
    # ...Do some processing on the sample here
    return sample

train_data = MyDataset()
train_dataloader = DataLoader(train_data, sampler=train_sampler, batch_size=batch_size)

Process per batch
You can use the collate_fn parameter of torch.utils.data.DataLoader to specify a custom function which processes your batch.
from torch.utils.data import Dataset, DataLoader

def collate_fn(samples):
  # samples is a list of samples you get from the __getitem__ function of your torch.utils.data.Dataset instance
  # You can write here whatever processing you need before stacking samples into one batch of data
  batch = torch.stack(samples, dim=0)
  return batch

train_data = Dataset()
train_dataloader = DataLoader(train_data, sampler=train_sampler, batch_size=batch_size, collate_fn=collate_fn)


Are the sentences exactly the same, word to word? If that is the case I would suggest removing the repeated sentences because that might create a bias for the word2vec model, ie. repeating the same sentence would overweigh those examples single would end with higher frequency of these words in the model. But it might be the case that this works in your favor for find synonyms. Subsample all the unique sentences, not just the most frequent ones to have a balanced model.

I would also suggest looking at the FastText model which is built on top of the word2vec model, builds n grams at a character level. It is easy to train using gensim and has some prebuilt functions like model.most_similar(positive=[word],topn=number of matching words) to find the nearest neighbors based on the word embeddings, you can also use model.similarity(word1, word2) to easily get a similarity score between 0 and 1. These functions might be helpful to find synonyms.


You are getting loss near to 0 but, Your true distribution of y in the range of 0-1 so, that 0.04 loss may be high loss.
Just get random model and check the loss. You will get to know how much you decreased the loss. I will suggest to use r^2metric for evaluation.


fast processing: changing the column value in a geospatial environment

This is to get whether the incident_zip is in the list of zip code.

df.isin({'incident_zip' : zip_code_list)

If you have a zip code borough mapping in the form of dict. You can do

df['borough'].map(zip_to_borough)

For pandas dataframe never iterate say by rows unless as last resort because the performance will be terrible.

You can speed these operation multiprocessing if you want.


Looks simply wrong to me. The second 'matrix' should be transposed.


Supervised learning on sources of information with different importance

Its better to do supervised classification then unsupervised clustering since you have the right labels for the response.

Now in supervised classification approach 1 is better than approach 2 because in approach 2 you will the reducing the already available information by combining features.

Approach 3 is advised where you will create more features from the given 3 features by use of NLP processing, sentiments, tags, chunking, time taken, text length etc and then selecting the features those provide more information gain using feature selection approaches.


How do I predict a class for each time step using the information from previous timsteps

Regarding neural networks, and supposing your output is based on three prior timesteps, two possibilities could be:

An approach with a CNN model with a (3,10,1) input and your desired output.
LSTM where you use three cells the 10 features as an input for each timestep and output the classes you need at the end (don't know if this one will work properly though,maybe it is too small, depending on your problem).
As in you question 1. you propose you could use a DNN with the input of one of your previous timesteps, but I don't think this will be the best approach neither.

If you provide more details (like an example of your dataset) we can help you with more specific answers.


Deep Q network disregards input, giving identical output no matter the input state

The value function you want to learn should be relatively simple, but I would expect optimal action values to be quite similar between moving left or right, at least when that is away from a wall. Recall that action values measure the expected reward for taking the selected action, then following the policy from that point on.

So in state [0 0 8 5 0 0], the action value under an optimal policy for "move right" should be +1, but the action value for "move left" is not much different, at 0.9801 . . . because under an optimal policy the agent will move right twice afterwards when following the policy.

That means the neural network will have to learn fine detail differences between estimates. You have made this harder than it needs to be if you are using the representation as "raw" input to the neural network. Neural networks learn badly when the input number range is high. In addition your learning rates seem quite high.

My suggestions:

Scale the inputs. You should have code that turns the state representation into neural network features. I'd suggest the neural network will function nicely with +1 for goal and -1 for agent, if you must work with this state representation.
Try lower learning rates. A rate of $0.01$ is high for the Adam optimiser.
Reduce discount factor $\gamma$ - that will make a clearer difference in this short episode-length environment between returns for faster and slower routes.


Found input variables with inconsistent numbers of samples: [11232, 5616]

It seems like the train and train_w2v dataframes have s variable number of rows. You will  have to make their shapes consistent before doing a train-test-split


R Programming, how to replicate for districts in a city

The latitude and longitude are stored in a text file that is read into a table, Dat.  It has the form:

lat long climate-group

For your particular case, you would calculate Dat[, 3].


How to implement Brown Clustering Algorithm in O(|V|k^2)

I have managed to resolve this. There is an excellent and thorough explanation of the optimization steps in the following thesis: Semi-Supervised Learning for Natural Language by Percy Liang.

My mistake was trying to update the quality for all potential clusters pairs. Instead, you should initialize a table with the quality changes of doing each merge. Use this table to find the best merge, and the update the relevant terms that make up the table entries.


how to evaluate top n recommendation system with movie lens dataset?

For various metrics feel free to look at various benchmarking libraries including MyMediaLite and LibRec. If you are doing a TOP N approach, then the way to evaluate this using a Movielens system is simple convert the ratings into binary likes and dislikes based on some threshold. Essentially you would take the "likes" of a user. Find the user is the testing set. Find the number of items that the user likes and see if the recommendation guesses the missing data correctly.

The key to thinking about these datasets is that the fact that they chose to rate a movie at all means the user actually went out an saw the movie. The fact that they saw the movie indicates an implicit approval of the basic premise. As such, a good recommender should be able to predict which items that user rates in the future.

The easiest way to evaluate the recommendation system though is just to plug into an evaluation framework such as LibRec, MyMediaLite, or various other ones and compare the returned metrics to your algorithm. These libraries typically have code that will generate the testing, training, and evaluation subsets for you and all you have to do is hook up your code as a module.

As a bonus, feel free to add your recommendation algorithm as a pull request to the library so other researchers can try it too and you'll have an excellent open source implementation of your algorithm that future researchers can reference in their own work.


Reinforcement learning: Discounting rewards in the REINFORCE algorithm

What does G, 'return from step t' mean here?

Return from step t to step T-1, i.e. R_t + R_(t+1) + ... + R_(T-1)?
Return from step 0 to step t?, i.e. R_0 + R_1 + ... + R_(t)?

Neither, but (1) is closest.
$$G_t = \sum_{i=t+1}^T R_i$$
i.e. the sum of all rewards from step $t+1$ to step $T$.
You are possibly confused because the loop for REINFORCE goes from $0$ to $T-1$. However, that makes sense due to the one step offset from return to the sum of rewards. So $G_{T-1} = R_T$ and $G_{T} = 0$ always (there is no future reward possible at the end of the episode).


Hyperparameter Optimization for a Machine Learning Algorithm

You are right, what has to be changed is the objective. You are currently using accuracy as a measure of how good your classifier is. Accuracy is not a good measure when you have class imbalance. For this reason, other objectives have to be used. AUC is a better measure, and so is the log-loss, although not that interpretable. However, both AUC and log-loss need you method to output probabilities, not just predictions of classes. For this reason, it is required that your SVM implementation has a predict probability method.


Why is the numeric column treated as a categorical column in Microsoft Learning?

Have a look at the comment in that notebook:
# Define preprocessing for categorical features (encode the Age column)

It seems that the data you have is different (maybe only in order) to what is used in the notebook as the Age column is the eigth column (index seven) in the notebook. See also the cell where data is selected from the input file:
# Separate features and labels
features = ['Pregnancies','PlasmaGlucose','DiastolicBloodPressure','TricepsThickness','SerumInsulin','BMI','DiabetesPedigree','Age']
label = 'Diabetic'
X, y = diabetes[features].values, diabetes[label].values


Can't reproduce results from GridSearchCV?

The score from your GridsearchCV is biased.  You can use cross-validation either for estimating accuracy, or for choosing hyperparameters; but not both.  If you use cross-validation to pick the best choice of hyperparameters, by measuring the accuracy of each possible option, the accuracy you got for the option you chose will tend to overestimate the accuracy you'll see on the test set.

To avoid this bias, select a separate hold-out validation set for estimating the accuracy of your selected parameters, or use nested cross-validation (or a scikit-learn Pipeline).

See https://datascience.stackexchange.com/a/17835/8560.


Spatial clustering based on response to inputs and building a reduced model

I'm not sure I'm following your question completely, but for spatial type clustering maybe a Self-Organizing Map would meet your needs. Basically it maps out the space based on nearby activations.

Side answer: I haven't used python


Issue translating large amounts of tweets using Google Translate

So this was my work around:

Convert the list of strings that need to be translated into an indexed tuple with the first value being the index and the second value being the string:

s = [(0, 'NEW'), (1, 'YOUTUBE'), (2, 'VIDEO'), (3, 'OUT'), (4, 'NOW:TOTTENHAM'), (5, 'NEWS'), (6, 'TRANSFER'), (7, 'WINDOW'), (8, 'UPDATE'), (9, '손흥민'), (10, 'Son'), (11, 'Award'), (12, 'Link'), (13, 'to'), (14, 'Premier'), (15, 'League'), (16, 'Defen...'), (17, 'TOTTENHAM'), (18, 'NEWS'), (19, 'TRANSFER'), (20, 'WINDOW'), (21, 'UPDATE'), (22, 'Carabao'), (23, 'Cup'), (24, 'Win'), (25, 'Final.'), (26, '손흥민'), (27, 'Son'), (28, 'Contract')]

Next as the words that were causing issues when translating were ASCII I extracted them using this code:

(index, item) for (index, item) in s if not item.isascii()]
# result
[(9, '손흥민'), (26, '손흥민')]

Then I ran the translations on these words instead of the entire string or the chunks of strings.
After translating I then added them back in the list of tuples
Convert the list of tuples to a list of strings and concatenate them into a single string

This significantly reduced the time to translate the data.


Normalization vs standardization for image classification problem

To be able to answer your question, firstly we should take into account the differences between Normalization and Standardization.
Normalization: normalized_value=(raw_value-min)/(max-min)
Standardization: standarized_value=(raw_value-μ)/σ
Also, one additional famous method is there which is centering. Where you subtract the mean from the pixels.
In general, all of these serve one common and crucial purpose: to provide "fair conditions" for all features. I.o.w. since, for each feature, we have many shared parameters (e.g. learning rate) instead of custom parameters, we need to have similar ranges. Therefore, sharing of parameters would not be optimal because a parameter (e.g. learning rate) would not have the same power over features with different ranges. For example, converging to the global optimum value might be effective for one of the features, however, another one might require a smaller learning rate value because of its range.
Additionally, smaller values increase the calculation process, fastens the converging. Also, interpretation and comparison of weights would be easier if the features are standard. If ranges are dissimilar one of the coefficients might be very big while another one might be comparably very small.
However, I want to draw attention to your Normalization technique where you divide pixel values by 255, which just lowers the range from 0-255 to 0-1, but the spread of pixel values over the range is kept the same. Normalization is mostly used when we want to have an abounding range for features, however, RGB has already an abounding system of 0-255. However, theoretically, this would still help to fasten the training process.
It is hard to say that one of these (Normalization or Standardization) is better than the other because one might beat the other depending on the scenario. Commonly, both techniques are tried and compared to see which one performs better.
In many cases, to have a more accurate model, usage of these techniques is a must. Let's say you have two images where one of the images is dark where all pixels have values close to each other (narrow range, small deviations, high kurtosis), but another one is a complex image where parts of the image dissimilar to each other in terms of pixel values (wide range, large deviations, low kurtosis). In such a case, using normalization would help a model to better understand and capture the relations inside of the images.


How to improve an existing machine learning classifier in python?

The simplest, and likely best, way is to just rebuild the model every time you add more data.

If you want to build on existing models, one way is to average multiple random forest models.  So you build a model on 20k, test it, then decide to build on it by building another random forest model on a separate set of 20k and averaging the model parameter results with the previous model.  This is basically a poorly described ensemble method.  Check out this: http://scikit-learn.org/stable/modules/ensemble.html.


How to handle columns with large/infinte values in dataset for ML classification

Depends a bit on the model you are going to run. I will explain a bit for Linear Models and for Decision trees ensembling (gradient boosting and random forest)

Decision tree

Not much to do, when the tree is built each branch will choose a split. If there is any information gain with a large value, it will choose it and make a split.

Some implementations, as catboost have a quantization in it. The split could be done eventually in something like 95% quantile and that will work with large values.

Generalized Linear Models

You will need to change this. My suggestion is creating a feature based in the values of the column (if df.col1> 9999: 1 else 0).
And then Winsorizing by a certain threshold.


Should you cluster before performing collaborative filtering?

Short Answer: No, you should not perform clustering before doing matrix factorisation.
First, I just want to say SVD is a special case of Matrix Factorisation. Another thing, SVD in recommendations is not traditional SVD, but has a different form.
Detailed Answer for why (in general) you should not perform clustering before doing matrix factorisation
Matrix Factorisation (MF) itself performs clustering. When you perform Matrix Factorisation, you end up with latent vectors for user and items. By running a clustering algorithm, such as K-Means, on these latent vectors, you end up doing clustering. But, if your end goal is just to recommend, then, there is no point performing clustering apriori.
In some corner cases, you may consider performing clustering

Do you want to cluster to understand the data better and build different recommendation models for every different cluster? If yes, then you may consider doing clustering before hand.


I also found an interesting paper (with code) where they merged local and global descriptors.

Scene Recognition by Combining Local and Global Image Descriptors

According to the paper: They take the daisy features (local features), cluster the features into k clusters, then create a histogram with k bins. They normalize the histogram, once they do this they concatenate this vector (the histogram) with the normalized HOG vector (global features). So in the end we just cluster the local features and create histogram, then just concat with global vector and there we have a training sample.

Also there may be an alternate method where you just use local features to cluster: https://www.quora.com/How-do-I-merge-features-from-different-feature-extractors-i-e-color-histogram-and-SIFT-for-bag-of-visual-words#


What you say seems reasonable.

You can also try to create the document embeddings as you mention and use k-Nearest Neighbors to find the nearest job descriptions to a given resume based on some distance, without any clustering of job descriptions. There are some approximate implementations of k-Nearest Neighbors that work very fast like https://github.com/nmslib/nmslib.


amount of data required for a good ann mdel

You seem to use a loss function for classification problems, binary crossentropy, for a regression problem.

Try to change your compile function to something like

model.compile(optimizer='adam', loss='mse', metrics=['mae'])

Also, you can change your fit function to

model.fit(X_train, y_train, epochs=500, validation_data=(X_test, y_test), verbose=2)

to track your accuracy during training. This might help you detect overfitting and change the amount of epochs accordingly.

Don't worry about your amount of data, try understanding the difference between classification and regression problems instead.


How is learning rate calculated in sklearn Lasso regression?

With sklearn you can have two approaches for linear regression:

1) LinearRegression object uses Ordinary Least Squares (OLS) solver from scipy, as Learning rate (LR) is one of two classifiers which have closed form solution. This is achieve by just inverting and multiplicating some matrices.

2) SGDRegressor which is an implementation of stochastic gradient descent, very generic one where you can choose your penalty terms. To obtain linear regression you choose loss to be L2 and penalty also to none (linear regression) or L2 (Ridge regression)

There is no "typical gradient descent" because it is rarely used in practise. If you can decompose your loss function into additive terms, then stochastic approach is known to behave better (thus SGD) and if you can spare enough memory - OLS method is faster and easier (thus first solution).

This answer is mostly extracted from https://stackoverflow.com/questions/34469237/linear-regression-and-gradient-descent-in-scikit-learn-pandas/34470001#34470001
The OP @Netro is and the answer is from @lejlot


p_value = 2 * stats.norm.cdf(lift, loc = 0, scale = scale_val )

This is the key for your question: The p-value is the probability that the null hypothesis is true.

If the null hypothesis is true: Your model does not find any differences between groups.
If false: Your model finds differences between groups.

Given that you are using a model which its subyacent assumption is normallity (amongst others), the hypothesis test is to be tried comparing the probability in the context of a normal distribution.

The function stats.norm.cdf returns the probability of "lift being close to zero" if lift is supposed to be "normal". If lift is zero, then there is no difference between groups, so a p-value of <0.01 tell us that the probability that the groups are equal is almost 0, meaning that your groups are different.

The 2 is due to a concept called "two-tailed distribution": The difference between groups can be A greater than B or B greater that A, that's why you measure the difference in either two of the ways.

The addition between standard deviations obeys the concept of:
$Var(X+Y) = Var(X) + Var(Y)$ if $X$ and $Y$ are independent.


Overfitted model produces similar AUC on test set, so which model do I go with?

If you don't provide any int for random_int for train_test_split it doesn't mean there isn't going to be anything. It defaults to None, check the documentation of train_test_split it says,

  If None, the random number generator is the RandomState instance used by np.random.

Now let's look at RandomState instance from the documentation of np.random. Take a look at these points:

  defaults to None. If size is None, then a single value is generated and returned.

and

  If seed is None, then RandomState will try to read data from /dev/urandom (or the Windows analogue) if available or seed from the clock otherwise.

what these mean is, you can achieve the results, the very same several times. But no guarantee it will work for others. There is nothing called random, everything uses pseudo-random. Somehow a "random_state" is generated.

My best guess would be to try: train:valid:test::80:10:10, or 60:20:20 after doing all this GridSearchCV compare your validation accuracy then try the best estimator on the test set. But this assumes you need to have more data.

Hope this helps. If anyone finds any mistakes, I'd be happy to get corrected.


The cross entropy is equivalent (up to a constant) to the Kullback Leibler Divergence  which has an interpretation based on information theory: (very crudely) it is the amount of information "lost" by representing the true labels via the distribution of their predicted values (measured in "nats" (e) or "bits" (2) depending on the base of the logarithm). I don't find it very useful as a "colloquial" interpretation or to think in units of bits.

Typically, you would calculate more interpretable metrics like accuracy and inspect them along with the loss to get a picture of the performance.

However, you can use the loss and compare it to a simple baseline (e.g. the model only predicting the average of your labels or only the majority class) and thus get a relative performance estimate.


Understanding AC_errorRate loss function

From my understanding, this loss type means:

you define a threshold percentage error (let’s say 2%)
for each true value y, the desired prediction should be between y + 0.02*y and y - 0.02*y
the percentage of predicted values fulfilling the rule above contribute to the “inliers” predictions, I.e., good predictions

This idea reminds me to what RANSAC does


Can I use a GAN to increase my Dataset used for Image detection?

In short: no

If you don't have enough images now then you almost certainly dont have enough to successfully train a GAN (it takes more than you think). If you can't train a GAN to reproduce good images, then you don't have images that are going to give you high accuracy for your YOLO effort. The most likely scenario is that you would end up with an algorithm that is really, really good at detecting GAN images that looking nothing like your side scan sonar validation data :)


The most informative curve for imbalance datasets

Precision-recall curves are argued to be more useful than ROC curves in "The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets" by Saito and Rehmsmeier. They argue that ROC might lead to the wrong visual interpretation of specificity.
F1-score equally balances precision and recall. In some domains it might be more useful to more heavily weight precision (F < 1) or recall (F > 1).


They are all bad. A good Silhouette would be 0.7

Try other clustering algorithms instead.


Equation for likelihood in logistic regression

By the definition of the logistic regression model $\mathrm P(y = 1 | x,w) = \sigma\left(\left<w, x\right>\right)$ thus $\mathrm P(y = 0 | x,w) = 1- \sigma\left(\left<w, x\right>\right)$

You should be able to verify (by setting y=0/y=1) that this is equivalent to

$\mathrm P(y | x,w) = \sigma\left(\left<w, x\right>\right)^y \left[ 1- \sigma \left( \left<w, x \right> \right) \right]^{1-y}$

I think you understand the rest?


Why does gradient descent gives me much better Relative Squared Error then the Least Squares approach?

The reason is that the two metrics, mean absolute percentage error (MAPE) and mean square error (MSE) are optimising to different targets. Improving one can be done at the expense of the other.

As a simple example, consider this data:

x = [ 0,  1,  2,  3,  4,  5]
y = [ 3,  5, 10, 10, 11, 15]

The best fit mean squared error (MSE) for a line on this data is $\hat{y} = 2.23x + 3.43$, which has MSE of $1.18$, and a mean absolute percentage error (MAPE) of $11.0$%.

The best fit mean absolute percentage loss for a line on this data is $\hat{y} = 2.35x + 2.99$, which has a MSE of $1.24$, and a MAPE of $8.34$%.

You can see that optimising for MAPE gives a worse MSE, and vice-versa.

The difference can get extreme when there is a large range for y values (in terms of orders of magnitude covered), because optimising for MAPE will favour being more accurate on small values at the expense of larger ones. So if we change y to be:

y = [ 1,  2, 10, 10, 11, 20]

Then optimising mean abs percentage gives the line $\hat{y} = 3.78x + 1.05$ with MSE $7.09$ and MAPE $21.9$%. But optimising for mean square error gives $\hat{y} = 3.49x + 0.286$ with MSE  $4.56$ and MAPE $62.9$% - this is a larger difference, and I suspect that your data has a large range of target variable causing a similar effect.

You can potentially get closer results using the Least Squares regressor by using a transformed target variable $z = log(y)$ and transforming back at the end. This still won't be quite the same, but it does reduce the difference significantly - in my last example if I try this, I get MAPE $24.2$% - compared to $21.9$% for optimising MAPE directly.


Is it possible to train a neural network to solve polynomial equations?

You're trying to fit a very complicated function.  There is no reason to expect that neural networks will be very good at this.  Neural networks aren't magic pixie dust.  They can do some things well, but don't expect a silver bullet.

You're trying to get the neural network to learn to compute some complicated function.  We do know that given sufficiently nodes and sufficiently many layers, you can get an arbitrarily good approximation to this function, but there's no a priori reason to expect it should be possible with the particular (small) number of nodes and layers you chose.  In fact, two layers suffices, if you have sufficiently many nodes -- but we have no way to compute how many nodes are needed.

In particular, the function you are trying to compute amounts to computing $x_0,x_1,x_2$ from $a,b,c,d$, where

$$\begin{align*}
x_k &= - {1 \over 3a} \left(b + \eta^k C + {\Delta_0 \over \eta^k C}\right)\\
\Delta_0 &= b^2 - 3ac\\
C &= \sqrt[3]{\Delta_1 \pm \sqrt{\Delta_1^2 - 4\Delta_0^3} \over 2}\\
\Delta_1 &= 2b^3 - 9abc + 27a^2d\\
\eta &= -{1 \over 2} + {1 \over 2} \sqrt{3} i
\end{align*}$$

(This comes from the general formula for solving a cubic equation.)

That's an extremely messy function, and thus it might be challenging to approximate using a neural network of the architecture you present.  You can always try increasing the number of nodes and/or number of layers, but there's no a priori theory to tell you what the right number is.


Shallow Neural Net for predicting numbers other then 1 or 0?

Well, the main problem is that the existing code and the desired codes solve different problems.

The existing code solves a classification problem, when you predict one of certain classes. And you want to solve a regression problem, so that neural net will predict an arbitrary number.

Sigmoid function is necessary when you predict classes, you need to remove it for regression. Or in other words you need not Logistic Regression, but Linear Regression.
Here is a great article with explanations on this: http://peterroelants.github.io/posts/neural_network_implementation_part01/

I have written an example of implementation: https://gist.github.com/Erlemar/6a5cfcca423ef3b5f6e890c6bef6d5ed


This is a good question - one that is of interest (or should be of interest) to those working in applied social sciences and operations or basically in any situation where the objective function is on panel data. There is a paper by Bai, Zhong and Gao on this topic: https://arxiv.org/abs/1708.00185


No. A confusion matrix is by definition a tabulation of real classes and predicted classes per subject. I've seen relative counts but they are not standard.

According to Wikipedia:

  Each row of the matrix represents the instances in a predicted class while each column represents the instances in an actual class (or vice versa).

The matrices listed above don't do that, so they are not confusion matrices. I'm not familiar with this format, and I don't think it is an academic standard. I'm not really sure how to interpet them, in that sense they are confusing matrices.

PS: You can obtain precision and recall from a confusion matrix.


How does two convolution layers make computation quadratic increase in GoogLeNet?

For any CNN layer $n$ with $F_n$ filters and kernel size $K_n^{height},K_n^{width}$ the number of parameters to train is
$$F_{n-1} \cdot F_n \cdot K_n^{height} \cdot K_n^{width} + F_n$$

where the first summand stands for the weights and the second for the bias parameters (if $n$ is the first CNN layer then $F_{n-1}$ equals the number of input channels). And for the special case of

$F_{n-1} = F_n$ (i.e. same number of filters for layer $n$ and layer $n-1$)
and $K_n^{height} = K_n^{width}$ (i.e. square shaped Kernel)

the number of parameters for layer $n$ is $F_n^2 \cdot K_n^2 + F_n$. Accordingly, you have a non-linear dependency of trainable parameters with regards to the number of filters.


Okay, I finally found the problem. It was that I was backpropagating the gradients on every layers. Including the input and output layers. And it seems that Mxnet expect strictly to have the same NDarray size than the one he computed (no bigger for instance). Otherwise, the array seems not to be copied at all (not even partially)and thus gives wrong results.

But to do that, I had to make sure the gradients size where equals, which is the case for every layers but the entry and output gradients. I incorrectly assumed that, if I increased the batch size of the input/output, all the layers of the network would have an increased batch size. However, the batch size of the input doesn't matter inside the network. So, what I thought I was doing by summing over the values for every batch size was clearly not doing what I thought - meaning averaging the gradients for every image. What I actually did with that was to level off every 3D kernels.

Thus, the simple solution in my case was just to sum the gradients for every layers but the first and last one.


How to determine irrelevant data in binary classification?

I agree that you could reasonably classify the stock that it relates to, and whether it concerns a trading intent or not, separately. Presumably, trading intent looks similar across stocks, so the two are not related much.

Your second and third ideas therefore sound relevant to me.

It's possible to consider a multi-task classifier too with deep learning architectures, one that tries to solve both at once. There might be small advantages to that, but it is more complex.


Visualizing a large number of variables in python

You can load these variables to pandas dataframe and use dataframe.describe() for summary statistics.


Is it vital to use weighted metrics with weighted loss functions?

Calculation of loss and the calculation of metrics on the test set are two different entities. Usually, the weighted loss function is used to weight one of the class (you can use higher weights to the important class in balance or unbalanced class distribution).
For metrics like F1, its always safer to use multiple measures in unbalance class distribution. It would be good to keep a check on macro as well as weighted-F1.
For example: a confusion matrix of the following order:
predicted labels:     0   1
true label 0:      | 70 | 0 |
true label 1:      | 30 | 0 |

Has macro-F1: 0.41 and weighted-F1: 0.58
Further, Aconfusion matrix of the following order:
predicted labels:     0   1
true label 0:      | 99 | 0 |
true label 1:      | 1  | 0 |

Has macro-F1: 0.50 and weighted-F1: 0.99
Both these cases are unbalance where 70 and 90 samples belong to class 0 in 1st and 2nd case respectively. However, when the dataset is too unbalanced, and model predictions are biased towards majority class, then weighted F1 becomes higher.


Recurrent neural networks (RNNs) can work with series as input or output or both.

Even a simple one-layer RNN is effectively "deep" because it has to solve similar problems as multi-layer non-recursive networks. That is because backpropagation logic in a RNN has to account for delay between input and target, which is solved by backpropagation through time - essentially adding a layer to the network for every time step of delay between first input and last output.

RNN architecture has become more sophisticated in recent years by using "gating" techniques such as Gated Recurrent Units (GRU) or Long Short Term Memory (LSTM). These have multiple trainable params - 3 or 4 - per neuron, and the schematics are more complicated than feed-forward networks. They have been demonstrated as very effective in practice, so this extra complexity does seem to pay off.

Although you can research and implement RNNs yourself in a library like Theano or Tensor Flow, several neural network libraries already implement RNN architectures (e.g. Keras, torch-rnn)


What is the meaning of each element in input_shape of Conv1D in Keras?

X[train].shape[0] - This is the number of instances. Let's say it is M
X[train].shape[1] - This is the shape of each  instance. Each instance is (1 x N)
Since input instances are of 1-D, the  input data become m x N. Had it been 2-D, it would have been m x Nx x Ny

And one more question, I know that CNN required fixed input size. But I split my data into train and validation data as k parameter = 5, mean that my data will become: Train = (84,95) and Validation = (21,95). So with the same model how can we train and validate data with difference size

Size means the size of each instance which is same in this case i.e (1,95). Just the number of instances are different i.e. 21 in Test and 84 in Train.
TimeSeries data -
 In TS learning, our initial data is just a time-based sequence of individual datapoint. We then make it Feature and Target by using a certain points (e.g. M) as Feature and  (M+1)th as Target. M is identified based on TS characteristics.
e.g.
1,2,3,4,5 will be (If I use 2 Feature)
1,2(X) --> 3(Y)
2,3(X) --> 4(Y)
3,4(X) --> 5(Y) etc.
These are 3 train records.
May read this too - Machinelearningmastery


Metric (other than RMSE, MSE, etc.) to select the best model to better detect peaks in weather forecasting

I had this problem in my work before and used weighted RMSE and assigned higher weights to the peaks.

Some ideas I took from here https://stats.stackexchange.com/questions/230517/weighted-root-mean-square-error


Word2vec works in two models CBOW and skip-gram. Let's take CBOW model, as your question goes in the same way that predict the target word, given the surrounding words.

Fundamentally, the model develops input and output weight matrices, which depends upon the input context words and output target word with the help of a hidden layer. Thus back-propagation is used to update the weights when the error difference between predicted output vector and the current output matrix.

Basically speaking, predicting the target word from given context words is used as an equation to obtain the optimal weight matrix for the given data.

To answer the second part, it seems a bit complex than just a linear sum.

Obtain all the word vectors of context words
Average them to find out the hidden layer vector h of size Nx1
Obtain the output matrix syn1(word2vec.c or gensim) which is of size VxN
Multiply syn1 by h, the resulting vector will be z with size Vx1
Compute the probability vector y = softmax(z) with size Vx1, where the highest probability denotes the one-hot representation of the target word in vocabulary.
V denotes size of vocabulary and N denotes size of embedding vector.

Source : http://cs224d.stanford.edu/lecture_notes/LectureNotes1.pdf

Update: Long short term memory models are currently doing a great work in predicting the next words. seq2seq models are explained in tensorflow tutorial. There is also a blog post about text generation.


ValueError from statsmodels ExponentialSmoothing

The error is raised from lead - lag; in initial_values, these are set as y[m:2m] and y[:m] respectively,  where m is the seasonality length (52 in your case). So lead is only getting 22 values, and hence the size mismatch complaint.
So yes, for this to work directly, you'd need at least 104 datapoints.  See the source, and docpage.
(N.B.  This is for version 0.10.  Some changes have been made in v0.12, in which the initialization takes more options.  But OP's context is version-specific, so I'll leave it at that.)
But, you can bypass this bit of the code by passing your own initial_slope to fit*.  I might suggest mimicking statsmodels's approach, but limiting the year-over-year slopes to the range you have available: (y[52:74] - y[:22]).mean() / 52
* this is one change in v0.12; these parameters are passed on model instantiation, not fit.  See the docs if you want to do this in a newer version.


So you want to do a Diebold-Mariano test eh? How about the Diebold-Mariano test dm.test function in the forecast package of R?

dm.test {forecast}

Diebold-Mariano test for predictive accuracy
Package:
forecast
Version:
6.2
Description

The Diebold-Mariano test compares the forecast accuracy of two forecast methods.
Usage

dm.test(e1, e2, alternative=c("two.sided","less","greater"),
    h=1, power=2)

(Took me ten seconds to find)


Non-Compact Domain/Range Machine Learning

Notice that the limitation of finite domains and ranges stems from the finite nature of hardware and thus finite representation of numbers. Therefore, a more promising approach is remodeling the domain, rather than using an "infinite" algorithm.

You can apply logarithmic scaling to your domain and range. This will get you off from the open bounds while still preserving order and continuity, which is important fur numerical ML algorithms.

The log function is the basic building block that you can use for your transformation. You can scale it to fit your ranges and this would solve your positive part of the range. You can do the same for the negative, even using  different coefficients if this suits you.


How to interpret Shapley value plot for a model?

1. 2. not always there are some blue points also.

3. 4. 5. yes

6. it depends on the shap plot you are using, on some them default is to surpress less important features and not even plot them.

7. They are discriminatory but not as much, you can reconcile them with some other feature selection technique and decide if you want to keep them.

8. Range of the SHAP values are only bounded by the output magnitude range of the model you are explaining. The SHAP values will sum up to the current output, but when there are canceling effects between features some SHAP values may have a larger magnitude than the model output for a specific instance. If you are explaining a model that outputs a probability then the range of the values will be -1 to 1, because the range of the model output is 0 to 1. If you are explaining a model that outputs a real number or log odds the SHAP values could be larger since the model outputs can be larger.


Segmentation model to predict face forward and profile parts of the face

There is a library called facemesh for Python. It can detect face landmark points in Python. Connecting facemesh points to crop image to a desired polygon is trivial.


XGB uses the two kinds of regularization in both classification and regression; each leaf is a continuous score, these scores added together for the final prediction (of log-odds in the classification case), so penalizing the weights makes sense in either setting.
See also L1 & L2 Regularization in Light GBM

But yes, some hyperparameters (scale_pos_weight) seem to be vestigial:
What does xgb's scale_pos_weight parameter do for regression?
https://discuss.xgboost.ai/t/scale-pos-weight-for-regression/218/10


How to draw convolutional neural network diagrams?

As to your first example most full featured drawing software should be capable of manually drawing almost anything including that diagram.
For example, the webpage "The Neural Network Zoo" has a cheat sheet containing many neural network architectures. It might provide some examples. The author's webpage says:

Djeb - Sep 15, 2016
Amazing. What software did you used to plot these figures ? Cheers !
Fjodor van Veen - Sep 15, 2016
I drew them in Adobe Animate, they’re not plots. Yes it was a lot of work to draw the lines.
Garrett Smith - Sep 15, 2016
Are your excellent images available for reuse under a particular license? Do you have an attribution policy?
Fjodor van Veen - Sep 16, 2016
As long as you mention the author and link to the Asimov Institute, use them however and wherever you like!

As for general automated plotting a commonly used package for Python is Matplotlib, more specific to AI, programs like TensorFlow use a dataflow graph to represent your computation in terms of the dependencies between individual operations.
TensorFlow computation graphs are powerful but complicated. The TensorBoard graph visualization can help you understand and debug them. Here's an example of the visualization.

A combination of automated output and manually annotating some of the details can produce sophisticated images not available from any one program.
This search turns up 1000's of diagrams from which you can obtain ideas to model your own images.


K-fold crossvalidation: how do MSE average and variance vary with K?

Average of the OOS MSEs should generally decrease as k increases. This is right but the difference is much less then on your chart. Suppose we have a dataset where the error will halve if we increase the data 10 times (approximately true for the paper Scaling to Very Very Large Corpora for Natural Language Disambiguation). Then the difference between 5-fold and 20-fold validation will be about 5% (1/(2^log10(0.95/0.8)) not halving like on your graph. And the difference between 20-fold and infinity-fold will be only about 1.5% (1/(2^log10(1/0.95))

For the chart you could use the formula: Average OOS MSE = 1/(2^log10(1-1/k))*MSE_inf. This will assume that you have MSE = MSE_inf at infinity.

Variance of the OOS MSEs should generally increase as k increases. MSE is an average and according to the Central Limit Theorem (if squared errors (SE) are independent and identically distributed which, in my opinion, is supposed for most of the machine learning algorithms) variance should equal to Var(SE)/N, where N is the number of data points used to calculate MSE. So for 5-fold you will have variance Var(SE)/(Npop/5) Where Npop is the total number of points that you have. For the average MSE between all k-folds the variance will be the same and equal to Var(SE)/Npop. So the answer is that the variance of individual MSE numbers of each k-fold increases with k, but the variance of the final average MSE does not depend on the number of folds.

To calculate the variance of the final MSE based on MSE of folds:

Var(MSE_final) = Mean(Var(MSE_folds))/k = Sum((MSE_folds - Mean(MSE_folds))^2)/k^2

MSE change based on number of folds

Here MSE at infinity is assumed 0.05.

Variance of individual k-fold MSEs change based on number of folds

Here Var(squared error for one point) is assumed 10 and number of observations is 1000.


How do I integrate Github files to Orange for ML?

There are three ways to install Orange add-ons:

The Options -> Add-ons menu of Orange.

Use pip: pip3 install orange3-prototypes

Install from the source:
Terminal commands:
git clone https://github.com/biolab/orange3-prototypes.git
cd orange3-prototypes
python3 setup.py install


What does it mean for an activation function to be "saturated/non-saturated"?

Please see this answer.

An activation function is considered non-satured if

$$
\lim_{z \rightarrow \infty} f(z) = \infty
$$

A saturated activation function has a compact range such as $[-1,1]$ for $\tanh$ or $[0,1]$ for the sigmoid.


I think your question has multiple answers. Let's start with a tool created with this purpose named featuretools. You can read more about it on the excellent documentation, but just to give you an intuition, think about a dataset that is on transaction level, that is, you have one row a new transaction, and then you want to make predictions based on customer level, you will create a series of features based on transactions, for example:

mean, max, min, sum, std of transactions values
number of transactions
number of unique products bought
...

This tool will automate all these tasks based on entity sets and relationships between your datasets.

Now, think about your situation, you might use PolynomialFeatures from scikit-learn to generate interactions and polynomial features that is more automated than other approaches.

Having said that, based on your score, in a real application, using these approaches, or trying to improve performance using more features, is overwhelming and not useful. We use kaggle as our standard training, and I think it is really good, but business requires explanation as well, and they will be happy with less predictive algorithm if they can trust on it.


How are data in tensorflow.examples.tutorials.mnist formatted?

Based on the official documentation after loading the data,

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

You can use the following line,

mnist.train.images.shape

to see the shape of images, as you can see it is a rank-2 matrix which means images are unrolled which one dimension specifies the number of examples and another specifies the number of pixels __features.


Is it possible to use Recurrent NN (LSTM) for classification?

Yes, it is possible. You will first use a LSTM layer and then use a Dense/Linear layer on top of it to get the final output. Make sure that your linear layer has number of outputs = number of classes.


Difference between Ridge and Linear Regression

Yes, ridge regression is ordinary least squares regression with an L2 penalty term on the weights in the loss function. The loss function is not really linear in any of its terms, right? it's the squared residuals plus squares of weights. But there is no reason the loss function needs to be linear. It's helpful if it's convex, which it is here, but even that is not required to try to minimize it.


Training Error decreasing with each epoch

I am not very sure about your case, usually I have seen the same problem but in the other direction, you can take a look here:

Quora loss drecrease, accuaracy constant
Cross validated loss drecrease, accuaracy constant

I would guess that your DNN is getting more answers right but without impoving its confidence  a lot.
Regarding your other questions, I would advise you to start with simplest possible model, for example, in this case it would be using the vgg16 (which is widely more used than the vgg19) and the default parameters ( number of neurons, optimization function...) Once you have something working you can start tuning and modifying things.


When fitting a GLM (at least in R), I know there is a optional weight vector that you can include.  This weight is not to give more importance to an observation, but to rather weight observations based on $T$ for example.

The R documentation says:

 For a binomial GLM prior weights are used to give the number of trials
 when the response is the proportion of successes

So I believe this would help adjust for your non-uniformity.  How to choose those weights can be tricky I suppose and can vary a lot with your data, but its worth looking into if it looks like it will help your problem.

Do you have enough data where you can play with dropping data, or maybe if you simulate how much the $SR$ is inflated at low $T$ you can try to adjust for it somehow.  It looks like after about 1000 trials the high success rate issue begins to mellow out, and after 3000 or so you start getting more reliable measures.


convert dataframe without header to dictionary with a row of number

Works for me with numbers as headers:

import pandas as pd
df = pd.DataFrame({'1': [1, 2],
                 '2': [0.5, 0.75]},
                 index=['row1', 'row2'])
df.to_dict()

Output:

{'1': {'row1': 1, 'row2': 2}, '2': {'row1': 0.5, 'row2': 0.75}}

You may also specify column names when you read the data:

Cov = pd.read_csv("path/to/file.txt",
                  sep='\t',
                  names=["Sequence", "Start", "End", "Coverage"])

See: https://stackoverflow.com/questions/34091877/how-to-add-header-row-to-a-pandas-dataframe


what is the largest network used for image recognition/segmentation?

There are many models proposed for image segmentation but I've used the U-net architecture which is basic enough for educational reading.
Some more examples can be found here


how to programmatically introduce grammatical errors in sentences

Generating artificial errors is generally risky in NLP, because it's difficult to make sure that the type and distribution of errors correspond exactly to real human errors. If the artificial errors diverge from real errors and a model is trained based on this data, the model will appear to have very good performance since it will rely on the patterns used to generate the errors. However it might not perform well with real data, and it would be difficult to detect it.
That being said, it's been a problem which has been studied for quite a while so the state of the art should help: Google Scholar gives a lot of references, probably some of these papers provide existing implementations as well. One may notice that the concerns I mentioned above are a recurrent question, with some recent papers analyzing how much artificial errors actually help.


Does running the script of train_test_split several times with varying test size in sklearn cause data leakage?

It's understandable that when you get less training data your model can overfit (i.e. less data means less requirements to satisfy for your objective function which results in easier fitting for the problem) but it is also interesting that your models are sensitive to that much change. I advise you to try cross-validation with 30 % test split size using RidgeCV and LassoCV classes.


"As I understand, if the p-value is smaller than 0.05, then I can reject the null hypothesis and tell that the variances are not equal (and then it makes sense to use ANOVA."
Your understanding is incorrect. As a measure of goodness of fitness of data, null hypothesis has to be accepted if alpha is less than  or = .05. If you want to perform statistical test of variability across groups, you need  an implementation of Chi-square test of variability across groups.
Your intuition (question in last part of body) -p-value should be greater than 0.05  is not logical. This value indicates sampling fluctuations or error arising on account of chance in sample selection. An (sampling ) error greater than 5% is not acceptable by any standards.


Will the features in the image (edge, color, etc.. ) impacts on the performance of the spherical k-means?

Yes it is true that in these images follow the trend you pointed, but that is not the only reason for the drop in accuracy:

Image 1 is pretty simple, and binary so it is easier samples, not because of clarity but of simplicity.
Image 2 is a bit more complex, but it is still binary and can be learned easily.
Image 3 is simple, but it is noisy and (as you pointed out) does not have strong features, since you're not dealing with CNNs you should pre-process this kind of dataset by binarization or image sharpening after noise removal (if you do it before you will amplify noise). This probably was taken with bad light conditions.
Image 4 this is really complex image, it is on color and until now I couldn't figure out what it is lol

Well, you are not wrong in your idea, but taking conclusions that way may mislead you on the future. There are other reasons (as pointed above) for your findings. So:

Create a thesis (like you did)
Test your thesis by trying to change the observed phenomena (e.g. pre-process images to find stronger features)
Check if that improved your results, create a new thesis and repeat until satisfied with results


Why the loss is nan by using linear activation function in the last layer?

There seem a lot of initialization problems.

There ain't too many biases. Its just 1 per layer. Your shape of
biases seems wrong.
You may have got the network right in shapes since it doesn't return shape errors. But bear in mind, it seems highly likely #1 is
true.
Same goes to w0 and w1.

Consider checking all dims again. If you need, I'm attaching a sample Neural Network implementation in python.

https://raw.githubusercontent.com/MasterSkepticista/NEAT_py/master/network.py

This is as it happens to be taught in Andrew Ng's course.


new and fresh ideas with stack exchange dataset

It might help to have a bit more information on what you want to do, but have a look at Kaggle - it's a regular big data science competition, all of the data sets are huge and available for download.

There's also some smaller datasets made available by Tableau.

Hope that give you some inspiration!


Categorical encoded variables in scikit-learn diabetes dataset

Yes, it is perfectly legal to do so. Scaling such binary variables does not change the shape of its histogram and the shape is all that matters to most models.


Using categorical_crossentropy for binary classification

Binary cross-entropy is a special case of categorical cross-entropy with just 2 classes. So theoretically it does not make a difference.

If $y_k$ is the true label and $\hat{y}_k$ is the predicted label of class $k$ (both one-hot encoded, i.e. $\sum_k y_k =1 \land \sum_k \hat{y_k} =1 \land y_k,\hat{y_k} \in \{0,1\}$) the multicategorical cross-entropy for $K$ categories is
$$-\sum_{k=1}^{K}y_k \log(\hat{y}_k)$$

which is equal to the binary cross-entropy for $K=2$ :
$$-\sum_{k=1}^{K}y_k \log(\hat{y}_k) = -y \log(\hat{y})- (1-y) \log(1-\hat{y})$$

Just in case there are any implementation differences, e.g. speed-wise, I would still just use binary cross-entropy for a binary classification problem instead of multicategory with $K=2$.


How to get probability of classification

It is indeed a probability of 1 because you didn't change the default parameters.

The probability for KNN is the average of all the neighbors. If there is only one neighbor n_neighbor=1 it can only be 1 or 0.

The DecisionTreeClassifier expands until all the training data is classified perfectly if you don't control the depth. Again, this likely led to overfitting and to extreme probability predictions as a result. You should try different values for max_depth and see what works best. You can do say by performing cross validation. (If you are unfamiliar with these I recommend reading up on it first.)


Best Model for Multi-label image classification

The models will stay the same for the case like ResNets, EfficientNets, NFNets and MobileNet amongst many others. To start with go EffNetB4, good training speed and accuracy. These are great feature extractors what you do with them bring another complexity so in multi-label, look at using label_smoothing for regularization.


So, before just diving into the performance of the CNNs based on the two methods, just lets start with what they both will do to the input.

The first method (IMG/255.0, and we'll call it scaling) will have the data scaled between 0 and 1. The second method (IMG - mean/STD, we'll call it centering) will have inputs ranging from arbitrary numbers (can be both positive and negative) with 0 being the mean.

Scaling will improve the convergence speed of the model, whereas centering will not only speed up the convergence of the model, but will also deal with the gradient exploding and vanishing problem.

As mentioned in CS231, centering is enough, since it does the scaling thing as well.

Lastly, as long as you don't have a very deep model, the two techniques won't make a lot of difference because batch-normalisation takes care of pretty much everything regarding image normalization, where all the layers receive the normalized data, and not only just the first one.


What is the risk of removing a feature with low correlation...?

Variable selection in linear regression is based on partial correlations, not zero order correlations. The partial correlation is the one resulting after a conditioning variable effect is removed from both X and Y.

While a variable may be non highly correlated with Y, it may be highly correlated with an X variable in such a way that the X variable after being partialled out of the conditioning effect becomes highly significant.

This effect is known as suppression among other names.
HTH


Multi-Feature One-Hot-Encoder with varying amount of feature instances

I think you can transform this into a text preprocessing problem and then use CountVectorizer. You basically build "documents" by putting together all the words in your raw data and then use CountVectorizer on those documents.
from sklearn.feature_extraction.text import CountVectorizer

X = [["banana","apple","cucumber"], ["orange","banana", "cucumber"]]
# Create documents
X_ = [' '.join(x) for x in X]
enc = CountVectorizer()
print(enc.fit_transform(X_).toarray())

Returns
[[1 1 1 0]
 [0 1 1 1]]

which has 4 different values as you expected.


"Granularity" refers to the resolution of the variables under analysis.  If you are analyzing height of people, you could use course-grained variables that have only a few possible values -- e.g. "above-average, average, below-average" -- or a fine-grained variable, with many or an infinite number of values -- e.g. integer values or real number values.

A measure is "fuzzy" if the distinction between alternative values is not crisp.  In the course-grained variable for height, a "crisp" measure would mean that any given individual could only be assigned one value -- e.g. a tall-ish person is either "above-average", or "average".  In contrast, a "fuzzy" measure allows for degrees of membership for each value, with "membership" taking values from 0 to 1.0.  Thus, a tall-ish person could be a value of "0.5 above-average", "0.5 average", "0.0 below-average".

Finally, a measure is "rough" when two values are given: upper and lower bounds as an estimate of the "crisp" measure.  In our example of a tall-ish person, the rough measure would be {UPPER = above-average, LOWER = average}.

Why use granular, fuzzy, or rough measures at all, you might ask?  Why not measure everything in nice, precise real numbers?  Because many real-world phenomena don't have a good, reliable intrinsic measure and measurement procedure that results in a real number.  If you ask married couples to rate the quality of their marriage on a scale from 1 to 10, or 1.00 to 10.00, they might give you a number (or range of numbers), but how reliable are those reports? Using a course-grained measure (e.g. "happy", "neutral/mixed", "unhappy"), or fuzzy measure, or rough measure can be more reliable and more credible in your analysis.  Generally, it's much better to use rough/crude measures well than to use precise/fine-grained measures poorly.


How does Doc2Vec treat numerical data which is a part of text data?

If you are passing in the numbers as a string type Doc2Vec should just accept these as part of the vocabulary without an issue. Have you tried running the Doc2Vec training with the numbers still included?

One way to solve the issue if you can't just pass the values in as is is to give them a unique identifier (e.g. < NUM >). It shouldn't matter what the value is as Doc2Vec should in theory not be able to draw any information (and really shouldn't) from that. Instead if you teach it when a number occurs in a document (by using the identifier) that might improve accuracy.


Understanding the "Wide" part of Google's wide and deep

Indeed you will have a large and very sparse matrix. The two important concepts in this are:

feature cross: you have two categorical features (here impressed and installed) and you do a carthesian product of both to create a new feature (as you did here). The issue is that crosses generate sparse matrices (as you can see in your example)

Neural netowrks perform well with dense, correlated features while linear models work better with sparse and low correlated feartures. Your cross features are sparse with low correlation, which leads to the second concept:

wide and deep network: since your dataset is a mix between dense features (continuous features) and sparse (cross) you can separate your network in two: the sparse will be directly sent to your output and thus treated as they would be in a linear model while your dense features will go through several hidden layers before going to the output.

The wide part behaves just like a linear model (you can also use sparse matrix calculus to speed it up) and the deep part like a traditional neural network and you get the best of both worlds. Given the size of the dataset (billion users x million apps), treating part of the data as a sparse input will speed up training and inference.

I went a bit further than what you asked but I figured it could be of help.


How to interpret the value of categorical cross entropy?

There is usually no straightforward interpretation of what cross-entropy means in the context of the given task. In practice, it is more important to follow the trend of how the cross-entropy develops during the training.
The measure comes from the information theory. It says how surprised the model is when it has some belief about the output (a distribution) and you provide it with the ground truth output. A nice (but not very useful) interpretation is that the entropy of $x$ means the same surprisal as observing an output of rolling and $2^x$-sided dice.
The value of cross-entropy indeed depends on the number of classes, just because with more classes you have the output distribution must cover more options and it is more difficult to assign more probability to the ground truth class.


When is precision more important over recall?

For rare cancer data modeling, anything that doesn't account for false-negatives is a crime. Recall is a better measure than precision.
For YouTube recommendations, false-negatives is less of a concern. Precision is better here.


Given time series data, how to model the frequency of someone changes his job?

A simple and perhaps somewhat naive approach would be to assume that a person changes jobs at a constant rate and that previous job changes have no influence on future ones. Under these assumptions you could model the job changes as a Poisson process and estimate the rate parameter using MLE (http://en.wikipedia.org/wiki/Poisson_process and http://en.wikipedia.org/wiki/Poisson_distribution).

Of course one should explore how well these assumptions hold in the data. To do this, you could study whether or not job changes are independent of one another by computing the correlation between events at various lags (http://en.wikipedia.org/wiki/Correlation). You could also plot the distribution of time between job change events. If the process is Poisson-like then you should observe little to no correlation between events at any number of lags and the distribution of time between job change events should be exponentially distributed (http://en.wikipedia.org/wiki/Exponential_distribution).


Are there any algorithms that learn to learn a function mapping?

This is equivalent to thinking of this as learning a function of two inputs, i.e.,  $g : (X,Z) \mapsto Y$ (i.e., $g(X,Z)=Y$).  Any machine learning method for learning functions can be used for that; you just treat the feature vector (the input) as the concatenation of the vector $X$ and the vector $Z$, and then use standard ML techniques on the resulting instances.  So, you don't need anything special or fancy to handle this -- you can use any existing machine learning method that you are comfortable with.


How to train f(x)=x*x using Artificial neural network?

The answer to your question lies here.

Personally, since I can see the high autocorrelation of your input signal x (obvious that x(t+1) = x(t) + 1), you could treat it as timeseries and use an LSTM-RNN to model the nonlinear function y. For simplicity, you could always treat your data as iid and, under this assumption, use an MLP.


Keras create custom network with certain unconnected neurons

I believe you can do this using the functional API and playing around with your input. Suppose you have the sets of input features (can be singleton sets) $a$,$b$,and $c$ for some $x$ in $X$. If you split your input into $X_a$, $X_b$, and $X_c$, where all elements in $x$ is transformed to include only features in $a$, you can theoretically build this model.

Here's a code snippet demonstrating this idea, given $X_a$, $X_b$, and $X_c$, and their corresponding shapes. You could widen this model by expanding the fully-connected layers (by increasing the variable set to 1 in the Dense calls). No promises on the code working off the bat: I've brushed over some details but this should give you a start on your problem.

input_A = Input(shape=shape_A)
input_B = Input(shape=shape_B)
input_C = Input(shape=shape_C)
A = Dense(1)(input_A)
A = Dense(1)(A)
B = Merge([input_A, input_B, input_C], mode='concat')
B = Dense(1)(B)
C = Merge([A,B],mode='concat)
C = Dense(1)(C)
B = Merge([A,B],mode='concat)
B = Dense(1)(B)
A = Dense(1)(A)

From here, if you want one output, you can call merge on $A$, $B$, and $C$ and then tack on a Dense (Fully-Connected) layer with, for example, a Softmax layer for multi-label classification.


Value error while using linear regression | ML

You have missing values in your DF (NaN) means no observations. You need to skip these values since linear regression cannot handle them. Looks like conversion of sqm failed. Check what the format is and try to get int or float from sqm column to avoid NaN.

If you want to skip NaNs read the docs: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.dropna.html


What's the principal difference between ANN,RNN,DNN and CNN?

Welcome to DS StackExchange. I'll go through your list:

ANN (Artificial Neural Network): it's a very broad term that encompasses any form of Deep Learning model. All the others you listed are some forms of ANN. ANNs can be either shallow or deep. They are called shallow when they have only one hidden layer (i.e. one layer between input and output). They are called deep when hidden layers are more than one (what people implement most of the time). This is where the expression DNN (Deep Neural Network) comes.
CNN (Convolutional Neural Network): they are designed specifically for computer vision (they are sometimes applied elsewhere though). Their name come from convolutional layers: they are different from standard (dense) layers of canonical ANNs, and they have been invented to receive and process pixel data.
RNN (Recurrent Neural Network): they are the "time series version" of ANNs. They are meant to process sequences of data. They are at the basis of forecast models and language models. The most common kind of recurrent layers are called LSTM (Long Short Term Memory) and GRU (Gated Recurrent Units): their cells contain small, in-scale ANNs that choose how much past information they want to let flow through the model. That's how they modeled "memory".

If you want to learn how to implement all these forms of ANN in TensorFlow, I suggest you this wonderful book:

Hands-on Machine Learning with Scikit-Learn, Keras, and TensorFlow, 2nd Edition by Aurélien Géron

this is the best book on ML and DL, IMHO.


Trying to predict extreme values corresponding to rare events

My suggestion:

There is a technique called Quantile Regression, which allows you to determine the highest (or lowest) values of a variable. This is valid only if you have regressors (exogenous variables).


Will a Count vectorizer ever perform (slightly) better than tf-idf?

I would say 1000 documents is a bit less to draw any conclusion about the vectorization technique, Neither an increase in True positive by 1 would matter. As the size of the vocabulary increases, TfidfVectorizer would be better able to differentiate rare words and commonly occurring words while Countvectorizer would still give equal weight to all words which is undesirable. So, TfidfVectorizer will give you better performance than CountVectorizer as the size of the vocabulary increases


check out the following paper. It purposes a 2 stage network and then used the output of the first stage to do grad CAM.
https://ieeexplore.ieee.org/abstract/document/8970899/


In my experience the activations are irrelevant to whether the classes are binary or multi-class. Their effectiveness depends on the kind of data you have.

Furthermore, there is one node in the layer because you are doing a binary classification. In other words, when the value of the last node is low or below a threshold the class is 0 and 1 if otherwise(value of last node is high or above a thresold).

And yes, if there are more classes you need as many nodes in the last Dense Layer. You can also you 2 nodes when you only have two classes in your data and predicting the one with the highest score/output.


Purpose of backpropagation in neural networks

Is backpropagation just fancy term for weights being optimized on every iteration?

Almost. Backpropagation is a fancy term for using the chain rule.

It becomes more useful to think of it as a separate thing when you have multiple layers, as unlike your example where you apply the chain rule once, you do need to apply it multiple times, and it is most convenient to apply it layer-by-layer in reverse order to the feed forward steps.

For instance, if you have two layers, $l$ and $l-1$ with weight matrix $W^{(l)}$ linking them, non-activated sum for a neuron in each layer $z_i^{(l)}$ and activation function $f()$, then you can link the gradients at the sums (often called logits as they may be passed to  logistic activation function) between layers with a general equation:

$$ \frac{\partial L}{\partial z^{(l-1)}_j} = f'(z^{(l-1)}_j) \sum_{i=1}^{N^{(l)}} W_{ij}^{(l)} \frac{\partial L}{\partial z^{(l)}_i}$$

This is just two steps of the chain rule applied to generic equations of the feed-forward network. It does not provide the gradients of the weights, which is what you eventually need - there is a separate step for that - but it does link together layers, and is a necessary step to eventually obtain the weights. This equation can be turned into an algorithm that progressively works back through layers - that is back propagation.

  To be more precise, what's the point of automatic differentiation when we could simply plug in variables and calculate gradient on every step, correct?

That is exactly what automatic differentiation is doing. Essentially "automatic differentiation" = "the chain rule", applied to function labels in a directed graph of functions.


In your specific case you are working with cities, which can be modelled as geographic location. I've never used it be you could look at the geohash method.

Or could also use an identifiant for each city. An algorithm like a random forest can directly use it this way.


Thought I'd share what I found here.

I have not tried any of this yet, but this looks very good, the Automatically Generated Inflection Database (AGID).

There is also the SPECIALIST Lexicon.

And for those using python, there are various modules you can use, such as LemmInflect.


In Deep Learning, how many kinds of Attention exist? And what is the history of Attention models?

As far as I know, one of the first "successful" use of attention came in 2014 by Badhanau, Cho, and Bengio with their paper "Neural Machine Translation by Jointly Learning to Align and Translate"

Since then, attention has been refined and improved in multiple papers. Attention is All You Need and the ever-growing use of transformers has made it even more popular.

However, I think it's crucial to understand that even though it has shown incredible value, it is ultimately just a mechanism that weights inputs in an attempt to pool them together in a smarter way than max or averaging pooling.


Found this as a hack, is this an efficient solution?
torch.complex(*x)
it unpacks the first dimension and feeds it into the real and complex dimension


sklearn stratifying dataset with more than one label

Looks like you have a set of "dummy" variables which were previously the same variable.

What you could do is to return to the original variable, get the stratified data, and then rerun the one-hot encoding to have the variables again.

Remember: If your dataset is very balanced, your results with and without stratification will be almost the same.


It depends on the complexity of the data. If the data representation is enough for one hidden layer then yes, it is possible, or at least it'll be able to find the best solution possible.

If the dataset is highly dimensional then it's unlikely that the neural network reaches a good generalization of the problem. So a local optimum is probably the only conclusion that the network will be able to find.


How to remove background (watermark) logo from image

Take a look at the python cv2 module. It has functions that should enable you to remove the watermark. If you have a separate image of the watermark and it is always in the same coordinate location in each image you should be able to subtract it from the images


Which Policy Gradient Method was used by Google's Deep Mind to teach AI to walk

They used Distributional Proximal Policy Optimization (DPPO). In the article that video is associated to, they provide a brief overview of it:

In order to learn effectively in these rich and challenging domains, it is necessary to have a reliable and scalable reinforcement learning algorithm. We leverage components from several recent approaches to deep reinforcement learning. First, we build upon robust policy gradient algorithms, such as trust region policy optimization (TRPO) and proximal policy optimization (PPO) [7, 8], which bound parameter updates to a trust region to ensure stability. Second, like the widely used A3C algorithm [2] and related approaches [3] we distribute the computation over many parallel instances of agent and environment. Our distributed implementation of PPO improves over TRPO in terms of wall clock time with little difference in robustness, and also improves over our existing implementation of A3C with continuous actions when the same number of workers is used.

Here are some resources:

The deepming blog post describing the method
The original article: Emergence of locomotion behaviours in rich environments


Categorical cross-entropy works wrong with one-hot encoded features

For it to work -

Change output neurons count to 02
Activation of output to Softmax
Keep all the vectors of OHE output

This is how Keras is designed internally. Same has been written on the official documentation page

BinaryCrossentropy class
Use this cross-entropy loss when there are only two label classes (assumed to be 0 and 1). For each example, there should be a single floating-point value per prediction.
In the snippet below, each of the four examples has only a single floating-pointing value, and both y_pred and y_true have the shape [batch_size]

CategoricalCrossentropy class
The shape of both y_pred and y_true are [batch_size, num_classes]

And we know that to keep the Classification multi-class you need to make all the num_class output relative to each other, so we use softmax
Ref
Keras official page
Similar SE thread
Similar SE thread


When should ordinal data be represented catigorically and when as integer?

You shouldn't keep it like this any way. One option is one-hot encode, but since your variables are ordinals, there's no point in one-hot encoding, you can just transform them into natural numbers.

One-hot encoding will increase numbers of independent variables significantly, that's why one-hot will be worse for your model. But your variables are clear ordinals, because they have clear order for all the values.

So, it this case transforming into natural numbers is the best option.


How to evenly distribute data to multiple GPUs using Keras

Check out the docs on TensorFlow GPU usage
If you wanted data parallelism where you run a copy of your model on multiple GPUs and split the data between them, you could use the tf.distribute.MirroredStrategy.
The tf.distribute.Strategy docs are also a good source to read.
Also, you should also profile your application; adding a second GPU has the potential to reduce performance depending on what your bottlenecks are.


Recurrent neural network multiple types of input Keras

Kera's functional API allows arbitrary models to be combined like you are describing.

One option is to define a model very similar to the documentation linked above. First, define a "main input" that is categorical, and then, define an "auxiliary input" that is numerical. Both of these sub-models can be merged into a single network with additional layers.


Dueling DQN - can't understand its mechanism

A slightly unrelated thought, 'V' is the score of the current state only. 'A' is the total future expected Advantage, for a particular action, right?

Not quite. $V$ is the total (discounted) future expected reward, assuming starting in state $s$, following current policy (in a control problem, usually best guess so far at the optimal policy) into the future. That includes selecting current action, $a$, according to the policy being assessed. The advantage function $A(s,a)$ (blog post has the arguments wrong for $A$) is the difference in value between selecting $a$ according to the current policy and selecting a specific action $a$. The value of $A$ also sums all future rewards assuming that the current policy is then followed into the future after this, maybe different, selection. Note that when the policy is the optimal one, and $V(s)$ is accurate, then $A(s,a)$ should always be zero or negative; optimal actions score zero, non-optimal ones will be negative.

  Even if network somehow benefits from one or the other, how does it help if both streams still end up as Q?
  ... Can someone provide a different example to the sunset?

The more prosaic explanation is that the function decomposition is always technically correct (for an MDP). Coding the network like this incorporates known structure of the problem into the network, which otherwise it may have to spend resources on learning. So it's a way of injecting the designer's knowledge of reinforcement learning problems into the architecture of the network.

Conceptually this is similar to designing CNNs for computer vision with local receptive fields because we know edges and textures can be detected this way in images. Although CNNs have more than just that benefit, one of the positive aspects of the design for vision tasks, is that they structurally match known traits of the problem being solved.

Value-based RL control methods (as opposed to policy-gradient methods) work due to "generalised policy iteration", where the agent is constantly assessing the current values of a policy, then using those value estimates in order to make improvements. The split between $V$ and $A$ functions fits very well with that conceptually. The $V$ function is generally being adjusted to assess the current policy as accurately as possible, whilst positive values in $A$ function identify likely changes to the policy.


Pattern Recognition - Kernel Density estimators 2.5.1

Pls. refer the equations above. In case of eq 2.248 (left box image) we're calculating density at point $x$, only. There are total of 3 points, only 2 qualify as per kernel function and hence probability at $x$, $p(x) = \frac{2}{3}$.

The right box diagram shows that we take the points, one by one, and calculate the probability at each point using kernel function. Thus we get probability at each of point of data set. And effectively, we get a probability distribution for the entire data set.

The bar chart shows the PMF for 2 cases - left: probability based on (eq 2.248) and right: for (eq. 2.249). I use PMF to easily communicate the understanding.

*Note:

1- With x_1 centered cube 2 points: x_1 & x_2 lie inside the cube; same for x_2 centered cube. However for x_1 only one point x_1 lies in the cube - out of total of 3 points.

2- d|a, b| gives distance between points a, b.

3- for a large collection of data points and cubes of small sides (h), we get a PDF distribution curve.


Does pruning a decision tree always make it more general?

If you filter something out by choosing one branch over another branch in the tree, the observations you did not choose are forever lost.

But to directly answer your question - no, it does not always make it more general. If you construct a tree where all the decision are exactly the same, then pruning does not make it more general.


Macro- or micro-average for imbalanced class problems

The choice of a metric depends on how you rank the importance of your classes and what you value from a classifier. Let's look at your example:

  For example if we have a data set with 90%-10% class distribution then a baseline classifier can achieve 90% accuracy by assigning the majority class label.

One minor correction is that this way you can achieve a 90% micro-averaged accuracy. If your goal is for your classifier simply to maximize its hits and minimize its misses, this would be the way to go.

However, if you valued the minority class the most, you should switch to a macro-averaged accuracy, where you would only get a 50% score. This metric is insensitive to the imbalance of the classes and treats them all as equal.

In many applications the latter is preferable. Imagine a classification problem aiming at diagnosing a disease that appears in 1% of the population. What good is a classifier that would always predict that the patient was healthy, even if it could achieve a 99% micro-averaged accuracy on the task?

The reason why micro-averaging is prevalent is because in most tasks, we would be interested in simply maximizing the number of correct predictions the classifier makes. In these tasks no class is more important than the others.