Is it possible the model be better on a few epochs rather than hundreds of epochs?

Yes, this is the reason you should use 'early stopping' in your models which will stop training when the model is not improving or you can keep the history of the training to pick the epoch that had the best performance.
The reason you get excellent results in the 12th epoch, but terrible performance in the 100th epoch is simply you are overtraining. By overtraining, you are causing overfitting, and the model is not able to generalize, instead, it imitates your data. Thus, the model will have high accuracy in in-sample data but comparably bad in out-of-sample data when you train a lot.
Moreover, take into account that unnecessarily complex and poorly regularized models are likely to overfit also. Especially, when the input data size is small. But in any case, if you lose performance as you train the model, this is probably because of overtraining.
For this reason, try to always have a graph of training accuracy vs test accuracy (or validation accuracy) by epoch. Thus, you can observe where (in which epochs) train and test accuracy move together. Where your train accuracy is >> test (or validation) accuracy then there happens overfitting, and where your test (or validation) accuracy is >> train accuracy then you are underfitting there.


Outlier detection on categorical network log data

Foremost, in my opinion categorical data should not be converted to continuous format at all. This is statistically incorrect.

Second, if a categorical data say Sex with two levels Male, Female exists then it can be written as 1,2, but, it should be specified that these numbers are to be treated as nominal and not continuous.

Continuing further, one method of detecting outliers in categorical data is to calculate the frequency of the data points and then average each such obtained frequency to the total number of data points. The data points with the minimum frequencies can be considered as outliers.

You might find this paper and this SO post implementation in R interesting.


If the participant has answered the question 2 before the question 1, you will lose the information on question one by using .agg("first") in the 4th option


Is there a real C4.5 implementation in Python ? (handling missing value)

I don't think there is a C4.5 implementation in a popular python library. Your options are :

Try github implementations such as : https://github.com/geerk/C45algorithm
Try getting R implementations with rpy package : see over there for an exemple of how that would work (C5.0) https://stackoverflow.com/questions/41070087/calling-c5-0-in-python


optical chemical structure recognition from images

What way I could follow to achieve this?

Create a dataset with image-label pairs.
Create a classification model.

I don't think you will find any algorithm "out-of-the-box" for you to use.
You might have a look at some paper to see the kind of approaches they have.

I would recommend you look at these:

https://arxiv.org/ftp/arxiv/papers/1802/1802.04903.pdf which uses convolution neural nets and a heatmap as an attention mechanism. It even deals with noisy images.
https://web.stanford.edu/class/cs231a/prev_projects_2016/optical_recognition_of_chemical_structures.pdf which tries to identify hand-drawn structures. It uses a sort of edge detection algorithm for recreating the hand-drawn structures.


Support vector machine model in sklearn support adding max iterations parameter which you can change to a higher value. But they don't have epochs parameters nor do they support batch sizes.
To go into more depth, support vectors use an exact convex optimization algorithm, not stochastic gradient descent (like Neural nets). They work on the entire dataset at the same time. The algorithm will run for max iterations or till minimum value is achieved and report one single accuracy number.
From the question it is not clear why you want to train multiple times using epochs. Comparing with neural networks, the equivalent here will be to just set high max iterations parameter and training once.


I got the following error : 'DataFrame' object has no attribute 'data'

"sklearn.datasets" is a scikit package, where it contains a method
  load_iris().

load_iris(), by default return an object which holds data, target and other members in it. In order to get actual values you have to read the data and target content itself.

Whereas 'iris.csv', holds feature and target together.

  FYI: If you set return_X_y as True in load_iris(), then you will directly get
  features and target.

from sklearn import datasets
data,target = datasets.load_iris(return_X_y=True)


How to train convolutional neural networks on unbalanced datasets of images?

By oversampling. When training a CNN, you generally use a mini-batch gradient descent method. The mini-batch method consists on taking some images at random and performing a gradient step with those images by backpropagating the loss of the model on those images. This random selection doesn't need to be uniform on all the images. Instead, you can make the images in the classes with few elements appear with more likelihood (oversampling them) than the other images. With this, you can help the CNN not only to learn about the most prevalent classes.

In addition, if you have very few number of images of some classes, it is recommended to do image augmentation, thus generate more images in order to avoid overfitting those classes.


Can data analytics be a basis for artificial intelligence?

Classes related to Artificial Intelligence are typically taught in Computer Science departments. Looking at the IT Project Subjects offered by your university, I suspect Data Analytics would indeed be more relevant to AI than Internetworking and Applications.

Looking at the courses offered by your department, the following likely involve aspects of AI:

Image Processing and Pattern Recognition
Intelligent Agents
Building Intelligent Agents

For self-directed study in AI, I recommend starting with Russell & Norvig's essential textbook Artificial Intelligence: A Modern Approach.

As to what it will take to create a human-like strong AI, I recommend this collection of essays: The Philosophy of Artificial Intelligence... even though the material is getting a bit out-of-date by now.

Good luck!


emission probability using hmmlearn package in python

According to that same documentation you provided, the way to use custom emission probabilities is:

"1.1.3. Implementing HMMs with custom emission probabilities
If you want to implement other emission probability (e.g. Poisson), you have to implement a new HMM class by inheriting the _BaseHMM and overriding the methods init, _compute_log_likelihood, _set and _get for additional parameters, _initialize_sufficient_statistics, _accumulate_sufficient_statistics and _do_mstep."

NOTE: The documentation pages are for hmm.learn version 0.1.* which is no longer the most recent one. That is, it seems that the documentation page available at any given time might not correspond to the most recent version of hmmlearn. For example, sample code for hmm  0.1.* does not run with hmm learn 0.20.


find most dense neighborhood of points in high dimensional space

Look into anomaly detection algorithms. Scikit-learn has a variety of built-in ones in its outlier detection module. Finding 30 most similar points among 500 is the same as finding 470 outliers. Most of these algorithms have a parameter contamination which specifies what fraction of your dataset you generally expect to classify as outliers, so manipulating the value of this parameter can possibly give you what you want to achieve.


Why not use more than 3 hidden layers for MNIST classification?

Empirically, the network performance does not increase much for a fully-connected network on MNIST when you add layers, but you can probably find ways to improve it on networks with 3+ hidden layers, such as data augmentation (e.g. variations of all inputs translated +-0..2 pixels in x and y, roughly 25 times the original data size, as a start).

I don't think this idea is pursued very far in practice, because CNNs offer a much better performance increase for the effort required. You hit the point of diminishing returns earlier with a basic MLP (around 96-97% accuracy) than you can reach easily with a CNN (around 99% accuracy).

The theory basis for this difference is not obvious to me, but very likely yes this is related to over-fitting. The weight sharing and feature pooling in a CNN is very effective way of processing image data for classification tasks, and avoids over-fitting by reducing the number of parameters, whilst re-using the parameters for the task in a way that makes very good sense given the nature of the inputs.


Training a Siamese Neural Network for object similarity assessment

without going into architecture that looks reasonable but always can be updated: Weights are dominantly updated for the negative pairs. why?

In the train set where you have (approx) 10 000 times more negative samples, you are training on them and letting the network learn almost only negative pairs, but then you test it on validation and you get what you would expect. No improvement on accuracy or loss on validation set. Make sure you are more balanced (down sample train or upsample valid/test)

EDIT: given new ifo here is a couple of suggestions.

Indication is overffiting obviously

Early Stopping as soon as validation dataset reaches minimum STOP training. ITs overkill after that
Covariate-shift make sure that patterns are similiar in all three sets (I assume they are but just in case)
Reduce complexity, how deep is your architecture, maybe you are over doing it. If you took some random Siamese network architecture from online it may be too much (they used it for images for example where you need additional complexity)


Just change the ’ to " it works just fine, see:

from sympy import *
x,y=symbols("x,y");
solution=solve((4*x-3*y-17,7*x+5*y-11),x,y);
P=(solution[x],solution[y]);

print(P)
(118/41, -75/41)


Validation loss diverging away from the training loss

This kind of overfitting is typical when finetuning large LMs.
The usual approaches to "avoid" it are:

Early stopping: select the checkpoint with the best validation loss.
Random restarts: train multiple times from scratch, and select the model with the best validation performance.


Is it possible to use an array of graph coordinates as an input variable?

Yes, the graph coordinates can be used as features for training your algorithm( whichever classification algorithm you choose). Features will be X and Y and output will be labelencoded type of country.


Input with variable length Classification problem

The goal is to predict the current stage for one patient, so for the classification part you must have a single instance for every patient. So the question is how to transform your features repeated for every visit into a fixed number of features.

The standard option is to use expert knowledge to engineer the features. For example there might be some features which are only relevant at a certain point in time and no longer relevant later, so for these you can just keep the latest value. There might be some features for which the evolution across time is significant, so for example the average increase in the past N months might make sense. The idea is to "summarize" any number of visits into a fixed number of features.

A more advanced option would be to "vectorialize" your features, i.e. generate some kind of embedding using some unsupervised deep learning method (but that's not my area of expertise).


Why does my random forest classifier predicts one class more often?

While prediction, If you have more date relevant to class 0 obviously this is the expected one.
But if your observation is like, the model predicts more data with class 0 as incorrect, then you model is kind of over-fitted.
To avoid these,

57% and 43% is not kind of class imbalanced, but still you use
class_weight with model.

Feature Engineering helps a lot with these kind of situations.


Spectral clustering result interpretation

Supposedly because of the weighting / normalization.

Point 8 is fairly far from all it's neighbors, so it's edges have a similar weight; and the normalization increases the edge weight to give every point the same influence. It's two other cluster members are (except they have one neighbor) similar. So I wouldn't be surprised if the two strongest edges after normalization of 8 are to 1 and 2.

To understand this better, I suggest that you compute the affinity matrix and visualize the affinities as edge strengths. The spectral embedding may also be worth looking at.

But this is an interesting example about the drawbacks of spectral clustering: normalization may give too much weight on "outliers".


Can I apply Clustering algorithms to the result of Manifold Visualization Methods?

You can do anything you want in the low dimensional space, and can try to validate as well. By clustering the above, you are in effect assigning features/tags to your data points in higher dimensions. Remember, tSNE tries to preserve distances, so that points in high dimensions will remain close to each other in low dimensions.

With that in mind, don't forget that no two instances of tSNE will be the same, which means that your clustering centers will be different each time you run tSNE.


Standarizing the Label to postive intergers in Machine Learning Classification task, why is it recommended?

Please can anybody be kind enough to explain this to me? When doing a
classification task suppose we have 3 targets with notation -2, -1, 0.
I read somewhere it is a good practice to Standardize the labels to
positive integers. In this case suppose we change it to 2, 1, 0. Why
is it recommended?

Can you please link a reference to this!. Usually in practice you wouldn't use integer labels at all. Instead you would use one-hot encoded labels. Here since you have 3 output classes, the neural network will have 3 output nodes. To be concrete the classes can be represented as follows :

0  == >  [1 0 0]
-1  == >  [0 1 0]
-2  == >  [0 0 1]

where one out of the three bits is turned ON. This is because in practice the output of the neural network may be a sigmoid (output: range[0,1]) or softmax function (output: probabilities)


Error: Input 0 is incompatible with layer lstm_1: expected ndim=3, found ndim=2

It's probably this way..(not sure , give it a try)

Iputs needs to be reshaped to be [samples, time steps, features]

so

TrainX= np.reshape(TrainX,(TrainX.shape[0], 1, TrainX.shape[1]))

You need to passin the actual vector also?


Q-learning with a state-action-state reward structure and a Q-matrix with states as rows and actions as columns

There is a problem in your definition of the problem.

Q(s,a) is the expected utility of taking action a in state s and following the optimal policy afterwards.

The expected utility of a certain state (based on your definition) is different after taking 1, 2 or 9 steps. That means that the reward of being in state s_0 and taking action a_0 is different in step 0 from what you get in step 9

To adequate model the problem, you should reframe it and consider the state to be both the 'position'+'step'. You will now have 90 states (10pos*9steps).


Reading file from Object Storage in IBM DSX

Found a sample "Load data from different sources" at https://apsportal.ibm.com/exchange/public/entry/view/07db16e78e1722931e27c074ebe343ae
It works.


Here you have some good references on Reinforcement Learning:
Classic
Sutton RS, Barto AG. Reinforcement Learning: An Introduction. Cambridge, Mass: A Bradford Book; 1998. 322 p.
The draft for the second edition is available for free: Reinforcement Learning: An Introduction
Russell/Norvig Chapter 21:
Russell SJ, Norvig P, Davis E. Artificial intelligence: a modern approach. Upper Saddle River, NJ: Prentice Hall; 2010.
More technical
Szepesvári C. Algorithms for reinforcement learning. Synthesis Lectures on Artificial Intelligence and Machine Learning. 2010;4(1):1–103.  Algorithms of Reinforcement Learning | Csaba Szepesvári
Bertsekas DP. Dynamic Programming and Optimal Control. 3rd edition. Belmont, Mass.: Athena Scientific; 2007. 1270 p.
Chapter 6, vol 2 is available for free: Dynamic Programming and Optimal Control
3rd Edition, Volume II | Massachusetts Institute of Technology
For more recent developments
Wiering M, van Otterlo M, editors. Reinforcement Learning. Berlin, Heidelberg: Springer Berlin Heidelberg; 2012 Available from: Reinforcement Learning | SpringerLink
Kochenderfer MJ, Amato C, Chowdhary G, How JP, Reynolds HJD, Thornton JR, et al. Decision Making Under Uncertainty: Theory and Application. 1 edition. Cambridge, Massachusetts: The MIT Press; 2015. 352 p.
Multi-agent reinforcement learning
Buşoniu L, Babuška R, Schutter BD. Multi-agent Reinforcement Learning: An Overview. In: Srinivasan D, Jain LC, editors. Innovations in Multi-Agent Systems and Applications - 1 . Springer Berlin Heidelberg; 2010 p. 183–221. Available from: Multi-agent Reinforcement Learning: An Overview
Schwartz HM. Multi-agent machine learning : a reinforcement approach. Hoboken, New Jersey: Wiley; 2014.
Videos / Courses
I would also suggest David Silver course in YouTube: RL Course by David Silver


How to learn irrelevant words in an information retrieval system?

If you are working with TF-IDF then it's important to experiment with min_df and max_df parameter. I guess you are on Python since you linked a Python tutorial. Here is the TF-IDF documentation and the related text to the above parameters.

  max_df : float in range [0.0, 1.0] or int, default=1.0 When building the vocabulary ignore terms that have a document frequency
  strictly higher than the given threshold (corpus-specific stop words).
  If float, the parameter represents a proportion of documents, integer
  absolute counts. This parameter is ignored if vocabulary is not None.

  min_df : float in range [0.0, 1.0] or int, default=1 When building the vocabulary ignore terms that have a document frequency strictly
  lower than the given threshold. This value is also called cut-off in
  the literature. If float, the parameter represents a proportion of
  documents, integer absolute counts. This parameter is ignored if
  vocabulary is not None.

You might find several rules of thumb on the web. Some of them suggest using a flat number on the min_df close to 5-7 documents and a percentage on the max_df about 80-85%. Maybe even lower. With this, you will be able to get rid of garbage, misspelt or unwanted tokens. Keep in mind that you need to try different combinations to get the right balance in your model.


Correlate an array of categorical features to binary outcome

How large is N?
Can you reshape your data into something like:

target   i1  i2  i3  i4  i5 ... i9 ... iN
     1    1   0   1   0   0 ...  0 ...  0
     1    0   0   0   1   1 ...  1 ...  0
     0    1   0   0   0   0 ...  0 ...  0

Once you have fit everything into a data frame, you can use any two-class supervised classification algorithm to build your model. There is no "best" model in general, but try a few to see which one works the best with your data.

Sorry for posting as an answer; comment doesn't allow preformatted text.


Does central limit theorem work well for Pareto distribution?

One key assumption of the central limit theorem is that the variance $\sigma^2$ of the underlying distribution is finite.  I would guess that you are using a parameterization of the Pareto for which $\sigma^2 = \infty$, in which case the CLT will not hold.  If you tweak your scale parameter so that $\sigma^2 < \infty$ you should see the result you want.


Have a look at a few networks:
-Siamese Network
-One-Shot Learning Model

Once going through these models you will understand how they can very well with very limited amounts of data.


OK, a bit more digging led me to this:

The TD target or "target value" gets its name because by updating a Q table or training a NN with it as a ground truth, the estimator will output values in future closer to the supplied value. The estimator "gets closer to the target".

So, I have to update the prediction network with the "ground truth".

    for i, val in enumerate(actions):
        predict_q[i][val] = target_q[i]


Why do the deconv outputs of layer >= 2 of Zeiler&Fergus look so unrealistic?

The reconstructed images from deconvnet represent the patterns in the original images which are very likely to strongly activate a particular featuremap at a particular convolution layer.

The gray portion in the reconstructed images shows that the values of those pixels in input images are not likely to strongly activate that featuremap.

There is no such gray portion in the first layer filters because first layer filter are representing the very simple patterns(e.g. edges) and those are very likely to present in input image at everywhere.


CNN tagging such that each input could have multiple tags

CNN's (generally) use softmax as activation function at the last layer, which gives a probability distribution over all possible labels. You use some kind of loss function to optimize the CNN to generate "right" label for a novel sample.

Loss function used in such case is cross-entropy loss or KL-divergence which measures how close two distributions are. For multiclass classification (different from your case, where each input example can have only one label), desired distribution is (0, 0, .... , 1, ..., 0) where 1 appears at the position of actual label. Loss function penalizes the distribution which is "far" from this distribution.

For your case you can encode your output as (0, 0, 1, 0, ... 1, ..,) so on where you put ones at positions of the labels which are associated with your input and use KL-divergence as loss function and optimize your CNN to  minimize the loss.


I guess you have made a file in your default document folder. A probable location for your notebook is where it starts if you have not changed the default path or maybe the location in which your files is located. Try to rerun your jupyter from your terminal or command prompt. It will open the contents of the folder you are looking for your notebook.


Colab can not connect to GPU from a python file

Why dont you import the file into notebook and run your function.

Eg: if your example.py has something like this

if __name__ == '__main__':
    myfunction()

Then in your colab,

import os
os.chdir("path/to/cloned/dir/")
import example
example.myfunction()


Choosing the right model for predicting demand

It looks to me that the data are in fact a Time Serie. Therefore, you can treat them as such.

Now, there are many approaches with each having each own strengths/weaknesses. I'd start with simple models such as ARMA or SARIMA. Possibly also GARCH or VAR. If you wish to go for something more advanced, Recurrent Neural Networks are also used in Time Series prediction.

Beside that, I am surprised that for example Random Forest have not given sufficient performance. Have you tried thorough feature selection? It may be that you have too high expectations.


The ground truth is what you measured for your target variable for the training and testing examples.

Nearly all the time you can safely treat this the same as the label.

In some cases it is not precisely the same as the label. For instance if you augment your data set, there is a subtle difference between the ground truth (your actual measurements) and how the augmented examples relate to the labels you have assigned. However, this distinction is not usually a problem.

Ground truth can be wrong. It is a measurement, and there can be errors in it. In some ML scenarios it can also be a subjective measurement where it is difficult define an underlying objective truth - e.g.  expert opinion or analysis, which you are hoping to automate. Any ML model you train will be limited by the quality of the ground truth used to train and test it, and that is part of the explanation on the Wikipedia quote. It is also why published articles about ML should include full descriptions of how the data was collected.


Computing a cumulative distribution function in Python

If I understand you correctly, these can be found in scipy.stats. scipy has a long list of different distributions that you can use, both continuous as well as multivariate and discrete. All distribution functions have an underlying cdf method which allows you to calculate the cumulative distribution functions of that specific distribution. Using the Chi-squared distribution from your example would look as follows:
from scipy.stats import chi2

chi2.cdf(x=30, df=50)
# 0.011164780271550276

Using other distributions is as simple as importing that distribution and using the cdf method as shown above.


Why does least squares linear regression perform so bad when switching from 2D to 3D line?

The matrix $X^TX$ in your example is close to a singular:

from numpy.linalg import inv, det

print(det(X.T @ X))

1.479949989718308e-06

which makes its inverse very large

inv(X.T @ X)

[[ 4.83118746e+11  2.66548273e+11 -1.83251938e+11]
 [ 2.66548273e+11  1.47061116e+11 -1.01104517e+11]
 [-1.83251938e+11 -1.01104517e+11  6.95093558e+10]]

This is the reason of the error in your question. The following expression

inv(X.T @ X) @ X.T @ X

should produce an identity matrix. But in your example it is

[[ 1.2265625   1.10289171  4.8378709 ]
 [ 0.02282715  0.61713325  0.95782902]
 [-0.01519775  0.25675456  0.33339437]]

So, when you multiply this matrix by beta the result is far from beta.

Another way to look at this singularity is that your 3D problem is not actually 3D. It is still 2D. That's why you have a line, not a 2D surface in your plot. It can be converted to a 2D representation by a transformation of coordinates. If you make a matrix for a proper 3D problem, say

np.random.seed(3)
X = np.hstack((np.ones((100,1)),np.random.rand(100,2)*100))

then inv(X.T @ X) @ X.T @ X gives the correct result:

[[ 1.00000000e+00 -1.24233956e-13 -6.21724894e-14]
 [-1.90819582e-17  1.00000000e+00  6.38378239e-16]
 [-8.67361738e-18  9.28077060e-16  1.00000000e+00]]

and the formula $\beta=(X^TX)^{-1}X^Ty$ works well.


As far as the paper "Sample-Level deep convolutional neural networks for music auto-tagging using raw waveforms", I can give you some of my intuitions about the question since I and my colleague proceeded the experiments.

To summarize, I suggest you to use spectrogram based approaches in your situations.

There are two reasons I would like to point out,

First, training raw waveform based architecture takes about 4 times longer than spectrogram based model when the sampling rate is ranging from 16kHz to 22kHz. In your case, sampling rate is even 22Mhz. I think it will take a lot more time than spectrogram based model with similar performances.

Second, to obtain well trained raw waveform based model, we need more than 50 hours audio since the model has more parameters and deeper layers. In my opinion, the benefit of using a raw waveform-based model is not the performance improvement, but on the generative model. If we use well performing raw waveform based model, we would not need to reconstruct audio signal from spectrogram when the case is generative model. This is the main reason why we performed reported experiments.

If computing power and memory improve with current trends, we expect that the raw waveform-based model will be the mainstream in the near future. But now I think the spectrogram-based model is more convenient, especially for industrial applications.


Preparing dataframe to carry k-means clustering

No, it does not make sense to encore the data this way.

You use Euclidean distance.

You need to encode the variables in a way that Euclidean distance computes a similarity that is useful for your problem. It strictly is not enough to encode stuff somehow as numbers! Garbage in, garbage out is what you get this way.


Is the neural network in DQN used to learn like a supervised model?

Yes.

In DQN, the neural network is used as a function approximator to learn the action value function $Q(s,a)$ - the neural network approximation to it is sometimes noted $\hat{q}(s,a,\theta)$ to show that this is an ongoing, approximate estimate, and that the values that it outputs depend on the NN's learnable parameters (weights and biases).

Why is this "supervised learning"? That is because in order to improve an estimate for Q, the network is presented with labelled data. In DQN this is specifically a mini-batch drawn from experience replay memory, but in all cases in RL, the format of each row of data is the same: A representation of the current state (or state+action sometimes), and a "ground truth" target value to learn to associate with that input. This learning by correct example is exactly supervised learning.

Now, there are some complications:

The "ground truth" is built by the RL algorithm on-demand, and equals the underlying real value $q_{\pi}(s,a)$ only in expectation over time. However, that is fine for any statistics-based learning algorithm that will learn a mean value.
The expected "ground truth" changes over time as RL improves the policy, so higher Q values will be expected, and the old lower ones need to be forgotten. This is why RL algorithms build the "ground truth" on demand - for single-step Q-learning, as used in basic DQN that is the $r + \gamma \text{max}_{a'}\hat{q}(s', a')$ formula that you may see in explanations, and is called the TD Target. That means that RL algorithms prefer to work with online algorithms that are biased towards most-recent data and forget older data. Neural networks and linear regression trained by gradient descent both fit this requirement.

An aside: In RL, to avoid using the term model twice, the term "function approximator" is used, where supervised learning might call the same thing a "model". That is because RL already uses the term model to refer to models of the environment (e.g. the rules of a game, or all the known transition probabilities and rewards).


Since you accepted another answer, which says this can't be done, I am editing this to include an example of it being done.  Hope this helps!

Original Answer:

The most logical way to transform hour is into two variables that swing back and forth out of sink. Imagine the position of the end of the hour hand of a 24-hour clock. The x position swings back and forth out of sink with the y position. For a 24-hour clock you can accomplish this with x=sin(2pi*hour/24),y=cos(2pi*hour/24).

You need both variables or the proper movement through time is lost.  This is due to the fact that the derivative of either sin or cos changes in time where as the (x,y) position varies smoothly as it travels around the unit circle.

This method works really well for clustering and for keeping the distance between 15 minutes after midnight and 5 minutes before midnight "close" in Euclidean space.  All of the modulo suggestions don't accomplish this and the cyclic representation that they do accomplish is pretty clumsy.

Finally, consider whether it is worthwhile to add a third feature to trace linear time, which can be constructed by hours (or minutes or seconds) from the start of the first record or a Unix time stamp or something similar.  These three features then provide proxies for both the cyclic and linear progression of time e.g. you can pull out cyclic phenomenon like sleep cycles in people's movement and also linear growth like population vs. time.

Hope this helps!

Example of if being accomplished:

# Enable inline plotting
%matplotlib inline

#Import everything I need...

import numpy as np
import matplotlib as mp

import matplotlib.pyplot as plt
import pandas as pd

# Grab some random times from here: https://www.random.org/clock-times/
# put them into a csv.
from pandas import DataFrame, read_csv
df = read_csv('/Users/angus/Machine_Learning/ipython_notebooks/times.csv',delimiter=':')
df['hourfloat']=df.hour+df.minute/60.0
df['x']=np.sin(2.*np.pi*df.hourfloat/24.)
df['y']=np.cos(2.*np.pi*df.hourfloat/24.)

df

def kmeansshow(k,X):

    from sklearn import cluster
    from matplotlib import pyplot
    import numpy as np

    kmeans = cluster.KMeans(n_clusters=k)
    kmeans.fit(X)

    labels = kmeans.labels_
    centroids = kmeans.cluster_centers_
    #print centroids

    for i in range(k):
        # select only data observations with cluster label == i
        ds = X[np.where(labels==i)]
        # plot the data observations
        pyplot.plot(ds[:,0],ds[:,1],'o')
        # plot the centroids
        lines = pyplot.plot(centroids[i,0],centroids[i,1],'kx')
        # make the centroid x's bigger
        pyplot.setp(lines,ms=15.0)
        pyplot.setp(lines,mew=2.0)
    pyplot.show()
    return centroids

Now lets try it out:

kmeansshow(6,df[['x', 'y']].values)

You can just barely see that there are some after midnight times included with the before midnight green cluster.  Now lets reduce the number of clusters and show that before and after midnight can be connected in a single cluster in more detail:

kmeansshow(3,df[['x', 'y']].values)

See how the blue cluster contains times that are from before and after midnight that are clustered together in the same cluster...

QED!


How to group every data point with HDBSCAN to some group to have no noise?

DBSCAN will always mark noisy points according to epsilon and min_samples parameters, so there is no way to avoid that unless you have very compact and "well defined" clusters, what seems unlikely.The short answers will be to use another clustering algorithm such as gaussian mixture, k-means, or Birch
If your problem really needs you to use DBSCAN, you can try performing a quantile tranformation (uniform) prior clustering
Example:
scaler = Pipeline([("imputer", SimpleImputer(strategy= "constant", fill_value= 0)),("transformer", QuantileTransformer(output_distribution = "uniform"))])

model = Pipeline([("scaler", scaler), ("cluster",HDBSCAN(min_cluster_size=10, min_samples=1))]).fit(data)


What is parts of speech technique in sentiment analysis?

Parts of Speech (POS)

This is what it is called when you label each of the words (often called tokens) of a sentence or many sentences. Usually they are labelled with grammatical descriptions, such as Noun, Adjective, Adverb. They can often get quite specific, also distinguishing e.g. between types of nouns (proper nouns etc).

You can then use these descriptions of the tokens as input to a model or to filter the tokens to extract only the parts you are interested in.

POS are usually parts of the output when we parse a block of text using an NLP toolkit, such as spaCy. Have a look here for their available POS.

Here is a snippet of  parse tree of the sentence: Apple is looking at buying a UK startup for $1 billion.

Apple has been recognised as a proper noun (NNP) as well as being the subject of the first verb (shown by the arrow labelled nsubj).

For a nice introduction to POS among many other terms within NLP, check out this article..

Sentiment Analysis Perspective

There are many many reasons to include POS in a sentiment model (some examples below), but they really all boil down to one overarching reason: polysemy. The definition of which is:

  the coexistence of many possible meanings for a word or phrase.

So essentially saying, that words in different contexts can have different meanings. This is of course a massive gain in information that we can pass to a model!

The word duck can be a noun (the bird) or a verb (the motion, to crouch down). If we can tell a model which one of these it is in a given sentence, the model can learn to make a lot more sense out of the sentence.

Beyond distinguishing between meanings of single words, we can also simply uses them on their usage, or placement. One example use would be to use the adverb: however.

If our parser is good enough to tell us that it used in a particular sentence as a contrasting conjunction (which technically, would be grammatically incorrect!). An example sentence could be:

  I really love muffins, however, I hate strawberries.

We have two clauses: a positive one before however and one after. The first clause is positive, the latter negative. If we have a scale of -5 ro +5 for sentiment for each clause (perhaps the mean of each word in that clause) we could imagine scores such as +3 for the positive clause and -3 for the negative.

This is where I have seen some models (Vader, SentiStrength, etc.) using POS to scale those base scores. In our example, perhaps however would be used to increase the magnitude of the negative clause's score by 10%, giving it a final score of -3.3. Whether or not that makes sense depends on the use case, the data and probably the developers general experiences.

Summary

There are many uses for POS, you can imagine quite a few, whether to hand-tailor a sentiment model of just to produce more features. In any case, it is a process that extracts more information from the original raw text, applying langage models (like grammar!) that have been tested and are known to be robust for any official form of writing.


How to encode a job description for machine learning

I would first start by using something like scikit-learn LabelEncoder. Examples are in the documentation.

EDITED : With this option, you convert every string to a integer starting from 1.

You can also think about trying to convert the strings into hash values.


In the context of image binary classification, is it necessary to divide dataset into true positive, false positive, true negative, false negative?

No it's not. The numbers of true positives, false positives, true negatives, false negatives, are something you can check from a confusion matrix when you evaluate the performance of your trained model on a test set. It's useful to know where your model is making more mistakes.

It's not something you can do before training.


GAN discriminator converging to one output

What you are experiencing is called mode collapse, which can occur in GAN Training and is one of its "training instability problems". If you are using Vanilla GAN one effective way is to implement mini batch discrimination, which for my understanding does give the discriminator batches of real and fakes and it has to decide batchwise if its fake or real. So if it encounters the same or nearly same image often it is easy for him to say it's fake.
Other GAN Architecture like WGAN, and BEGAN state that they don't suffer from mode collapse which would be another alternative.

You can also try to expand the GAN to an AC-GAN, which produces classwise samples (0-9) but in AC-GAN it's also possible to suffer from classwise mode collapse.

Here is a pull request for keras implementing minibatch discrimination : https://github.com/keras-team/keras/pull/3677


Why I get AttributeError: 'float' object has no attribute '3f'?

Try this instead,

  print(
"{:.3f}% {} ({} sentences)".format(pcent, gender, nsents)
)

Refer the latest docs for more examples and check the Py version!


How to represent a user who hasn't churned in training data

In your setup, the only way is probably to set it to some large number, say 365. However, this will force you to discard all dates that are less than 365 days old, because you can't be certain a customer won't churn before he reaches 365 days (which is still in the future).

A better and more common way is to look at churn on a rolling window basis, e.g. will the customer churn within the next 30 days. This turns your problem into a classification problem. That way you only need to discard the most recent 30 days of data.


Should I eliminate all ID columns and similar columns from training data?

It depends.

If your data samples are IID (independent and identically distributed) then you can remove the sample ID, given that all samples come from or refer to the same source/object and they don't somehow identify the sample class.

But, if your data is sequential, such as time series, it would be a big mistake to neglect the ID, as it identifies the time order between the samples. The time dependencies are a great source of information for problems such as time series forecasting, regression and classification. If you treat sequential data (time series) as IID (by removing the ID), you will have inferior performance, because you neglect one source of information, i.e. temporal dependencies. You should not include the ID as input to your model, but you should respect the order of the samples, which is shown by the ID.


"What approach should I use to match rows in my data frame to each other based on columns and then manipulate them."
Use pandas.DataFrame.loc:

Setting values
Set value for all items matching the list of labels

df.loc[['viper', 'sidewinder'], ['shield']] = 50
df
            max_speed  shield
cobra               1       2
viper               4      50
sidewinder          7      50

Set value for rows matching callable condition

df.loc[df['shield'] > 35] = 0
df
            max_speed  shield
cobra              30      10
viper               0       0
sidewinder          0       0


If you want to become a data analyst then R is the best language for you. It is purely made for statistical analysis. It is a free software, so you can install it in your system without any hassle. You can find about it here-

https://www.r-project.org/about.html

It has nearly 10,000 packages which you can use as per your requirement. You can find many free tutorials for it as well.


You could put a one-class classification model before your CNN.

This would mean that you treat both your classes as one and then frame it as an anomaly detection problem. There are some different ways of achieving this. One way could be to do dimensionality reduction on the images and then use that image encoding to train an outlier detector like an one-class SVM. You can get some ideas here:

Learning Deep Features for One-ClassClassification

Anomaly Detection using One-Class Neural Networks

You can also look at cbeleites answer to this related questions. This was actually where I learned about one-class classification on images and it goes into a bit more detail and explains some caveats with using it.


If you are hoping to process the text of the comments this is definitely possible. Just NLP training and a single output score.

But this might be more machinery than you're looking for? If you have more data on the comments this will be do-able without a neural net.


I guess what you meant by correlation between SHAP values is "SHAP Interaction Value".

SHAP value is a measure how feature values are contributing a target variable in observation level. Likewise SHAP interaction value considers target values while correlation between features (Pearson, Spearman etc) does not involve target values therefore they might have different magnitudes and directions.

The features may grow together but their contribution to target variable in different intervals may reverse.

You may want to check docs and this beautiful work.


Why are variables of train and test data defined using the capital letter (in Python)?

The X (and sometimes Y) variables are matrices.

In some math notation, it is common practice to write vector variable names as lower case and matrix variable names as upper case. Often these are in bold or have other annotation, but that does not translate well to code. Either way, I believe that the practice has transferred from this notation.

You may also notice in code, when the target variable is a single column of values, it is written y, so you have X, y

Of course, this has no special semantic meaning in Python and you are free to ignore the convention. However, because it has become a convention, it may be worth maintaining if you share your code.


How exactly dependent variable is expressed in terms of independent variables using Partial Least Square Regression Method?

This lecture helped me get my head around PCA: https://www.youtube.com/watch?v=a9jdQGybYmE

The analogy that I am sharing with you comes directly from this lecture:

Imagine that you have a weight that is on a spring. It can bounce up and down and thus is a one degree of freedom system. Imagine that you have three sensors which record the (x,y) position of the weight as it bounces up and down. Now you have six vectors of data (a set of x,y from each camera). PCA tries to infer the actual (x,y) coordinates of the weight as it bounces based only on the data that you get from the cameras.

This analogy is very rough and I highly recommend that you watch the linked video. There is really no short answer to your question!


How to start learning Python for Machine Learning without spending money?

There is plenty of material on the internet in the form of blog posts. This, together with the philosophy of learning by doing, leads me to the following advice: google "python XXX tutorial" where XXX stands for a basic machine learning algorithm and, for a few of the first results, use Google Colab to mimic what the tutorial explains.

Whatever you don't understand, you look up in google (e.g. what is Google Colab, loops in python, python named arguments, etc).

The main python libraries used in ML probably are scikit-learn and pandas. The online documentation of these and any other library used in the tutorials will probably be very useful to understand what each piece of code does.

Some ML algorithms you may want to explore are:

Linear regression
Logistic regression
k-nearest neighbors
k-means

When going through the tutorials, you will probably find many important transversal concepts, e.g. difference between classification, regression and clustering, data split in train/validation/test sets, performance measures like accuracy, the ROC curve, the area under it; look up in google any term you don't understand, the first results or their wikipedia pages will probably give you a basic understanding of them.


Packages for unit testing and assertive testing that are actively maintained:
Packages for unit testing

testthat: more information on how to use you can find here or on github
Runit: Cran page

Packages for assertions:

assertthat: info on github
assertive: Assertive has a lot of subpackages available in case you do not need all of them. check on cran
assertr: info on github
ensurer: info on github
tester: info on github

It is a matter of preference what you want to use for assertions.
Read this bioconductor page for more info on the difference between RUnit and testthat.


Best ML approach for huge number of classes

Given data will keep increasing in the future along with the classes. You need to look at fast methods of doing things. Look at approximate KNN to do classification in high-volume data. Approximate KNN will solve your problem. Here's the library for it. Your accuracy will suffer a bit but this method would scale.


On Kaggle.com, there is a datasets section. In this section, you can post or find datasets. For each dataset, you have the data, possibility to discuss about it and, of course, a list of kernels posts by the user. For instance, for the iris dataset, you have 592 kernels available.


I'm writing an example code in python:

import sklearn
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split

X, y = whatever your data (X are the input variables, y are the output)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)

lr = LinearRegression().fit(X_train, y_train)

print("Training set accuracy: {:.2f}".format(lr.score(X_train, y_train))
print("Test set accuracy: {:.2f}".format(lr.score(X_test, y_test))

Imported necessary packages.
Defined your input (X) and output data (y).
Shuffled the data into the training set (75%) and the test set (25%).
Defined the linear regression model and fitted the training data.
Printed training and test set accuracies.

Hope that helps!


How multi-head attention mechanism in Transformers is able to attend to information from different representation subspaces at different positions

I think, what you are looking for is $d_k = d_v = d_{model}/h$ [1] where $h$ number of heads and $d_{model}$ dimensions of keys, values and queries for single attention version of the model. In relation of the model architecture and its embedding specifically, the above translates to
$Query Size = Embedding Size / h$
Model input
According to the above, at the input embedding layer weights for each head are stacked together in the single embedding matrix. Stacking together, hmm.. (stacking, ensembling).

Per head scores
As in the normal self-attention, attention score is computed per head but given the above, these operations also take in place as a single matrix operation and not in a loop. The scaled dot product along with other calculations take place here.
Multi head merge
As a final step, the attention score of each head is merged by simply reshaping the full  attention score matrix so that the per-head attention scores are concatenated into a single attention score.

Summing it up
With a clearer view of what the architecture of the model is and how its computational graphs looks like, we can go back to your original questions and say:
The multi-headed model can capture richer interpretations because the embedding vectors for the input gets "segmented" across multiple heads and therefore different sections of the embedding can attend different per-head subspaces that link back to each word.
In a more general sense, one can argue that running through the scaled dot-product attention multiple times in parallel and concatenating is a form of ensembling.

I hope it helps. For more details about the several operation taking place in the transformer architecture, I suggest you have a look at this post from which my answer is heavily influenced from:
https://towardsdatascience.com/transformers-explained-visually-part-3-multi-head-attention-deep-dive-1c1ff1024853
[1] 3.2.2 https://arxiv.org/pdf/1706.03762.pdf


Softmax output in neural networks can be misleading - often the confidence provided is higher than is intuitive.  See e.g. here:

A Baseline for Detecting Misclassified and
Out-of-Distribution Examples in Neural Networks
https://pdfs.semanticscholar.org/c26e/1beaeaa55acae7336882de5df48716afb8bb.pdf

which suggests that in practice, softmax is not helpfully interpretable as a probability but should instead be used for ranking among class options.

If you want to have an accurate probability estimate, you might consider using a Bayesian approach in which you explicitly model your estimate of each of the input variances, the output variance, etc.

Failing that, having a second phase neural network that takes the input and predict correct or incorrect classification by the first network is an interesting idea - where incorrect classification is a proxy for 'low confidence' classification.  If you try it I'd be curious to know how it works.

Edit: As @Emre said the input to the softmax would be more informative than the softmax itself because it's pre-scaled (i.e. not forced to sum to 1). So it should reflect confidence better, with values further away from 0 indicating higher confidence.


Using GridSearchCV and a Random Forest Regressor with the same parameters gives different results

RandomForest has randomness in the algorithm. First, when it bootstrap samples the data for each tree. Second, when it chooses random subsamples of features for each split.

To reproduce results across runs you should set the random_state parameter. For example:

estimator = RandomForestRegressor(random_state=420)


Bad classification performance of logistic regression on imbalanced data in testing as compared to training

I suspect the reason is that the class balance in your test set is different from the class balance in your training set.  That will throw everything off.  The fundamental assumption made by statistical machine learning methods (including logistic regression) is that the distribution of data in the test set matches the distribution of data in the training set.  SMOTE can throw that off.

It sounds like you have used SMOTE to augment the training set by adding additional synthetic positive instances (i.e., oversampling the minority class) -- but you haven't added any negative instances.  So, the class balance in the training set might have shifted from 0.5%/99.5% to something like (say) 10%/90%, while the class balance in the test set remains 0.5%/99.5%.  That's bad; it will cause the classifier to over-predict positive instances.  For some classifiers, it's not a major problem, but I expect that logistic regression might be more sensitive to this mismatch between training distribution and test distribution.

Here are two candidate solutions for the problem that you can try:

Stop using SMOTE.  Ensure the training set has the same distribution as the test set.  SMOTE might actually be unnecessary in your situation.
Continue to augment the training set using SMOTE as you're currently doing, and compensate for the train/test mismatch by shifting the threshold for classification.  Logistic regression produces an estimated probability that a particular instance is from the positive class.  Typically, you then compare that probability to the threshold 0.5 and use that to classify it as positive or negative.  You can adjust the threshold to correct for that: replace $0.5$ with $0.5/k$, where $k$ is the ratio of positives in your training set after augmentation to positive before (e.g., if augmentation shifted the training set from 0.5%/99.5% to 10%/90%, then $k=10/0.5=20$); or you can use cross-validation to find a suitable threshold that maximizes the F1 score (or some other metric).

Incidentally, I recommend you make sure to use regularization with your logistic regression model, and use cross-validation to select the regularization hyper-parameter.  There's nothing wrong with 15K features if you have 120K instances in your training set, but you might want to regularize it strongly (choose a large regularization parameter) to avoid overfitting.

Finally, understand that dealing with severe class imbalance such as you have is just hard.  Fortunately, there are many techniques available.  Do some reading and research (including on Stats.SE) and you should be able to find other methods you could try, if these don't work well enough.


How can we get gradient with some other loss function apart from MSE?

Yes we have. MSE loss function is usually used for regression problems. We can have different loss functions according to our needs. Follow the article below.
https://towardsdatascience.com/common-loss-functions-in-machine-learning-46af0ffc4d23
If you wish to learn as to what does gradient does in the algorithm   you can visit this article:
https://towardsdatascience.com/wondering-why-do-you-subtract-gradient-in-a-gradient-descent-algorithm-9b5aabdf8150


Classify samples based on other sample probabilities

This is a case of multilabel/multioutput classification.  You have a corpus of data in which several classes can be true for a single sample.  Moreover - where one class is literally a mixture of the other two classes.  A much more common problem than a lot of us would wish it to be.

Note: I'll rename classes 1, 2 and three into classes 0, 1 and 2 respectively; since that is how sklearn enumerates them.

The sklearn's RandomForest supports multilabel classification out of the box, therefore instead of organizing your data as follows:

X                   | y
feature1  feature2  | label
--------------------+------
0.1       0.3       | 0
0.2       0.1       | 1
0.7       0.5       | 1
0.8       0.3       | 1
0.6       0.6       | 1 (but also 0 - so probably should be 0 and 1 - class 2?)
0.3       0.9       | 0
0.5       0.5       | 0 (but also 1 - so probably should be both as well- class 2?)

Organize the data in the following way:

X                   | Y
feature1  feature2  | class0?  class1?
--------------------+-----------------
0.1       0.3       | 1        0
0.2       0.1       | 0        1
0.7       0.5       | 0        1
0.8       0.3       | 0        1
0.6       0.6       | 1        1
0.3       0.9       | 1        0
0.5       0.5       | 1        1

In other words, make your label vector into a matrix - i.e. both $X$ and $Y$ will have two dimensions now.  sklearn's RandomForest will accept that inside it's fit() and inside it's predict() methods (and inside predict_proba() as well).

The only tricky bit may be the interpretation of the output of predict_proba() in multilabel/multioutput classification, for example (watch for typos, I'm doing this code from memory):

import numpy as np
from sklearn.ensemble import RandomForestClassifier

X = np.random.random((3, 3))
Y = np.array([[0, 1],
              [1, 0],
              [1, 1]])
model = RandomForestClassifier()
model.fit(X, Y)
model.predict(X)

    np.array([[0., 1.],
              [1., 0.],
              [1., 1.]])

model.predict_proba(X)

    [np.array([[0.6, 0.4],
               [0.7, 0.3],
               [0.1, 0.9]]),
     np.array([[0.9, 0.1],
               [1.,  0. ],
               [0.2, 0.8]])]

In summary, predict_proba did return a list of two elements: the first element is the probability of class 0 independently of class 1, whilst the second element in the list is the probability of class 1 independently of class 0.  Whether the is a high probability of class 0 and a high probability of class 1 then you have a prediction of [1, 1].


Iterate over multiple dataframe rows at the same time

First: I think you want the product functionality, not zip, since you are checking every df with every ref. In zip, you would check df_a with ref_1 and df_b with ref_2 only.

Second: Your can look at the equation $(1+2+3+4)−(5+5+5+5)$ as $(1-5) + (2-5) + ...$ which is simply subtracting data frames and sum over columns.

With these two consideration, assuming you have defined your objects as follows:

df_a = {
    'name': 'df_a',
    'value': pd.DataFrame([[1, 2, 3, 4], [2, 4, 6, 8]])
}
df_b = {
    'name': 'df_b',
    'value': pd.DataFrame([[10, 5, 2, 1], [4, 4, 6, 2]])
}

ref_1 = {
    'name': 'ref_1',
    'value': pd.DataFrame([[5, 5, 5, 5], [5, 5, 5, 5]])
}
ref_2 = {
    'name': 'ref_b',
    'value': pd.DataFrame([[3, 3, 3, 3], [3, 3, 3, 3]])
}

I did this because I want to use the names in creating the name of the columns of your final df. Then your code would be:

from itertools import product

final_result = pd.DataFrame(
    {
        '{}_{}'.format(df['name'], ref['name']): (df['value']-ref['value']).sum(axis=1)
        for (df, ref) in product([df_a, df_b], [ref_1, ref_2])
    }
)

I have used dictionary comprehension to skip the ugly loop/append solution.
product function from itertools does your iteration. product on (ab, cd) gives you ac, ad, bc, bd
as for keys, df names are joined together with _, and as for values, I have subtracted two dfs and sum over columns (axis=1)

The result would then be as you expect:

   df_a_ref_1  df_a_ref_b  df_b_ref_1  df_b_ref_b
0         -10          -2          -2           6
1           0           8          -4           4

Still if you want to expand the dictionary comprehension or do not want to define dictionaries of names/values, of course you can imagine how you can write simple for loops with the same logic:

for (df, ref) in product([df_a, df_b], [ref_1, ref_2]):
    # your desired columns
    col = (df - ref).sum(axis=1)


Looks like that number is calculated from the total_cases column. Value = "total_cases from day before" - "total_cases of that day". In this case: -209 is 130 - 339. Not sure why that number would decrease, but could be they changed the way they count, or just an error in the data.


Determining number of clusters in high dimensions

There isn't a correct way to approach this problem. One common way is what you are doing, i.e.  check for various values of $k$ and have a heuristic tell me the best value. Some such methods are are the elbow, silhouette and the gap statistic that you're using. Determining the number of clusters via such a method is perfectly valid; in fact that's what they're for.

Another approach would be to try hierarchical clustering on the data and see which level leads to the maximum difference in variance.


Given the files and their parsed content how can I reverse engineer the file format?

I have had to perform that type of operation on so-called .DAT files. You need a  good hexadecimal editor, that allows you to display char, binary and hex contents from binary, and some patience. And probably a digit-probe friend you can talk with, to help decipher the riddle.

Seek global headers and local ones, file ID, dates and try to locate numbers or ascii code from your database. With that, you can infer field storage length with a relative ease, as least as long they are not exotic, like multiple of 4 bits. Sometimes, there are dummy bits to fill blanks. If the file is somehow compacted (one chunk on 3 bits, the next on 17 bits), it can become quite complicated. Imagine you are a private investigator,  challenge a geek friend. Performing such a task with another person can make it funnier.

I used HxD and HexEd.It.


Why do we need the hyperparameters beta and alpha in LDA?

LDA is a bayesian model. The equation that you gave is the posterior distribution of the model. The alpha and beta parameters come from the fact that the dirichlet distribution, (a generalization of the beta distribution) takes these as parameters in the prior distribution. So to answer your first question, will the formula above work without the alpha and gamma, yes, you would implicitly be assuming these parameters from the prior distribution are both equal to zero. You will still get a result, but the prior you are using might be problematic on a conceptual level (maybe it would cause some numerical problems too, I'm not sure?)

To answer question 2, I want to point out that in LDA we use the conjugate prior to simplify the calculation of the optimal parameter values. That is what you are seeing in the above equation. What you are seeing is the posterior value is proportional to the left hand side. Adding the "c" terms allows you to calculate the posterior.


How to handle non-stationary data in online neural network based one-class classifier for anomaly detection?

Usually, non-stationary series can be dealt by differencing the time series once or twice. You can add verification to your tool - checking auto-correlation plot (or partial correlation plot).


Install the latest Keras version: https://github.com/keras-team/keras/issues/7736#issuecomment-324989522


Python: multiplication of sparse matrices slower in csr_matrix than numpy

Here, you do not time only the time taken to make the matrix multiplication but also the time taken to convert your matrix from dense to sparse. If you convert your matrix before the timing starts, you will see that multiplication with scipy is indeed more than twice faster

import time, numpy, scipy
from scipy.sparse import csr_matrix
import numpy as np

W = np.random.binomial(n=1, p=0.01, size=(100, 100))
start=time.time()
numpy.matmul(W,numpy.transpose(W))
end=time.time()
dt_dense = end - start
print ('time taken for the dense matrix {}'.format(end - start))

sparse_W = csr_matrix(W)
start=time.time()
sparse_W.dot(sparse_W.transpose())
end=time.time()
dt_sparse = end - start
print ('time taken for the sparse matrix {}'.format(end - start))
dt_dense/dt_sparse


Is the following a good method for determining learning rate in a neural network?

Starting with a high value is not a good idea. Since we are not aware of where the training starts on the Loss surface, so it can easily diverge.
Also, in between we need a higher LR to quickly move on saddle points (plateaus).
 Both start and end should be at a small value
A well-known approach is called Cyclical-Learning-Rate suggested by Leslie N. Smith in this paper Link
It suggests following a Cyclic path e.g. Triangle, Sinusoidal, etc.
It says to first increase from a minimum bound and starts decreasing when reached a maximum bound.
$\hspace{3cm}$
Paper has clearly explained -
- How to find the bounds
- How to decide the stepsize


Is there any model in machine learning that does not have parameters?

Yes. k-nearest neighbors  is parameterless (there is only a single hyper-parameter $k$).

  If such parameterless models exist, what are their purpose then? Isn't it the whole point of training to tune a model's parameters?

Exactly: such models require no training at all. k-NN in particular relies on knowing the data set upon prediction. Anything close to "training" this model would be pushing data points to a set, but these do not count as parameters.


Siamese networks vs Semantic similarity (may be gensim)

Siamese and semantic similarity are not same.
See example here:
Siamese are effectively used for image classifications , but there is a paper publication by Cornell university for text classification as well.
Now for your question, we train siamese in a way such that one is positive and one is negative.
Lets talk about job title called java developer , we train it with java developer as input and j2ee developer as output in one network. In another network we train java developer as input and QA engineer as output but we dont change weights of the network.

Since we train a neural network with positive and negative so that siamese networks learns the positives and hence its also called one shot learning etc..

Now coming back to semantic similarity- its a unsupervised learning wherein the network will place similar objects together, the cosine distance that we get from gensim is how close one object to the other.


training accuracy greater than validation accuracy

Your model is clearly overfitting. You should use higher dropout value like 0.5 .For better generalization use deep models. And you can also use early stopping so that your model stops training before significantly overfitting.


I would definitely use a graph (Though, this clearly depends on the final application, maybe you could add more information)

For the nodes, you should consider as nodes not only tanks but also points were pipelines change name or bifurcate. For instance, following your example:

    e1     e2        e3          e4        e5          e7
    +---+----------.---------+----------.----------+-----------
    |          |         |                     |          |
[R tank 1]  [S tank 1] [S tank 2]              |e6     [S tank 3]
                                               |
                                           [S tank 4]

Now adding the nodes:

    e1 n2  e2     n4   e3   n6   e4    n8  e5     n9   e7
n1 +---+----------.---------+----------.----------+----------+
   |          |         |                     |              |
  n3         n5        n7                     |e6           n11
                                              |
                                             n10

Lastly, you need some kind of mapping.
Some of the nodes will map to tanks:

[R tank 1]     n3
[S tank 1]     n5
[S tank 2]     n7
[S tank 4]     n10
[S tank 3]     n11

And the pipelines will be represented by paths in the graph

Pipeline 1     e1 e2
Pipeline 2     e3 e4
Pipeline 3     e5 e7
Pipeline 4     e6


How to deal with missing continuous data

Where ever you don't have an entry just make that to a null value or a random unique value. an then create another column, make that column data equal to 1 if data is present 0 otherwise so, the model may learn about that unique imputation and data using another column we are adding.


Tool for clustering and cleansing data set

What do you mean to cluster data around a column? You can use standard clustering models, such as k-Means clustering or Gaussian Mixture Models for an exploratory analysis of your dataset. However, I'm not sure this is what you're looking for, please let me know.
I often study a new dataset by employing some dimensionality reduction technique. The most common is PCA, but I don't recommend it since it can extract only latent factors that are linearly associated with your variables. You can use t-SNE models (available in sklearn), or, if you are familiar with Deep Learning, with Autoencoders for dimensionality reduction. Once your dataset is compressed/reduced, you can observe how different values-factors are distributed on it.
Dimensionality reduction is also very important in case your dataset suffers from high multicollinearity.
You can remove duplicates using pandas' drop_duplicates() function, explained here.

Hope this helps, otherwise let me know.


From the seaborn documentation:

  scale : {“area”, “count”, “width”}, optional

  The method used to scale the width of each violin. If area, each violin will have the same area. If count, the width of the violins will be scaled by the number of observations in that bin. If width, each violin will have the same width.

So the violins are scaled such that the width is proportional to the number of observations. You were expecting the area to be scaled with count, not the width, and that seems natural to me but that option does not seem to exist in seaborn. Here is an issue regarding this, with a handmade solution:

https://github.com/mwaskom/seaborn/issues/962


Q-Learning experience replay: how to feed the neural network?

Input is a 4D tensor [batch_size, height, width, channels] . Single state is already 4 frames stacked together so when you sample a state from the experience replay you sample a 3D tensor [height, width, channels]. When you sample 32 states you actually sample 32 of those 3D tensors and feed them directly to the network. For more details on preprocessing refer to the page 6 of the original DQN paper found here.


What is the meaning of colors in activation maps?

In heat maps, generally reddish regions represents higher values where as bluish ones represent lower.


Different training method for encoder-decoder model

One is a straight forward use of API while the other one gives you much better control on training. If you are experimenting, it is good to go with a custom training loop so you can control the various things that happen to your model's training.
But, if you want to just train a model and not experiment with it much, save time and go for the straight forward method of training.
Both are same but one gives you much more control.


Visualize/analyze data before or after imputing missing values?

Why not do both? Like you mention, it might be worth first computing the percentage of all values that are values. Generally you might also have a percentage in mind that is acceptable, like up to 10% missing values, if they are scattered at random throughout your dataset.

There are libraries built specifically for visualising missing data, such as missingno, which offers quite a few ideas. Here is an example heatmap of missing variables across features:

"missing" normally implies you have a sequential dataset, for example time-series data. If you had discrete observations e.g. of people's height versus shoe size, there is no sequential causality (autocorrelation: dependency on previous values). In this case, imputing makes little sense.

So assuming you do have sequential data, whether or not to impute or drop time steps with missing values will really depend on your use case. Also perhaps the frequency of the data. If all the missing vaiues appear in one chunk at either end of the time series, it is cokmmon to simply leave out that chunk.

For example, if you have minute frequency data and you wish to predict a value once per day, then missing a few minutes here and there might be tolerable, and imputation of some kind (e.g. fill-forwad) wouldn't have a huge impact overall, but could help the model optimisation work more effectively. Some models cannot handle missing values, so imputation is necessary.

In any case, it would always visualise the data before and after imputation. You can usually run the same visualisation anyway. Sure it costs a few extra minutes, but you might catch important issues. This can save a lot of time compared to only finding the issues later on while debugging your trained model.


How to compare experiments run over different infrastructures

This is a very good question and a common situation.

In my opinion there are three different factors that must be controlled:

Data: There exist already different benchmarks in order to evaluate algorithms and architectures. These data must be publicly available so that everybody can contrast their approaches.
Architecture: My suggestion is to test everything on the cloud, so that everyone can contrast their results and also there is no doubt the same machines and software is used.
Algorithms: If you have developed a distributed algorithm, it would be great to compare your algorithm on a specific data. In this case, algorithms must not be public.

So, answering your question, if you want to compare different experiments and state to what extent your distributed algorithm outperforms others, you should try to replicate as accurate as possible the same environment (data and architecture) where the experiments were carried out.

If this is not possible, my suggestion is that you test your algorithm with public data and cloud architecture so that you become a referent as you are facilitating the comparison of future algorithms.


Understanding why shuffling reduces weirdly the overfit

There is a crucial assumption made by any supervised ML approach: both the training set and the set are samples drawn from the same population. This means that the model expects to see the same distribution of features in the test set as in the training set.

In order to make sure that this assumption is satisfied, it is important to shuffle the instances before splitting between training set and test set. This will avoid any visible or invisible bias due to the order in which the data was collected or assembled. That's the effect that you can observe in your first experiment: the main issue is not so much about overfitting due to the model relying too much on some parameters, it's that neither the training or test set are a random subsets of the population. It might make complete sense for the model to rely on these 3 parameters based on the training set, the problem is that they don't behave the same way in the test set. "behaving in the same way" includes their relation to other features, so the difference might not be visible by looking at these features independently. This bias (which probably affects more than the 3 features) causes a huge discrepancy when evaluating the model on the test set.


How are weight updates handled in Batch Gradient Descent vs SGD?

What is being stored at each sample, that can be applied at the end of the batch

You store the prediction and error and then calculate the average after each cycle.

GD - Update after all rows. It will give a correct direction to the weight update but will be very slow

SGD - Update after each row. It will be fast but the direction may swing

Batch - Update after a specific count. This approach gives a balanced solution to the two other approaches.


is it reasonable to consider Horse Colic dataset as a binary classification problem?

It depends on your goal.

If you're interested in the horse's status then this is a multiclass classification problem.

Or if you're only concerned if a horse died and not concerned about how it died, then you can treat it as a binary problem (after grouping 'euthanised' with 'died').


Short answer : a model will not be able to predict attribute it has not seen during the training process. From what I understand from your code, each model will erase the previous one.


How to prevent/tell if Decision Tree is overfitting?

Overfitting meaning your model is learning the noise from the data and its ability to generalize the results is very low. In this case you have a small training error but very large validation error. If you inspect (e.g. by plotting) the evolution of training and validation errors, you see that training error is always going down but validation error is goes up at some point. That is the point you need to stop training to avoid overfitting. I strongly recommend you to read this.

So, the 0.98 and 0.95 accuracy that you mentioned could be overfitting and could not! The point is that you also need to check the validation accuracy beside them. If validation accuracy is falling down then you are on overfitting zone!

  What are some best practices in addition to a balanced input to avoid
  overfitting?

It is called Prunning. Beside general ML strategies to avoid overfitting, for decision trees you can follow pruning idea which is described (more theoretically) here and (more practically) here. In SciKit-Learn, you need to take care of parameters like depth of the tree or maximum number of leafs.


How clustering is used in data management?

This is a wide open question, so I am not sure which aspects you are most interested in.  Here are some Wikipedia articles you can get started with.

Metadata Harvesting

Metadata Discovery


Predicting the next occurrence based on binary

Do you have more features ?
If not, you can try to find a filling pattern, for example, probably some places are filled first because, for example, are closer to the entrance, then another group etc.
Try to plot as a time dependent problem. I cannot tell how much bigger the error will be.
If you have at least the x, y of the place and the timestep of the value, then you have a pattern.


Which one first: algorithm benchmarking, feature selection, parameter tuning?

I assume you mean feature selection as feature engineering. The process I usually follow and I see some people do is

Feature engineering
Try a few algorithms, usually highly performant ones such as RandomForest, Gradient Boosted Trees, Neutral Networks, or SVM on the features.

2.1 Do simple parameter tuning such as grid search on a small range of parameters

If the result of step 2 is not satisfactory, go back to step 1 to generate more features, or remove redundant features and keep the best ones, people usually call this feature selection. If running out of ideas for new features, try more algorithms.

If the result is alright or close to what you want, then move to step 3

Extensive parameter tuning

The reason for doing this is that classification is all about feature engineering, and unless you know some incredible powerful classifier such as deep learning customized for a particular problem, such as Computer Vision. Generating good features is the key. Choosing a classifier is important but not crucial. All the classifiers mentioned above are quite comparable in terms of performance, and most of the time, best classifier turns out to be one of them.

Parameter tuning can boost performance, in some cases, quite a lot. But without good features, tuning doesn't help much. Keep in mind, you always have time for parameter tuning. Also, there's no point of tuning parameter extensively then you discover a new feature and redo the whole thing.


XGBoost: # rounds is equal to n_estimators?

For gradient boosting, there really is no concept of a "layer of trees" which I think is where the confusion is happening. Each iteration (round) of boosting fits a single tree to the negative gradient of some loss function (calculated using the predictions from the updated model in all prior iterations), in your case, root mean squared error. The algorithm does not fit an ensemble of trees at each iteration. Each tree is then added (with optimal weighting) to all prior fitted trees + optimal weights in previous iterations to come up with final predictions.

The validation scores you see are, as a result, the score of your complete model up to that iteration of tree fitted. So this line here for instance:

[93]    validation_0-rmse:0.233752      validation_1-rmse:0.373165

is the performance of your model on validation_ 0 and validation_1 for a model that has fit 93 trees on past gradients generated in prior iterations.


Dissimilarity Matrix of non-metric proximity data

Maybe I did not completely understand your question, but I think the answer you are looking for is one of the following:

You may want to fill a n-by-n matrix with 1 if the person $i$ has sent e-mail(s) to person $j$, 0 otherwise
Maybe you want to fill the n-by-n matrix with the number of emails sent from person $i$ to person $j$.

Both measures are distances in the mathematical definition.

For clarity:

You could program the dissimilarity matrix as $M[i,j] = 1$ if the pair of people in your data exists.


Representation of state space, action space and reward system for RL porblem

I would suggest you to use Deep Q or A2C (I personally use A2C). As a terminal state you can consider the state in which every tile has been visited once, except if you want to your agent wonder forever. I create OpenAI gym gridworlds so I can use some of their very useful wrappers (example TimeLimit wrapper in which an episode terminates when a certain number of steps has been reached).

For your state representation I would suggest you to follow  well established practices. I assume that you want to use CNNs as a perceptual module and not MLP. You could either use an image of your gridworld with different colors for every entity or use what we call feature-image layers as inputs. These are simply a volume of images and each image has the same dimensions as your grid map and is everywhere 0 except the location of an entity which will have a value of 1. This is in other words a one-hot encoding but in the spatial dimensions of your map.

Actions seem fine to me and your reward function is worth giving a try but I wouldn't penalize that heavily (maybe -0.1 instead of -0.75). The issue will rise initially when your agent explores. If it is heavily penalized it will try to maintain its reward and deliberately crash.

Do not get frustrated if initially it doesn't learn. Designing a proper reward function is quite a task besides the proper feature representation (I suggest images).


How exactly do I go about extracting features from timestamps for machine learning?

A common approach for time-series classification problems is to divide the continuous stream of data into samples of a certain duration.

This is called sliding window segmentation.

You don't really use timestamps as features because they wouldn't be useful during the classification of unseen data. Imagine training a model with data obtained in 2018, and trying to classify data for 2019. The information is not on the dates but in the values of the other features!


Why ELMo's word embedding can represent the word better than glove?

I am wrong. ELMo also use the output of LSTM for context-dependent representation.

The output only from word embedding is the context-independent representation.

Why the representation is useful?

I think it is because, it is learning the difference between words and the representation is not the real meaning for the word.


Why my results have time delay when I use LSTM?

I've had similar results when working with time series data. My conclusion was that the model does not learn any real pattern, except that the next value is pretty close to the previous one (or a smoothing of previous ones) + some noise.

This can be easily verified, if you feed your model's predictions recursively into the model to further predict the future (multi-step ahead forecasting based on the model's predictions). In the above mentioned case, your predictions will explode exponentially pretty quickly.


How to understand incremental stochastic gradient algorithm and its implementation in logistic regression [updated]?

Gradient Descent

The idea of gradient descent is to traverse a function $f_{LR}(\textbf{w})$ and find a local maximum or minimum for a set a values $\textbf{w}$. Gradient descent is an iterative process. At each iteration you will evaluate the function given your current set of values. Then you will take the derivative of that function with respect to those values to see how much each value contributes to the slope of the function. We can then change the values in a proportionate way to move towards this optimal point.

The gradient descent equation is described as

$\textbf{w}^{(k+1)} = \textbf{w}^{(k)} - \rho \frac{\partial f_{LR}(\textbf{w})}{\partial \textbf{w}^{(k)}}$

where $\rho$ is the learning rate, usually small number. A constant which determines the speed at which we want to change the values we are optimizing.

Initializing the values

There's many ways to initialize these values. We can either set them all to zero, or set them randomly.

Then you can take a random instance in your dataset $x_i$ and $y_i$ and compute the derivative

$\frac{\partial f_{LR}(\textbf{w})}{\partial \textbf{w}^{(k)}} = \textbf{x}_i (-y_i \frac{e^{-y_i \textbf{x}_i \textbf{w}}}{1 + e^{-y_i \textbf{x}_i \textbf{w}}})$.

Once the compute this you can put the result into the gradient descent equation and update all your weights.

You then continue to go through this process until your weights $\textbf{w}$ converge to a value, or some other condition is met. You might want to limit your algorithm with some iteration counter to avoid infinite loops caused by weights that do not converge.

Gradient Descent Code

Here is an example using gradient descent to train weights along the logistic regression loss function.

import numpy as np

def update_weights(x_i, y_i, w):
   p = 0.8                  # The learning rate
   yhat = predict(x_i, w)   # The predicted target
   error = y_i - yhat
   return w + p * (y_i - yhat) * x_i  # Update the weights

def predict(x_i, w):
   return 1/(1+np.exp(-1 * np.dot(w.T, x_i)))

def train_weights(x, y, verbose = 0):
   w = np.zeros((x.shape[1],))
   w_temp = np.zeros((x.shape[1],))

   epoch = 0
   while epoch <= 1000:
      for i, x_i in enumerate(x):
         w = update_weights(x_i, y[i], w)

      pred = 1/(1+np.exp(-1 * np.dot(x, w)))
      error = np.sum(pred - y)

      pred[pred < 0.5] = 0
      pred[pred >= 0.5] = 1
      epoch += 1

      if verbose == 1:
         print('------------------------------------------------')
         print('Targets: ', y)
         print('Predictions: ', pred)
         print('Predictions: ', pred)
         print('------------------------------------------------')

      # Check if we have reach convergence
      if np.sum(np.abs(w_temp - w)) < 0.001:
         print(epoch)
         print(error)
         return w
      else:
         w_temp = w
  return w

# Create some artificial database
x = np.zeros((4,3))
y = np.zeros((4,))
x[0] = [1, 1, 1]
x[1] = [1, 2, 2]
x[2] = [1, 10, 10]
x[3] = [1, 11, 11]
y[0] = 0
y[1] = 0
y[2] = 1
y[3] = 1

print(x)
print(y)

# Train the weights
w = train_weights(x, y, 0)
print('Trained weights: ', w)

# Get predicitons
pred = 1/(1+np.exp(-1 * np.dot(x, w)))
error = np.sum(pred - y)
pred[pred < 0.5] = 0
pred[pred >= 0.5] = 1
print('Predictions: ', pred)


Hello, when i'm training my model with 80% data and testing with 20% data the accuracy is 49% and without split it's 99%

When you split the data , you are training your model on 80 percent of the dataset , but you are finding the accuracy of the remaining 20 percent of the data.
And when you are not splitting the data your model is learning and calculating accuracy from a similar dataset , hence the accuracy is pretty high.
You should:
1.Always split the data and try to achieve high accuracy on the test set rather than the training set.
2.If your training data accuracy is quite higher than the test data this means your modell is overfitting.


Nested cross-validation and selecting the best regression model - is this the right SKLearn process?

Yours is not an example of nested cross-validation.

Nested cross-validation is useful to figure out whether, say, a random forest or a SVM is better suited for your problem. Nested CV only outputs a score, it does not output a model like in your code.

This would be an example of nested cross validation:

from sklearn.datasets import load_boston
from sklearn.cross_validation import KFold
from sklearn.metrics import mean_squared_error
from sklearn.grid_search import GridSearchCV
from sklearn.ensemble import RandomForestRegressor
from sklearn.svm import SVR
import numpy as np

params = [{'C': [0.01, 0.05, 0.1, 1]}, {'n_estimators': [10, 100, 1000]}]
models = [SVR(), RandomForestRegressor()]

df = load_boston()
X = df['data']
y = df['target']

cv = [[] for _ in range(len(models))]
for tr, ts in KFold(len(X)):
    for i, (model, param) in enumerate(zip(models, params)):
        best_m = GridSearchCV(model, param)
        best_m.fit(X[tr], y[tr])
        s = mean_squared_error(y[ts], best_m.predict(X[ts]))
        cv[i].append(s)
print(np.mean(cv, 1))

By the way, a couple of thoughts:

I see no purpose to grid search for n_estimators for your random forest. Obviously, the more, the merrier. Things like max_depth is the kind of regularization that you want to optimize. The error for the nested CV of RandomForest was much higher because you did not optimize for the right hyperparameters, not necessarily because it is a worse model.
You might also want to try gradient boosting trees.


Using GPUs of other machines in the network with Keras

I'm not sure how exactly you're imagining it but the way you're describing it is not possible. You can't perform some computation locally and some remotely and even if you could set it up it would be inefficient due to latency.

A lot of people (including myself) have similar situations and the way we deal with it is executing everything remotely. I.e. you have your data, your code and your notebooks all in the remote machine, from where you run them. However, you access these from your own PC. E.g. you might have a notebook running on your own browser, that actually executes its commands on the remote machine (think of it like google colab or kaggle notebooks).

How to set this up

First of all, creating a dual-boot linux isn't necessary. You should do it only if you feel that you're a lot more familiar Linux than Windows. What you need to do is:

Install all necessary NVIDIA tools so that you can run keras on GPU. These include installing (a) the proper graphics card drivers, (b) CUDA and (c) cuDNN
Setting up your python ecosystem, which needs to have all necessary libraries (jupyter, tenrosflow, keras, etc.). I'd suggest a virtual environment. At this point you should make sure keras runs properly on the GPU on your remote machine.
Setup an ssh connection that forwards everything sent to port 8888 of your remote machine to a port of your choosing (e.g. 9999) in your own machine:
ssh -N -f -L localhost:8888:localhost:9999 username@remote_hostname.
Connect via ssh to your remote machine and run jupyter notebook (I prefer running it on the background or in a screen so that I don't have to keep the terminal always open). Take note of the token that it outputs to the screen as it won't log you in automatically.
Open your browser and type localhost:9999. You need to add the token here for authentication. Now you're using a notebook that's actually running on your remote machine!

Additionally, you can set up other tools to make your life easier. For instance, I have a FTP client for transferring data easier and have set up PyCharm to use a remote interpreter (i.e. execute code I write on the remote machine).


I think the easiest way would be to cluster them with wordvectors.
The "20 Newspaper" dataset would be a good test for the algorithm
http://qwone.com/~jason/20Newsgroups/

On the Sklearn Website, you will find some easy example for using wordvectors and classification:
http://scikit-learn.org/stable/datasets/twenty_newsgroups.html

If you go deeper into this space you could start using LSTM networks and neural networks, but this is a little bit harder to develop. So first, try to use the problem statistically. If you want to analyze the text semantically you will need LSTM.

I hope I could help you.


Yes there is a cost (score/utility) function and your intuition is correct. In vanilla PG we optimize the expected return $J$ of a trajectory $\tau$ under policy $\pi$ parametrized by $\theta$:

$$\nabla_{\theta} J\left(\tau\right)
\approx \frac{1}{N} \sum_{i=1}^{N} \nabla_{\theta} \log \pi_{\theta}\left(\tau_{i}\right) r\left(\tau_{i}\right)$$

(You can find lots of information here: https://spinningup.openai.com/en/latest/algorithms/vpg.html)

The vanilla PG is very closely related to maximum likelihood:

$$\nabla_{\theta} J_{\mathrm{ML}}(\theta) \approx \frac{1}{N} \sum_{i=1}^{N} \nabla_{\theta} \log \pi_{\theta}\left(\tau_{i}\right)$$

The two gradients are almost the same except the reward multiplication. This reward is the learning signal. Thinking in terms of backpropagation your gradients are being multiplied by the reward signal. You can think of the vanilla PG as a cost-sensitive classification - with the broad sense.

I will give you a very simple example with Neural Networks in order to demonstrate you the result of the PG learning mechanism. Assume a very simple architecture:

( input --> CNN --> CNN --> fully connected (fc) layer --> out1: V(input), out2: $\pi(a|input)$ )

which can be trained asynchronously or synchronously. The output has two heads one for the expected reward and one for the policy.
Let's assume a task in which an agent has to learn to select between two rewarding targets (orange r=10, green r=1). The targets are presented either both of them or one at a time randomly upon completion of an episode.

Assume now that the agent is fully trained. Taking the fc representations from various episodes and running tsne (clustering) we get the following picture:

This 2D representation tells us that the network has a "clear understanding" when there is only the green target, only the orange target and both of them together. We could colored differently the cluster to get a sense of the expected reward or the action preference (as the fc encodes spatial information, reward information and action preference).

Policy Gradients are mapping states to action distributions (and/or reward predictions). This means that the learned function (the Neural Network) should have the appropriate representations to do that mapping. And this is essentially what is learned by the network: a decision boundary (given input state). Please note that this is a very simplistic example to get an insight of what the network has learned so you can easily draw parallels to the classification case.


what does "blocks" mean in the context of HDFS ecosystem? is it the same concept in the context of a single hard disk drive?

Essentially yes but the size is very different. A hard drives default block size is 512 bytes but Hadoops default block size is 128 Megabytes.

Hadoop also replicates blocks to maintain integrity of the data.


Check similarity of table/csv of Product Names

Your problem is known as detection of near-duplicate documents, i.e. you have strings that are similar but not exact duplicate. The most common approaches are using cosine similarity and Jaccard similarity. You could check this page for more information

First you have to convert your strings to a vector of features, this features could be tf-idf vectors of all the tokens (words) that appear in the database, could also be a vector of n-grams. For a discussion of semantic and syntactic features you can look here.

Finally you would have to check the similarity of every pair of documents, in your case 18000. The brute force approach is O(n^2), so this could be unfeasible. A common technique to deal with this issue is to use fingerprinting (hashing) together with Locality Sensitive Hashing (LSH).

You can find an introduction and a general discussion of the whole topic in Chapter 3 of Mining Massive Datasets


Feeding 3 consecutive video frames to a CNN to track a tennis ball

The researchers who made Tracknet finally open-sourced their code and will do so with dataset as soon as they settle their copyright issues.

Here are the links:

Arxiv paper:  Tracknet Arxiv paper

Tracknet repo

If the link is broken, let me know and I'll upload the zip and tar.gz along with Readme file to Dropbox.

Here is a link to the resulting video with tracked ball.
Fed Nadal demo

It is not perfect so probably going to combine this method with blob detection, difference frames used in other papers.  Also need to take out the lines, players and other background from being detected.

Here is the code snippet where they concatenate three frames in predict_video.py.

#combine three imgs to  (width , height, rgb*3)
X =  np.concatenate((img, img1, img2),axis=2)


Can some one explain how PCA is relevant in extracting parameters of Gaussian Mixture Models

I believe the claim that you are referring to is that the maximum-likelihood estimate of the component means in a GMM must lie in the span of the eigenvectors of the second moment matrix.  This follows from two steps:

Each component mean in the maximum-likelihood estimate is a linear combination of the data points.  (You can show this by setting the gradient of the log-likelihood function to zero.)
Any linear combination of the data points must lie in the span of the eigenvectors of the second moment matrix.  (You can show this by first showing that any individual data point must lie in the span, and therefore any linear combination must also be in the span.)


LOF gives same number of outliers irrespective of parameters

As per sklearn documentation, you have default parameter contamination set at 0.1.

contamination : float in (0., 0.5), optional (default=0.1)
The amount of contamination of the data set, i.e. the proportion of outliers in the data set. When fitting this is used to define the threshold on the decision function.

No matter how many times you will run the algorithm with different n_neighbours, 10% of your dataset will be retained as outliers.
Keep in mind that, when running a LOF, you are first executing a k-nearest-neighbour algorithm, which is dependent of the n_neighbours parameter. You then evaluate the local density of your points (respectively with their nearest neighbours), which returns a numerical value. However, you have yet to decide over which threshold value a point should be considered as outlier, and this is precisely where the contamination parameter intervenes. It allows you to calculate the threshold with respect to the contaminated proportion you have specified.
I suggest you visualize the results of the LOF to determine whether your contamination proportion is relevant, or ought to be adjusted.