Getting very low/ wrong accuracy from RandomizedSearchCV

UPDATE AFTER EXCHANGING COMMENTS
You might be facing issues with the computation of the accuracy

I think the MLP with the log-loss can work well with your output data. Your output data is a vector $(N, 230)$ with $N$ the number of samples, with only 1s or 0s. This data is indeed a one-hot encoded vectors with multiple 1s.

You are computing the accuracy by flattening the predictions and comparing them elemt-wise ($N*230$ elemetns),

For computing the accuracy, I guess if the classifier is not comparing the one-hot vectors (ground truths and predictions) element wise , but comparing if they re the same for each one of the $N$ samples.  Think that if only one element of the 230 onte-hot encoded is missclassified in one sample, this accuracy will drop by $1/$N$*100$ %. If accuracy is computed element-wise, the drop in the accuracy will be $1/(230*N)*100$ %...

Try to update your accuracy computation assingning a 1 only if each predicted (230, 1) vector of each sample is equal to its (230,1) ground truth vector.

PREVIOUS ANSWER BEFORE COMMENTS
I guess you are experimeting problems with your data...
Your data does not seem to be a binary classification problem, for binary classification your data should have the following dimensions:

Input: $(N, K)$
Output: $(N, 1)$ or $(N, 2)$ if is one-hot encoded.

With $N$ the number of sample of the split, $K$ the dimension of the feature input space
If your output data is of size
$(N, D)$,
then it could be a regression problem that maps a feature space of $K$ to $D$. Yout MLP should try to mimmic a function.
$f'(X): K \to D$
For regression problems you must use other metrics, like MAE or MSE
You can treat the problem from various perspectives (just some ideas).

as a masking/segmentation problem in 1D (making an analogy with mask segmentation for 2D images...)
A Bayesian approach could work well also. You can try to estimate the posterior probability of parameter of the Binomial distribution which models the nodes being 1 or 0 (posterior) from your data (likelihood)... and then update your posterior distribution with new data so that you can have updated and more accurate credible intervals. Obviouslly you may thing about if a Binomial distribution models fine your data (i.e. independancy, etc...) Maybe other probability distribution works better

Thge following example works well. I know it does not answer the question (I'm just trying to help), but at least, we can see with an example that RandomizedSearchCV should give the same score as the accuracy_score with your code for a binary classification problem with a MLP
from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import RandomizedSearchCV
from sklearn.metrics import accuracy_score
from scipy.stats import uniform
from sklearn.neural_network import MLPClassifier
from sklearn.model_selection import train_test_split
import numpy as np
X, y = make_classification(n_samples=1000, random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
clf = MLPClassifier(solver = 'adam',
                max_iter=9999,
                alpha=1e-5
                )

hidden_layers = 2
neurons = list(range(10,210,5))

m = [0]*(hidden_layers*len(neurons))

for i in range(1,hidden_layers+1):
    for idx,i2 in enumerate(neurons):
        m[((i-1)*len(neurons)) + (idx)] = [neurons[idx]]*i

param_space = {
    'hidden_layer_sizes':   m,
    'activation':           ['identity', 'logistic', 'tanh', 'relu'],
    'learning_rate':        ['constant','invscaling','adaptive'],
    'learning_rate_init':   np.arange(1e-4,0.1+1e-4,1e-4)
    }

clf_rand_search = RandomizedSearchCV(clf, param_space, n_iter=2,
                                        scoring="accuracy", verbose=True, cv=2,
                                        n_jobs=-1)

search = clf_rand_search.fit(X_train, y_train)
print(search.score(X_test,y_test))

print(accuracy_score(y_test.flatten(), search.predict(X_test).flatten()))


I pondered this question a little more, there might not be an optimal loss function.. But here is an idea which could utilize SVMs hyperplane seperation ability.

I take the point cloud, if I need an approximating line from the bottom, copy points below with user defined gap, and I flip the points, as in mirror image along the x-axis. I give both point groups opposing labels, then feed the whole thing to SVM. Ideally I should get something like this:

The top line is the line I am looking for.

Code

import pandas as pd
points1 = np.array(pd.read_csv('quadri.csv'))
plt.plot(points1[:,0], points1[:,1], 'o')
points2 = np.copy(points1)
points2[:,1] -= 7.
xmin = np.min(points2[:,0]); xmax = np.max(points2[:,0])
points2[:,0] = (xmax-points2[:,0])+xmin
points = np.vstack((points1,points2))
plt.plot(points[:,0], points[:,1], 'o')
plt.xlim(4,14); plt.ylim(0,15)


Appropriate ML algorithm for allocating students to seats

That problem is an optimization problem, selecting the selection of the best element (with regard to some criterion) from some set of available alternatives.

It falls in the general class of computational geometry. Specifically, a bin packing problem, items of different values must be packed into a finite number of containers.


Do Convolution Layers in a CNN Treat the Previous Layer Outputs as Channels?

Lets say you have a max pooling layer that gives 10 downsampled feature maps. Do you stack those feature maps, treat them as channels and convolve that 'single image' of depth 10 with a 3d kernel of depth 10? That is how I have generally thought about it. Is that correct?

Yes. The usual convention in a CNN is that each kernel is always the same depth as the input, so you can also think of this as a "stack" of 2D kernels that are associated with the input channels and summed to make one output channel - because under the convention that $N_{in\_channels} = N_{kernel\_depth}$ this is mathematically the same. Expressing as a 3D convolution allows for simpler notation and code.

  On the second convolution layer in the above visualization most of the feature maps only connect to 3 or 4 of the previous layers maps. Can anyone help me understand this better?

The diagram is non-standard in that respect, although it seems to show pooling and fully-connected layers as normal. It might be a mistake in the diagram, or something unconventional about that specific CNN.

  If our input is a color image our first convolution kernel will be 3D. This means we learn different weights for each color channel (I assume we aren't learning a single 2D kernel that is duplicated on each channel, correct)?

Correct. You can see this in the visualised filters for AlexNet (do note that for computational reasons, AlexNet specialised one half of its filters to work in greyscale, and had other clever optimisations that we don't use nowadays because available GPU power is high enough to not need them). Most implementations will also treat a greyscale image as a 1-channel 3D shape for consistency.


Data driven approach to define a churn user

Another approach would be to model "churn" (aka "diminished use of the service, including non-use") as a process and not an event.  Years ago in retention marketing this was called a "defection funnel", to mirror the "sales funnel" on the customer acquisition side (suspect -> prospect -> trial customer -> repeat customer -> loyal customer).  So a defection funnel might look like this:

  loyal/frequent customer -> disaffected customer -> infrequent customer -> non-customer

It is proper to label this a "funnel" because a subset of each stage move on to the next stage.  Not all "disaffected customers" become "infrequent customers", and so on.

There are two keys to defining a defection funnel.  First, define the behavioral characteristics for the funnel as a whole, and for each stage (category) within the funnel.  In your case, it might be a variation of the familiar RFM ("recency" "frequency" and "monetary") score.  Second, you need to identify other behavioral characteristics or patterns that show a propensity to move from one stage to another.  These might include: complaints, being victim of trolling, experiencing service interruptions, experiencing betting losses, how long they have been using the service, or maybe it is just demographics.

With these definitions in place, you are in a position to build a predictive model and also track over time the population of customers in each category.

By the way, this approach is not dependent on dividing the funnel into "stages", nor does it matter fundamentally how many stages you have.  However, defining discrete stages has many practical benefits, including communicating your model and results to other people who are not quantitative or statistically minded.


Custom loss function with additional parameter in Keras

You can write a function that returns another function, as is done here on GitHub

def penalized_loss(noise):
    def loss(y_true, y_pred):
        return K.mean(K.square(y_pred - y_true) - K.square(y_true - noise), axis=-1)
    return loss

input1 = Input(batch_shape=(batch_size, timesteps, features))
lstm =  LSTM(features, stateful=True, return_sequences=True)(input1)
output1 = TimeDistributed(Dense(features, activation='sigmoid'))(lstm)
output2 = TimeDistributed(Dense(features, activation='sigmoid'))(lstm)
model = Model(input=[input1], output=[output1, output2])
model.compile(loss=[penalized_loss(noise=output2),
penalized_loss(noise=output1)], optimizer='rmsprop')

In the wrapper function you can pass scalars or keras tensors like additional inputs. In your case you would add the weights in the top wrapper function and reference them in your inward function.


Why are results of cross-validation before splitting is different from results after splitting?

Without having more information my hypothesis the complexity of your model.
I think you might have a model so complex that it needs a "large" amount of data for having a good performance (First scenario with cross validation on full data)
Then when you split your data in train - test set and repeat the cross validation the amount of data is reduced naturally so it is causing that your model do not have enough samples to generalize.
That might be confirmed via a learning curve:

If the training and cross-validation scores converge together as more data is added (shown in the left figure), then the model will probably not benefit from more data. If the training score is much greater than the validation score then the model probably requires more training examples in order to generalize more effectively.


Getting stock data in a discipline manner from Yahoo finance

Use:

data.stack().reset_index().rename(index=str, columns={"level_1": "Symbol"}).sort_values(['Symbol','Date'])

Output:

           Date       Symbol  Adj Close  ...     Low    Open     Volume
0    2018-01-01  AXISBANK.NS     564.80  ...  560.50  563.80    6943234
7    2018-01-02  AXISBANK.NS     558.81  ...  556.35  567.00    6292268
14   2018-01-03  AXISBANK.NS     559.75  ...  555.75  561.30    3990149
21   2018-01-04  AXISBANK.NS     559.21  ...  558.00  564.85    2766664
28   2018-01-05  AXISBANK.NS     562.55  ...  556.70  561.05    3249056
35   2018-01-08  AXISBANK.NS     564.75  ...  562.45  565.80    3770339
42   2018-01-09  AXISBANK.NS     564.60  ...  563.00  564.00    4607504
49   2018-01-10  AXISBANK.NS     562.10  ...  560.45  566.15    2411625

The basic operation is stack that stacks the column headers into a multiindex. This multiindex is then converted to columns (reset_index()) which then get proper names. Finally the data are sorted by Symbol and Date as required.

Remark: You don't need df = pd.DataFrame(data), yf.download already returns a DataFrame.


Create most "average" cosine similarity observation

You are doing the correct thing. Technically, this averaging leads to computing the centroid in the Euclidean space of a set of N points. The centroid works pretty well with cosine similarities (cosine of the angles between normalized vectors), e.g. the Rocchio algorithm.


Can Adagrad be used to optimize non-differentiable functions?

The book has a misunderstanding (but it's understandable where it came from).

If you can compute subgradients, you can use gradient descent.  You don't have to use AdaGrad -- you can use any gradient method you like.  Basically, you just use a subgradient in place of the gradient in the update step.  See, e.g., https://en.wikipedia.org/wiki/Subgradient_method.

AdaGrad is an adjustment to gradient descent that adjusts the update step.  I believe AdaGrad is orthogonal to whether you use subgradients or gradients in the update step.

I can see where the misunderstanding comes from.  The original paper on AdaGrad talks about subgradient methods.  However, if you read the introduction carefully, you will recognize what's going on there.  Subgradient methods are a broader category, that includes both ordinary gradient descent and subgradient descent.  So, the paper is just trying to be as general as possible.  Their method applies both to ordinary gradient descent and also to subgradient descent.


Would there be any reason to pretrain BERT on specific texts?

Sure, if you have a large and good quality in-domain dataset, the results may certainly  be better than with the generic pretrained BERT.
This has already been done before: BioBERT is a BERT model pretrained on biomedical texts:

[...] a domain-specific language representation model pre-trained on large-scale biomedical corpora. With almost the same architecture across tasks, BioBERT largely outperforms BERT and previous state-of-the-art models in a variety of biomedical text mining tasks when pre-trained on biomedical corpora. While BERT obtains performance comparable to that of previous state-of-the-art models, BioBERT significantly outperforms them on the following three representative biomedical text mining tasks: biomedical named entity recognition (0.62% F1 score improvement), biomedical relation extraction (2.80% F1 score improvement) and biomedical question answering (12.24% MRR improvement).

Of course, other factors may be taken into account in the decision to pretrain such a model, e.g. computational budget.


Why transpose of independent feature matrix is necessary in case of linear regression?

That answer comes from the set of weights $w$ (or $\theta$) that analytically solves the cost function which is defined to be

$J(\theta) = (X\theta - y)^T (X\theta - y)$

(See here for more info)

Expanding the cost function we get

$J(\theta) = \theta^TX^TX\theta - 2 y^TX\theta + y^Ty$

(Note that all three terms come out to be scalers)

Before we take the next step, we need to brush up on derivatives of matrices

Some common matrix derivative formulas for reference:

$\frac{\partial (AX)}{\partial X} = A^T \ ;\  \frac{\partial (X^TA)}{\partial X} = A \ ;\ \frac{\partial (X^TX)}{\partial X} = 2X \ ;\ \frac{\partial (X^TAX)}{\partial X} = AX+A^TX$

Using those rules we can take the derivative of the cost function with respect to $\theta$

$\frac{\partial J(\theta)}{\partial \theta} = 2 X^TX \theta - 2 X^Ty$

Setting this to 0 we get

$2 X^TX\theta - 2 X^T y = 0$

solving for $\theta$ we get

$\theta = (X^TX)^{-1} X^T y$

Written in code that's

w = inv(X.T.dot(X)).dot(X.T).dot(y)

Hope this helps.


Python Seaborn: how are error bars computed in barplots?

Looking at the source (seaborn/seaborn/categorical.py, line 2166), we find

def barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None,
        estimator=np.mean, ci=95, n_boot=1000, units=None,
        orient=None, color=None, palette=None, saturation=.75,
        errcolor=".26", ax=None, **kwargs):

so the default value is, indeed, .95, as you guessed.

EDIT: How CI is calculated: barplot calls utils.ci() which has

seaborn/seaborn/utils.py

def ci(a, which=95, axis=None):
    """Return a percentile range from an array of values."""
    p = 50 - which / 2, 50 + which / 2
    return percentiles(a, p, axis)

and this call to percentiles() is calling:

def percentiles(a, pcts, axis=None):
    """Like scoreatpercentile but can take and return array of percentiles.
    Parameters
    ----------
    a : array
        data
    pcts : sequence of percentile values
        percentile or percentiles to find score at
    axis : int or None
        if not None, computes scores over this axis
    Returns
    -------
    scores: array
        array of scores at requested percentiles
        first dimension is length of object passed to ``pcts``
    """
    scores = []
    try:
        n = len(pcts)
    except TypeError:
        pcts = [pcts]
        n = 0
    for i, p in enumerate(pcts):
        if axis is None:
            score = stats.scoreatpercentile(a.ravel(), p)
        else:
            score = np.apply_along_axis(stats.scoreatpercentile, axis, a, p)
        scores.append(score)
    scores = np.asarray(scores)
    if not n:
        scores = scores.squeeze()
    return scores

axis=None so score = stats.scoreatpercentile(a.ravel(), p) which is

scipy.stats.scoreatpercentile(a, per, limit=(), interpolation_method='fraction', axis=None)[source]
Calculate the score at a given percentile of the input sequence.

  For example, the score at per=50 is the median. If the desired quantile lies between two data points, we interpolate between them, according to the value of interpolation. If the parameter limit is provided, it should be a tuple (lower, upper) of two values.

Parameters:
a : array_like
A 1-D array of values from which to extract score.
per : array_like
Percentile(s) at which to extract score. Values should be in range [0,100].
limit : tuple, optional
Tuple of two scalars, the lower and upper limits within which to compute the percentile. Values of a outside this (closed) interval will be ignored.
interpolation_method : {‘fraction’, ‘lower’, ‘higher’}, optional
This optional parameter specifies the interpolation method to use, when the desired quantile lies between two data points i and j
fraction: i + (j - i) * fraction where fraction is the fractional part of the index surrounded by i and j.
lower: i.
higher: j.
axis : int, optional
Axis along which the percentiles are computed. Default is None. If None, compute over the whole array a.
Returns:
score : float or ndarray
Score at percentile(s).

and looking in the source for scipy.stats.stats.py we see the signature

def scoreatpercentile(a, per, limit=(), interpolation_method='fraction',
                      axis=None):

so since seaboard calls it with no param for interpolation it is using fraction.

On a side note, there is a warning of future obsolescence in stats.scoreatpercentile(), namely

  This function will become obsolete in the future. For Numpy 1.9 and higher, numpy.percentile provides all the functionality that scoreatpercentile provides. And it’s significantly faster. Therefore it’s recommended to use numpy.percentile for users that have numpy >= 1.9.


What are the practical differences between pooling types at convolution?

See Analysis and Optimization of Convolutional Neural Network Architectures for the pooling types in general.

  What is the difference between max pooling, average pooling and min pooling?

A pooling function $f: \mathbb{R}^n \rightarrow \mathbb{R}$ is a function which is very symmetric:

$$f(x_1, x_2, \dots, x_n) = f(x_2, x_1, \dots, x_n) = f(x_n, x_1, \dots, x_2) = \dots$$

So the function does not care about the order of the arguments. This is the case for $\min$, $\max$ and average.

In the context of CNNs, you apply the pooling function to each feature map independantly. The output of a pooling layer has exactly as many feature maps as the input. For each feature map, you take a $p \times p$ section and apply the pooling function $f$ to it. Usually, you apply it with a stride $s > 1$ so that the output is much smaller than the input (only $\frac{1}{s^2}$).

  I have learnt that pooling is a sort of downsampling where we can preserve the locations of the original image that showed the strongest correlation to the specific features we searching for.

This is only true if you talk about max-pooling with $s > 1$. Which is usually the case. Although I would not say "correlation" but "activation".

  But what is the point of find weakest correlations with min pooling, for example?

I don't know. I have never seen min pooling even be mentioned. Where have you seen it?


How to do multivariate survival analysis on dataset having only categorical variables

It seems a problem that can be solved with a correct approach for survival analysis with time-dependent covariates.

https://cran.r-project.org/web/packages/survival/vignettes/timedep.pdf

This vignette is useful also for those not interested in R code.

Have you tried a random forest survival analysis approach?


Churn definition for non-contractual services

Perhaps you can define an "active user" (e.g., someone who has made a purchase in the last 3 months, etc. Choose a period sensible for the typical purchase cycle) and calculate the something along the line of DAU or MAU, etc. Say, if a typical active user will on average buy something from your store every 3 months, assume a user has churned if she fails to make a purchase in the last avg + 1sd days, etc.?

The other potential KPI to use is probably the CLV, but similar to DAU and MAU, it is not without its criticisms.


Pandas - Create a Integer Primary Key based in string columns - python

You could simply drop the index to create and use it as a primary key column.
all_data.reset_index(inplace=True)
all_data.head()


In linear regression, is there anything I can do if the coefficient for one of the features is unrealistic/inappropriate?

What could be happening here is multicollinearity - where some of your predictors are correlated. In this case, it is not unreasonable to think that square footage, number of beds and number of bathrooms are all positively correlated with each other. This is not a big deal if your main goal is to just predict house prices, but what multicollinearity does in essence is that it makes it 'harder' to estimate the actual coefficient values, so your interpretations of the coefficients can't carry as much weight. I suspect that using more data will indeed reduce the chance of this happening.


Reverse classification model: Is it possible?

As with anything, it depends. :) Your question will very much depend on the model.

This question is reminiscent of the broader debate about discriminative versus generative models. Usually, we work with discriminative models. That is, you model $\text{P}(Y=1\,|\,X_1, X_2, \dots)$, where $Y$ are your classes and $X_i$ your observations.

There is another class of models: generative models, like Restricted Boltzmann Machines, which model joint distributions, $\text{P}(Y,X_1, X_2, \dots)$. They can be used for classification because you can easily turn a joint probability into a conditional probability. These models usually are broader in scope, and usually do not perform as well, which is why they aren't used as much. But they do exist.

Assuming that you are talking about discriminative models, like decision trees or the logistic regression, then what you want is how to invert this conditional probability, so that you have a distribution along $X_i$; that is, $\text{P}(X_1=x_1, X_2=x_2, \dots \,|\, Y)$.

From Bayes's theorem, $\text{P}(Y=1\,|\,X_1=x_1, X_2=x_2, \dots)=\text{P}(X_1=x_1, X_2=x_2, \dots \,|\, Y=1)\frac{\text{P}(Y=1)}{\text{P}(X_1=x_1, X_2=x_2, \dots)}.$

So, yes, you can. Where is the catch?

$X$ and $Y$ have to be discrete. It is very easy to create a probability density function from categorical variables by just getting conditional probabilities out of your model by just trying all combinations of $X$. And, once you have a probability density function, then you can just use a sampling technique to generate values.

It is less clear to me how you could make this work for continuous values, unless you are willing to use an approximation by discretizing your observations. I think an exact solution will depend very much on the discriminative model at hand. You cannot do this alone by getting conditional probabilities out of the model.

But if sampling is important for you, then you should just use a generative model.


Retrieving follower and followee (friend) counts using Twitter API

I end up using GET users/show from Twitter API.

The details of User object which can be retrieved with this GET request can be founded in here.


How to implement sequence to sequence models?

you need to define how many time steps you want to have in each time series block.
then for each unique patient, you need to create these blocks so the training set going to be a 3D matrix, and the dimensions are:
number of blocks * number of time steps * number of features
in addition to time series data, you can also add another head to feed NN with the constant data like patient id, day of the week, and ...
for the time series part, you can use biLSTM or biGRU or and other RNN layers and then a Dense layer and then concatanate the results with the results coming from constant features.
for the output, you can also use an RNN layer to predict the sequence of future visits or simply use Dense layers.
==============Updated
consider below flow chart
if your other features (like drugs, lab tests) don't have the same time structure, consider it as groups of time series and for each one add other heads along with RNNs with different input shapes (for the number of time steps). the key is to bring all your features to the latent space and from there, do the decoding and predict the sequence of the future.


How can I use my own dataset for Image segmentation using Tensorflow

Just having segmented images is probably not enough. The training data for segmentation needs to be in a specific format.
Have a look at the coco dataset for image segmentation. Sometimes we need to convert the dataset into that format.
I'd suggest reading up a bit on how to train a mask rcnn model on your own dataset. There are a number of articles available online.


Training network with variable frame rate?

I don't believe there is a well-known method to deal with this.

Simple pre-processing

While I haven't done this with images/videos, I know from general time-series analysis that you basically have to interpolate the lower frequencies or you need to down-sample the higher frequencies. If you think about, what else is there to do...?

Modelling solution

Nvidia released a research paper with an accompanying video showing how they were able to train a model, which could estimate the frames between frames - effectively interpolating video and increasing its frame rate. This would essentially be the equivalent of interpolation between frames and allow you to scale up your lower frequency videos to match the higher frequency ones. The paper is named:

  Super SloMo: High Quality Estimation of Multiple Intermediate Frames for Video Interpolation

... sounds like something worth reading.

There are older algorithms that try to do the same thing (e.g. "twixtor"), but I read they have problems with things such as rotating objects. Another thing to keep in mind is the usual GIGO: garbage in garbage out. There are still some artefacts of interpolation in the Nvidia video, but that likely comes from blurry input images used during training when e.g. objects were moving faster than the recording frame rate could handle.

It seems that they train two models: the first encodes the optical flow between frames and the second model uses that, along with the base images to perform the interpolation. Please read the paper for more details. It also outlines how they train the model (learning rates, number of epochs, augmentation steps, etc.).

Here is the sketch of their model for flow computation/interpolation:

We can see that it is an encoder/decoder-looking model, introducing a bottleneck that condenses the information, before upsampling again. This is based on the U-net model architecture: an encoder/decoder that also introduces skip connections between layers of different scales.


Rather than use an external dictionary of keywords that are indicative of target class, you may want to take your raw data (or rather a random subset of it), then hand-label your instances (assign each row a label, BEST_EFFORT or URGENT). This becomes your training data - each row of data can be transformed into a bag-of-words vector indicating the presence/absence of the word in that particular text. You can train a classifier on this data, for example a naive bayes classifier, which can then be tested on the held out unseen test data. The advantages of the  proposed approach are: (1) automated computation of features vs. hand created dictionary; (2) probabilistic/weighted indicators of class vs. binary dictionary indicators.


Are there any objections to using the same (unlabelled) data for pre-training of a BERT-Based model and the downstream task?

Not at all. A recent ACL paper by AllenAI even says this is the best way. They recommend continuing pre-training on the task data and claim that it reduces the problems caused by domain mismatch. So, if you train the model on the in-domain data from the very beginning, it is probably a good thing given you have enough data for that.


Are weights of a neural network reset between epochs?

An epoch is not a standalone training process, so no, the weights are not reset after an epoch is complete. Epochs are merely used to keep track of how much data has been used to train the network. It's a way to represent how much "work" has been done.

Epochs are used to compare how "long" it would take to train a certain network regardless of hardware. Indeed, if a network takes 3 epochs to converge, it will take 3 epochs to converge, regardless of hardware. If you had used time, it would be less meaningful as one machine could maybe do 1 epoch in 10 minutes, and another setup might only do 1 epoch in 45 minutes.

Neural networks (sadly) are usually not able to learn enough by seeing the data once, which is why multiple epochs are often required. Think about it as if you were studying a syllabus for a course. Once you finished the syllabus (first epoch), you go over it again to understand it even better (epoch 2, epoch 3, etc.)


How can I use geo location for predictive modelling

Why is it categorical? You can use the longitude / latitude numeric coordinates as two features.


Similarity between two time series with different sampling frequency, different amplitude, and different lengths but taken from the same source?

What you could do is

downsample both series to match sampling rate between them
crop the longest series to match the shorter one

Then, there is a variety of methods to estimate similarity between the two series. Some of those are:

cross correlation: this will be affected by the amplitude and will not be able to estimate lagged correlations, prone to noise.
coherence: normalised frequency based correlation (cross-spectrum), not prone to amplitude or noise.
wavelet coherence: similar to above but based on wavelet transformations instead of STFFT.
dynamic time warping: measuring similarity between two temporal sequences, which may vary in speed.


Creating a feature by combining 2 features with different units?

You can combine multiple features only if they are on same scale.

Combining feature A with range of possible values (100-1000) with feature B with range of possible values (1-10) will result in feature biased towards A.

You will need to standardize them to the same scale.

For every value X of A = (X - smallest(A))/(biggest(A) - smallest(A))
For every value Y of B = (Y - smallest(B))/(biggest(B) - smallest(B))

Now all values of A and B resides in the range of (0,1). You can add based on the weight of every attributes. If both are equally important then C = (0.5 * A) + (0.5 * B) and if A should have 70% of weight then C = (0.7 * A) + (0.3 * B)


Random forest model gives same result for all test data, Next step?

Some of the possibilities include the following:

1) The training data has class imbalance.

Solution:

Train the model using CV = 5 or 10;
Do a log transformation to make the target distribution more normal in nature;
Check if you can add a weight variable that can fix the distribution.

2) Testing data is a small sub sample. Since it's Kaggle, I believe the testing data will be standard in nature, so the problem might be in the process that is generating the submission script.

As a beginner, you should use any benchmark script available in the forum to start with, which shouldn't have such issues.


How to predict probabilities in xgboost?

Just use predict_proba instead of predict. You can leave the objective as binary:logistic.


Is there a R implementation of isolation forest for anomaly detection?

See the iforest package on Sourceforge or on R-Forge:

This package implements an anomaly detection method that detects data-anomalies using binary trees. Using the property that anomalies are more susceptible to isolation, anomalies can be detected as data points which have short expected path lengths.

  Isolation Forest detects data-anomalies using binary trees. Platform:
  R Reference: Fei Tony Liu, Kai Ming Ting, and Zhi-Hua Zhou, “Isolation
  Forest”, IEEE International Conference on Data Mining 2008 (ICDM 08)

or the isofor package on GitHub:

One efficient way of performing outlier detection in high-dimensional datasets is to use random forests. The isofor ‘isolates’ observations by randomly selecting a feature and then randomly selecting a split
value between the maximum and minimum values of the selected feature.


Do I use the mean vector from my training set to center my testing set when dimension reducing for classification?: Yes.

Test set must not be combined with training set in any step of calculating the reduced dimension space. Characteristics of final space is determined by training set and test set just follows that i.e. the mean-adjusting step uses training mean.

You just calculate the final eigenvectors matrix $E$ (whose dimension is $d\times d$ at the beginning where $d$ is the dimensionality of data, and becomes $d_{reduced}\times d$ after choosing top vectors) and then your test data $D$ ($n\times d$) is just multiplied to that matrix, you get test data in the reduced space ($D^{'}$):

$$D_{n\times d}\times E^{T} = D^{'}_{n\times d_{reduced}}$$

where the dimensionality of $E^{T}$ is $d\times d_{reduced}$ as $T$ denotes matrix transpose (you mentioned inverse which is wrong).

NOTE: Depending on how you arrange samples in your data matrix, the matrix product will be totally different. Do not get confused if you see different things in literature. The standard form of data is usually $n_{samples}\times n_{features}$ which was assumed above as well. Each row is a sample and each column is a dimension.

I hope it helped. You can comment if you had any questions.


Understanding the algebra behind a specific partial derivative equation


Purpose of trace-decay parameter in eligibility traces

The beauty of eligibility trace lies in the fact that it generalizes and unifies TD and Monte-Carlo methods.

When lambda=0, only the present state will get updated, because for the other states eligibility trace will be 0 and they will not be updated. This will be a TD update.

For larger values of 0 < lambda < 1, more of the preceding states are changed, but each state which is more temporally distant is changed less due to decaying property of eligibility traces.

When lambda=1, the preceding states with positive eligibility traces will be updated. This allows us to achieve monte-carlo updation method by backward view. Eligibility trace allows us to look backward and perform updated to the preceding states. Here, the decay parameter is used to achieve the discounted reward setting for the monte-carlo updates. This property of eligibility trace will also allow us to use monte-carlo approaches for continuing tasks.


How to tell how much information I lose when I simplify the graph data structure with respect to unsimplified graph?

Graph comparisons can be tricky.

One option is to take an Information Theory approach, something like "An information-theoretic, all-scales approach to comparing networks"


Well, there is a bunch of articles that tries to tackle this problem but basically, to guarantee a good solution you will need to do Grid Search (sklearn tutorial on it)

You can use various techniques for that, for example:

Binary Gridsearch: Try the maximum and the minimum value in the interval you want, and the middle point, check which side is best and set the minimum or the maximum as your previous middle point according.

That can help you find an average solution fast, but remember that this comes without warranty.

Exhaustive Grid Search
Randomized Parameter Optimization
Genetic Algorithms

Check the link for sklearn for more information. I research on kernel methods and this is aways a bit annoying thing to tackle.

Note: If you're only going to try RBF I would advise to use $\sigma$ as a value betwen the norm of your training samples $\pm 80\%$. You could also normalize you vectors to norm 1 and limit the search to $0.2$ to $1.8$. Usually too small $\sigma$ gives high sensibility to noise while too big aproximates a straight line (loses non-linear power)


Contrasting logistic regression vs decision tree performance in specific example

A few assumptions I'm making:

I believe you're mapping your input set of integers to another integer, which means your output is discrete, so I think you're using [multinomial logistic regression] (https://en.wikipedia.org/wiki/Multinomial_logistic_regression).
You're treating your discrete inputs (integers) as continuous--i.e., you're not using a one-hot-encoding for each integer.
Your underlying function is something to the like of if $\forall j=2,..,10$ if $x \in (x_{j-1}, x_j)$ then $y = c_j$, correct?

If the above three are true, then it's clear why Logistic won't work and why the Decision Tree will. The Logistic will approximate the relationship between your input and output with a $continuous$ linear relationship, which is not exactly what you have here because you have a discontinuity. It's worth mentioning that Decision Trees will perform better at these points, which means the more discontinuities you have the worse your performance will be.

But after a quick simulation, the magnitudes you quoted are too large to be coming from this. So I'm guessing you're using $binary$ logistic regression, which is just the wrong choice of model (since it's mapping everything to a single class instead of many classes).

So, it sounds like you're just using the wrong model.

Below is a quick demo in R.

# Loading packages
require(nnet)
require(rpart)
set.seed(024)
buildData <- function(n){
  x <- 1:n
  x_j <- data.frame(vals=quantile(1:n, probs=1:10/10))$vals
  c_j <- 1:10
  y <- rep(0, n)
  for(i in 1:length(c_j)){
    if(i==1){
      y <- ifelse(x <= x_j[i], c_j[i], y)
    } else {
      y <- ifelse( x >= x_j[i-1] & x <= x_j[i], c_j[i], y)
    }
  }
  print(table(y))
  xdf <- data.frame(x, y=factor(y))
  return( xdf)
}
# Building the data
n <- 1e4
xdf <- buildData(n)
# Random 90-10 split
trnflt <- runif(n) <= 0.5

# Multinomial Logistic Model
multinommod <- multinom(y~x, data=xdf)
xdf$preds_mult <- predict(multinommod, xdf, type='class')

# Binary Logistic Model
logisticmod <- glm(y~x, data=xdf, family='binomial')
xdf$preds_log <- ifelse(predict(logisticmod, xdf, type='response') <= 0.5, 0, 1)

# Decision Tree Model
treemod <- rpart(y~x, data=xdf[trnflt,], method='class')
xdf$preds_tree <- predict(treemod, xdf, type='class')

# Multinomial Logistic confusion Matrix
print(with(xdf[trnflt,], table(y, preds_mult )))
print(with(xdf[trnflt==F,], table(y, preds_mult )))

# Binary Logistic confusion Matrix
print(with(xdf[trnflt,], table(y, preds_log )))
print(with(xdf[trnflt==F,], table(y, preds_log )))

# Decision Tree confusion Matrix
print(with(xdf[trnflt,], table(y, preds_tree)))
print(with(xdf[trnflt==F,], table(y, preds_tree)))

# Here's the performance of all 3
print(c(paste('Multinomial Logistic Regression Accuraccy =', sum(diag(with(xdf[trnflt==F,], table(y, preds_mult )))) / sum(trnflt==F)),
        paste('Logistic Regression Accuraccy =', sum(diag(with(xdf[trnflt==F,], table(y, preds_log )))) / sum(trnflt==F)),
        paste('Decision Tree Accuraccy =', sum(diag(with(xdf[trnflt==F,], table(y, preds_tree )))) / sum(trnflt==F))))


python - Will this data mining approach work? Is it a good idea?

I am not sure if using a classifier is the best way to approach this problem.  If it is something which can be easily extracted using regex, then that is the best way to do it. If however, you want to use classifiers, here are two questions you need to ask yourself.

One, what does the unlabelled data look like and can you design good features from it? Depending on the kind of feature vector you design, the complexity of the classification task may range from very easy, to impossible. (A perceptron cannot solve XOR usually, except when you provide it with specific linear combinations of the input variable).

Two, what does the labelled data look like? Is it representative of the entire dataset or does it only contain very specific types of format? If it is the former, then your classifier will not work well on files which are not represented in the labelled data.

If you just want to test run a classifier first, you can solve the problem of having more features than training samples by using Regularization. Regularization forces the training algorithm of the classifier to accept the simplest possible solution (think occam's razor).

Almost all Machine Learning related packages in Python will have regularization options you can use, so enjoy.


XGBoost results are not invariant under monotone predictor transformations?

A quick experiment suggests that xgboost makes its splits at midpoints between values of a feature in its training set:

https://github.com/bmreiniger/datascience.stackexchange/blob/master/74634.ipynb

The history turns out to be relatively complex, and possibly ongoing.

In this github issue there's an indication that the midpoint splits are only for small-cardinality discrete features.  That code is gone in the current (at time of posting) version of the code.
It was removed in pull 5251, commit 969ebbc, with further discussion pushed into issue 5096.

In the opposite direction, the function AddCutPoints didn't always exist, but the same discrete/continuous optimization shows up here, commit Jan 2017.  So it seems that historically left-endpoints were used (at least for continuous data), supporting the arXiv paper, but that currently midpoints are used across the board.

The experiment above finishes with the Wisconsin Breast Cancer dataset, which has well over 16 values for the relevant features, and still has splits appearing at midpoints.

Finally, just a couple words about the monotonicity.  First, as the arXiv paper mentions, this is entirely a question of how the model will apply to unseen data and a feature value that lands between values in the training data.  Using left endpoints will always put such a value to the right side of the split, and so any monotonically increasing transformation won't affect that.  A monotonically decreasing transformation will exactly reverse that.  A linear(/affine) transformation will preserve the behavior when using midpoints (and also either left/right endpoints, depending on the sign of the transformation).


Initially in the uppermost node, you have 30 samples or data points that needs to be classified into yes/no category. Out of 30, nearly 27 are with no label and 3 are with yes label.

In the next level, it gets divided on the basis of poutcome value. Records in left side of the tree at level 2 are one with poutcome value is non-existent or fail while that on right hand side are with value success.


How to run a saved tensorflow model in the browser?

You can find exactly that at this site, which offers a handwritten digit recognizer as a static site served from github pages.
Here you can find the article describing how the author did it. You can also have a look at the github repo or directly the html file to understand the how it works. The author also released the colab notebook used to train the model.


How do you find the standard deviation of a dataset over a certain period?

I think you can only do that if your dataset contains a column encoding the date (see Dates and related info) that you can filter by.
See below a simulated dataset of such type.
df <- data.frame("x" = rnorm(4000, mean = 0, sd = 1+(1:4000)/1000), "d" = seq.Date(from = as.Date("2010-01-01"), by = "day", length.out = 4000))

Then it should be pretty standard:
# sd of x over the whole dataset
sd(df$x)
#[1] 3.121845

# define a logical vector identifying the dates of interest
interval <- (df$d >= as.Date("2010-11-17")) & (df$d <= as.Date("2020-11-16"))

# calculate the sd over the dates of interest only
sd(df[interval,]$x)
#[1] 3.227157

# display it as a plot
plot(x ~ d, df, col = ifelse(interval,2,1))

Only, make sure you check what your date format is, as that might depend on your system. Like:
Sys.Date()
[1] "2021-03-21"

This shows that my system expresses the date as "year-month-day". That's the format I used for the filtering in as.Date conversions.
[Note: there might be clever ways to use other formats].


Approaches for implementing Domain specific Question answering System

While the actual "best system" depends heavily on a number of factors including your goals and your resources, it is possible to discuss some general pros and cons to each system.

1. IR Based approaches: Information retrieval approaches allow the algorithm to make effective use of what we might call "explicit knowledge" or hardcoded facts. They can work very well when the answer to the query exists in some form already and where the algorithm simply needs to find this answer amongst a set of all the other possible answers. Such systems typically rely on either an explicit dataset of possible answers or facts, or by treating the web as such a dataset and querying it in some way. IR systems are often the only reasonable choice when the answer cannot be generated from abstract principles. For example, if we built a system to answer trivia questions about movie stars, we would need to have explicit knowledge of which features are associated with which movie stars (i.e. Brad Pitt has brown hair and starred in Fight Club.) No machine learning algorithm can be expected to generate this without the knowledge already present (although machine learning systems with access to such knowledge may serve as effective information retrieval systems.) Due to the external nature of the data with respect to the algorithm, IR systems tend to be very effective for large and rapidly changing data sets, which would otherwise require retraining of the machine learning model or manual reconfiguration of the ontology to handle. It is also worth noting that more complex information retrieval systems may include other systems such as NLP engines to translate the data (ex. natural language text) into a form usable by the IR system.

2. Ontology based approaches: Ontology methods take the most time to implement and are usually the most finicky. They require the iterative hypothesizing of a structured representation of the domain, testing of the representation, and modification of the representation based on discovered flaws. For complex real-world domains with many possible contingencies, this process can take a very long time and be quite frustrating. Because everything is hard-coded, even the best ontology-based systems display a relative degree of inflexibility compared to their machine learning and IR counterparts. Ontologies can be effective, however, when you do not have access to a data set for information retrieval or machine learning training, as the domain knowledge are hard-coded into ontology systems by hand. They can also be useful when the domain is relatively well-structured and where it is important to understand and plan every decision made by the system such as in automated attendant phone systems.

3. Machine learning based approaches: As machine learning approaches extract patterns from data, they are relatively robust to subtleties present in complex domains that were not explicitly built into an algorithm, model, or ontology. They work best when a prediction needs to be made about which "class" or category a given input (or query in your case) belongs to, or when a quantitative prediction needs to be produced from data. For example, if I have a large collection of animal pictured labeled with the type of animal present in these images, I can train a machine learning model to predict which animal type is present in future images, as long as the model has seen enough pictures of this animal that it can extract the patterns in the image that correspond to the image likely representing a lion or a tiger or a bear, etc. This works because there are properties in the image itself that predict which animal it represents and these patterns can be extracted from labeled data (there are also machine learning algorithms that pick out patterns in unlabeled data called unsupervised algorithms, but these are not relevant for your domain of interest.)  Traditionally, machine learning systems are relatively poor at modeling domains where the answer depends not on recognizing a pattern, but having access to knowledge like in the movie stars example above. Machine learning systems are also great because they require relatively little manpower to implement. As you mentioned, they also require access to a dataset, which may need to be quite large depending on the complexity of the domain.

We can roughly summarize the advantages and disadvantages by ranking the methods according to a few criteria:

All of the best systems (ex: IBM Watson) use a hybrid approach, taking advantage of each method for its relative strengths and substituting other methods to address their weaknesses. Depending on the performance you want, a QA system can be built by a single person with some knowledge of any of the above, or may require a team of upwards of 100 engineers.


Which statistical test tells which classifier performs better than the other?

Cochran's Q test

Is a generalisation of the McNemars test and can be used to see if there is a truly better classifier for the metric chosen. You can ofcourse also do pairwise Mcnemare test and draw conclusions from there.

NOTE:

These things are expensive


Choosing a right algorithm for template-based text generation

You give this one a try - generation-caption-for-new-image . This has 2 parts one labeling the image and second generating text for those labeled images.
Your case is similar to this, the difference is - in your case there are templates and in this case there are images.

Please comment if you need help in understanding the code (that code is not mine, but I have gone through that in detail) or you find difficulty mapping this answer to your problem.


Is recall more important than precision for mass mailings?

Neither.  What you really need is for the probability estimate to be accurate.  It's not enough to optimize just one of them (and you can't optimize for two metrics simultaneously, since better precision tends to lead to worse recall, and vice versa).

I suggest you minimize the cross-entropy loss function.  This is designed to help produce accurate estimates of the probability.  In some sense, that will optimize both precision and recall and trade them off in a particular way.  The specifics will depend on what classifier you use.


Is there any proven disadvantage of transfer learning for CNNs?

Based on my experience, not just for ImageNet, if you have enough data it's better to train your network from scratch. There are numerous reasons that I can explain why.

First of all, I don't know whether you have had this experience or not but I've trained complicated CNNs neworks with over 25 million parameters. After reaching 95% accuracy, after convergence, I changed the learning rate to a bit bigger number to find another probable local minimum. I've not found any answer till today but whenever I did so, my accuracy decreased signifincantly all the time and it never imporoved even after more than thosands of epochs.
The other problem is that whenver you use transfer learning, your training data should have two options. First of all, the distribution of the training data which your pre-trianed model has used should be like the data that you are going to face during test time or at least don't vary too much. Second, the number of training data for transfer learning should be in a way that you don't overfit the model. If you have a few number of labeled training data, and your typical pre-trained model, like ResNet has millions of parameters, you have to be aware of overfitting by choosing appropriate metrics for evaluation and good testing data which represent the real distribution of the real population.
Next problem is that you can not remove layers with confidence to reduce the number of parameters. Basically the number of layers, as you yourself know, is a hyper-parameter that there is no consensus on how to be chosen. If you remove the convolutional layers from the first layers, again based on experience, you won't have good learning because of the nature of the architecture which finds low level features. Furthermore, if you remove first layers you will have problem for your dense layers, because the number of trainable parameters changes in this way. Densely connected layers and deep convolutional layers can be good points for reduction but it may take time to find how many layers and neurons to be diminished inorder not to overfit.

If you don't have enough data and there is already a pre-trained model, you can do something that can help you. I divide my answer to two parts for this situation:

The pre-trained model does not have common labels for most of its classes

If this is the case, you can forget all the fully connected layers and replace new  ones. Basically what they do is just classifying the features that the network has found to reduce the error rate. About the convolutional layers you have to consider two major points:

Pooling layers try to sum up the information in a local neighbourhood and make a higher representation of the inputs. Suppose that the inputs of a pooling layer have nose, eyes, eybrows and so on. Your pooling layers somehow attempt to check whether they exist in a neighbourhood or not. Consequently, convolutional layers after pooling layers usually keep information which may be irrelevant to your task. There is a downside for this interpretation. The information may be distributed among different activation maps as Jason Yosinski et al. have investigated this nature at Understanding neural networks through deep visualization where you can read One of the most interesting conclusions so far has been that representations on some layers seem to be surprisingly local. Instead of finding distributed representations on all layers, we see, for example, detectors for text, flowers, fruit, and faces on conv4 and conv5. These conclusions can be drawn either from the live visualization or the optimized images (or, best, by using both in concert) and suggest several directions for
future research and These visualizations suggest that further study into the exact nature of learned representations—whether they are local to a single channel or distributed across several .... A partial solution can be keeping the first layers which find low level features that are usually shared among different data distributions and removing deeper convolutional layers which find higher abstractions.
As stated, the main problem of convolutional layers is that the information they find may be distributed among different activation maps. Consequently, you can not be sure by removing a layer you can have better performance or not.

The pre-trained model has some common classes with your labels

If this is the case you can visualize the activations using the techniques described here. They have shown that although human face is not a label in ImageNet, some of internal activation maps get activated by face. This observation can be seen for other labels too. For instance, netwroks for deciding a scene contains a car or not are usually sensetive to roads and trees. The image below shows that which parts of ouputs get activated for which parts of images. This can help you when you don't have enough data and you have to use transfer learning.

Based on the answer here The standard classification setting is an input distribution $p(X)$ and a label distribution $p(Y|X)$. Domain adaptation: when $p(X)$ changes between training and test. Transfer learning: when $p(Y|X)$ changes between training and test. In other words, in DA the input distribution changes but the labels remain the same; in TL, the input distributions stay the same, but the labels change. Consequently, domain adaption problems also can be considered for the mentioned solutions.


So I guess that if I train a GloVe I could use it just for finding synonyms, or something more?

GloVe (vectors) are not the perfect word representations if you were to find synonyms.
Since GloVe vectors are generated on the basis of the contexts in which they appear (context implies words before and after the word in study within a sentence), you may find antonyms will also have similar GloVe vectors since they too will appear in the same context. For eg.

Consider the two words "good" and "bad" used in the following sentences:

John was a good boy who was injured in the war.
John was a bad boy who was injured in the war.

Here, both the words "good" and "bad" appear in the same context. The context before is "John was a" and the context after is " who was injured in the war."

Hence, their GloVe vectors won't have much of a distinction and you might change the meaning of your sentence completely when spinning for a new word.

To address the above, a very good alternative to GloVe vectors is "retro-fit vectors". Here is the link of the original article. and here is the GitHub link of the actual vectors. since they are learned for semantic similarity. I suggest using these retro-fit vectors since you seem to be interested in lexical substitution of synonyms.


Word2Vec algorithms (Skip Gram and CBOW) treat each word equally,
because their goal to compute word embeddings. The distinction
becomes important when one needs to work with sentences or document
embeddings; not all words equally represent the meaning of a
particular sentence. And here different weighting strategies are
applied, TF-IDF is one of those successful strategies.
At times, it does improve quality of inference, so combination is
worth a shot.
Glove is a Stanford baby, which has often proved to perform better. Can
read more about Glove against Word2Vec here, among many other
resources available online.


Importing Common Constants to R and Python

You should consider storing this sort of data into a format that is more universally accessible.  I would suggest either JSON or YAML. JSON can be readily parsed by both R and Python

Your data would look something like:

{
    "FIRST_YEAR": 1952,
    "IV_TYPES": [
        ["p", 6],
        ["n", 6],
        ["w", 4]
    ]
}


As far as I know, experts systems were popular around the 80s-90s, before the big trend of Machine Learning. They were mostly based on symbolic logic reasoning, as opposed to statistics in ML.

They can probably be considered as one the first stages of ML-based systems: experts systems automate the reasoning steps based on some data, which is a bit similar to ML. However the data was strongly structured (and possibly quite complex) and usually had to be entered manually by an expert. This is the main reason why ML approaches made them obsolete for the most part: ML systems can learn from a vast amount of possibly noisy features with little structure, whereas the cost of preparing the data for experts systems was prohibitive.

Experts systems were indeed a kind of knowledge-based system (probably the first generation), but I think the latter are much more general: knowledge-based system include many different kinds of data base and different methods for processing it.

Note: this answer is based on my general understanding and knowledge of these terms, which is probably correct but not sure ;)


How to train a model to predict a time window than an event will occur on a website

You can use TICK (Telegraf, Influx DB, Chronograf and Kapacitor) stack for the same. You need to install the above mentioned stack on your web server. Chronograph is a visualization tool which gives you information about your server.

Morgoth is a unsupervised learning algorithm which can help you achieve your purpose. You need to combine Morgoth framework with Kapacitor so that the event is triggered once you have an anomaly


The short answer is that usually if you are performing data transforms, you fit on the training data and transform training and test data.
The long answer is that if you are doing purely supervised machine learning then you want to avoid "leakage".

Data leakage is when information from outside the training dataset is used to create the model.

https://machinelearningmastery.com/data-leakage-machine-learning/

I'd read the above link if you want more information. In your case, it just comes down to preprocessing only using information in your training data.


Models that converged before aren't converging anymore in Keras

It was actually just the random weights and incredible luck that I got good convergence the first three tries in a row while didn't most other times afterwards.

I tried setting the seed and found certain seeds that gave me good results every time whereas most other seeds won't converge for many epochs.

from numpy.random import seed
seed(5)
from tensorflow import set_random_seed
set_random_seed(42)


9 and 10 have different schema. For example, a displaced transverse fracture of the right femur would be

821.01RT in 9
S72.321 in 10

10 is also more specific. In the example, 9 doesn't tell you that the fracture is transverse and displaced.

Since ICD10 is basically a better organized and more precise superset of the data represented by ICD9, someone has probably created a mapping. However, I haven't looked into that.


It should be a bug in their server. The fmla variable should have the same contents in your code and in theirs. This is because the last assignment on both scripts is

fmla <- lm(blood_pressure ~ age + weight, data=bloodpressure)


Data science Ph.D. program, what do you think?

It seems to me that the premise of a PhD is to expand knowledge in some little slice of the world. Since a "data scientist" is by nature is somewhat of a jack-of-all-trades it does seem a little odd to me. A masters program seems much more appropriate.

What do you hope to gain from a PhD? If the rigor scares (or bores) you, then what about a more applied area? Signal processing, robotics, applied physics, operations research, etc.


The inductive bias of a Gaussian process (GP) is encoded in the covariance kernel. A GP is a distribution over functions — when we choose a kernel, we are specifying characteristics that we expect the solution function to have, e.g., smooth, linear, periodic, etc.

For example, a common covariance kernel is the squared exponential:

$$k_{SE}(x, x') = \exp \left( - \frac{||x - x'||_2^2}{2l^2} \right)$$

where $l$ is the characteristic length-scale. This kernel specifies that an unobserved point will be similar to each observed point as an exponentially decaying function of the Euclidean distance between the two points.

More detailed explanations can be found in section 2.4 of Andrew Gordon Wilson's thesis or in the book Gaussian Processes for Machine Learning.


Predicting earthquakes using disturbances in DTH TV transmission

I think that if there are disturbances caused by something preceding earthquake, they might be used.

The problem is that you need to find which cause produces that effect and measure it. For example you can team up with geologists, geophysicists or someone similar and try to build as complete hypothesis as possible and then design experiment to gather data. If your experiment would bring some non noise data then you can start to thinking about machine learning algorithms which will work in this situation.

But you might also try to do it on "brute force" way by actually recording DTH TV images in seismically unstable regions and try to correlate those videos with seismic data. Then after some manual examination and categorization you could define (or not if this cause and effect hypothesis is wrong) some possible glitches that are observed and try to develop software that tries to detect them (OpenCV might be useful for example).

IMHO in either way, some domain knowledge related to earthquakes would be more useful on beginning stage, and experience related to machine learning would be more useful on latest stages of such ambitious project.


How many time a recommender system can recommand the same item to an user?

I don't think it matters if you recommend the same song in multiple playlists, just that your recommendations were accurate.

For example, imagine a user has two playlists a rock playlist and a classical playlist. If you recommended Crazy Train - Ozzy Osbourne in both playlists, you could theoretically have a "successful recommendation" in the rock playlist, and an bad recommendation in the country playlist.

The number of times a song appears is a design decision/variable - there is no right answer. You could potentially optimize on in the future using A/B testing (if I limit a song to being recommended x times, do those users then value my recommendations more than the general population?).


Find specific topics with topic modelling

You can use LDA (Latent Dirichlet Allocation), as input data it only needs different collections of text. As output it generates for each document the main topics (Like: Document1:0.3% Topic1, 0.2% Topic5, 0.2% Topic8, 0.2% Topic12, 0.1% Topic3) and for each Topic the different words with the amounts they contribute to that Topic. You can then browse the words of the Topics and manually decide how to name the label of each Topic.


Does resizing the image size, reduce the quality of the images in CNN?

Of course, making them smaller will cause loss of information. Since before you had N x M data points for each image to describe the content of the image, but after resizing you will have n x m (Where n and N denote the number of rows in an image, m and M denotes the number of columns in an image. Also, n <= N and/or m <= M). That is, a small number of pixels will result in less information.
Open CV's resize() function squeezes the image instead of cropping, meaning it preserves aspect ratio, original content but it displays objects or parts in the image with fewer pixels. To achieve it, Open CV uses the interpolation technique. (read more here)
Two solutions you can try:

If your smallest image's size does not differ much from the size of the majority of your image, then resize them to the smallest. Because in that case, if you have a good model, your performance will not be affected severely.

If your smallest image's size differs much from the majority, or in general you have a group of small images and big images which sizes differ a lot, then choose a threshold of minimum size to which you will resize the images and drop the images that have a size less than your threshold.

In both cases, you will lose data or information, it is inevitable. The best practice is to test various possibilities to see which works well. Look at the distribution of the sizes of your images, make your decision accordingly.
If the size of the smallest image is big enough, and the smallest image and the biggest image do not differ a lot in size, I would just resize them. Because it would at least, gives a chance to the model to capture the feature in the image. However, in the second case (dropping the small images), you would not even give that chance to the model.


Regression model to predict probability of rare event

The output of logistic regression is exactly that - the probability of an event happening. If your covariates are informative then your model will do better than just saying "P=1000/900000" everytime, because it might say "P=10000/900000" for a positive event, or even "P=0.9" of a positive event given certain covariates.

If there's no predictive power in the covariates (ie they don't correlate with the positive events) then yes, the model will say P=1000/900000 but that's the way it is.

If you want a binary outcome then you have to decide what threshold of P you choose, based on your fear of false positives/negatives or value of true positives/true negatives. For example, if one false positive means people die, you set your threshold such that you don't get false positives. These thresholds are generally not statistical decisions but based on application logic. ROC curves can help here.


Missing value in continuous variable: Indicator variable vs. Indicator value

As you realise, you are introducing some form of redundancy by using both indicator values and variables; however, it might be a good starting point. Many models such as neural networks and boosted regression will be able to pick up on this, and will likely end up making use of one of the two primarily. This is because, in your particular case, the variable will be 100% correlated with the imputed indicator value.

Using both will give your model as much help as possible to learn about the missing values and their relation to the rest of the data.

My advice would be to as many combinations for which you have time. So try:

indicator value and indicator variable
indicator value
imputation via one or more methods

You can then compare the results of each of these and (assuming you have enough data to make things statistically trustworthy), you will be able to assess, which method is indeed the best in your case.

You could try thinking about how to encode perhaps a little more information into either the value or variable, in order to distinguish them from one another. E.g. you could vary the value (don't always make it 500, as per your example), depending on a metric e.g. a function of how long it has been since the previous missing value.


What do you mean by 'all over the place'? Have you tried actually using scoring measures such as accuracy scores, AUC, etc? These will play a vital role in determining how your model is performing. I'd suggest ROC AUC as to start off since accuracy will be pretty misleading due to the class imbalance.
The class weights you used make little sense. You usually would use something like n_samples / (n_classes * np.bincount(y)) for your weighting, but since sklearn provides automatic balancing of classes, you should probably use that by setting class_weights='balanced': http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html


Does Karl Pearson correlation indicate linear relationship between two variables ? Or it indicates nonlinear relationship or simply the correlation?

The Pearson correlation coefficient does indeed quantify the linear relationship between two variables.

Have a look at one of the many mathematical formulas to compute it, based on a sample of data from two variables $X$ and $Y$:

I like to read this loosely in terms of variance (or spread across each variable). It is asking, how do $x$ and $y$ scale together? This is the covariance, top part of the fraction. This is scaled by the product of their individual standard deviations, like normalizing the covariance by the magnitude of the individual variations $\rightarrow$ bringing the final value into the range $[-1, +1]$.

The geometric interpretation is also quite intuitive and worth reading.

You could also notice the power of the values. The numerator has $x^1 * y^1$ (so a like a squared term), and the denominator multiplied two terms that are each the square root of a squared term, also meaning $x^1 * y^1$. So the final dimensionality is a linear value, as we divide one squared terms by another. (This naïve argument of course neglects the units of $x$ and $y$.)

Here is a nice comparison of many values to gain an intuition - try imagining the linear line of best fit through each of these sets of points, and then how far away the points are from that line. This further away they are, the larger the value of the Pearson correlation coefficient $\rho$. As with normally regression, the sign of the gradient also gives a sign the $\rho$:

Image source

What value do you think the Pearson Correlation would be for a group of points almost all lying on a vertical line parallel to the y-axis?  :)

Compare correlation to regression here.


XGBRegressor vs. xgboost.train huge speed difference?

xgboost.train will ignore parameter n_estimators, while xgboost.XGBRegressor accepts. In xgboost.train, boosting iterations (i.e. n_estimators) is controlled by num_boost_round(default: 10)

In your case, the first code will do 10 iterations (by default), but the second one will do 1000 iterations. There won't be any big difference if you try to change clf = xg.train(params, dmatrix) into clf = xg.train(params, dmatrix, 1000),

References

http://xgboost.readthedocs.io/en/latest/python/python_api.html#xgboost.train

http://xgboost.readthedocs.io/en/latest/python/python_api.html#xgboost.XGBRegressor


Are Deep Neural Networks limited to grayscale images depending on whether you use Seq. or Func. API?

The answer is no, they are not limited.
However, your statements seem to contain multiple misunderstandings, so let's first clarify them:

The sequential and functional APIs in Keras are different approaches for structuring the layers of a neural network. Both can have dense layers and convolutional layers.

Convolutional layers exploit information locality and therefore normally perform better on images, where information locality is key.

Dense layers, on the other hand, can only handle vectors as input, therefore, anything we want to feed as input to a dense layer must be a vector; we can feed image data as input to a dense layer, but we must first remove the spatial organization (i.e. flattening), that is, we must lose the information about which pixel is next to another, and which channel it is in.

With this information in mind, we can conclude that, while we can use images, either grayscale or color, as input to dense layers, we need to flatten the image as a vector, which makes dense layers in general not very appropriate to receive images as input, because the locality information is not used by them.
Update: regarding the ability for dense layers to accept inputs of more than one dimension, the multiplication takes place along the last dimension, as explained in the documentation:

Note: If the input to the layer has a rank greater than 2, then Dense computes the dot product between the inputs and the kernel along the last axis of the inputs and axis 1 of the kernel (using tf.tensordot). For example, if input has dimensions (batch_size, d0, d1), then we create a kernel with shape (d1, units), and the kernel operates along axis 2 of the input, on every sub-tensor of shape (1, 1, d1) (there are batch_size * d0 such sub-tensors). The output in this case will have shape (batch_size, d0, units).

But this is applicable to both the functional and sequential APIs.


What is auxiliary loss in Character-level Transformer model?

Auxiliary losses are additional terms added to your global loss to induce learning further upstream in your model and can be seen as a way to combat vanishing gradients.

An early reference would be how Google's Inception model uses auxiliary classifiers. The general idea is that you take an intermediate output of your model and use it as the prediction in a separate loss function. So during training, your model is acting as both a global model (all parameters subject to that final global loss) and a model composed of sub-models with specific terms applying exclusively to your auxiliary tasks.

In practical terms, you can follow this example. If the link ever dies, here's a generic view:

# let's say we have two auxiliary losses, and thus two auxiliary outputs
final_task_prediction, predictions = model.forward(x)

global_loss = loss(final_task_prediction, y)
intermediate_loss_1 = aux_loss_1(predictions[0], aux_y_1)
intermediate_loss_2 = aux_loss_2(predictions[1], aux_y_2)

# can weight auxiliary losses however we choose
total_loss = global_loss + .4*intermediate_loss_1 + .8*intermediate_loss_2
total_loss.backward()

As an example, say we have an input sequence ABCDEF. To quickly run through the auxiliary losses in the Al-Rfou et al. paper

Multiple positions works as an auxiliary task of "given A, predict B, then given B (and our internal memory of A), predict C" (etc)
Intermediate hidden representations works the same as multiple positions, except intermediate layers also get their own loss terms
Multiple predictions breaks the target prediction sequence into multiple subsequences, so our auxiliary task is "given A predict B,C ; given B, predict C,D" (etc)

Hope this helps!


Output probabilities for each class on tensorflow sigmoid function

You need to print output of sigmoid before tf.argmax is applied. It can be done with "tf.print", tf.print is a network node that does modify values.

y_pred = tf.nn.sigmoid(layer_fc2)
y_pred = tf.print(y_pred ,[y_pred ])
self.y_pred_cls = tf.argmax(y_pred, dimension=1,name="predictions")

Docs : https://www.tensorflow.org/api_docs/python/tf/print


is it a good idea to take the derivative or integral of some features and add them as new features in machine learning?

While performing feature engineering , transforming the existing features is recommended step instead of adding transformed values of the existing feature into the dataset.
Since, if we add these kind of data elements they will be highly correlated with each other and it effects the model performance.
If you have less features and cannot create a model, ask for additional data.


How to measure variance in a classification dataset?

I would start with logistic regression, and get a measure of importance for each of your 20 predictor variables. It's a little tough to understand what you mean by 'variance' in your two classes of good and bad. If you mean variance in your predictor variables that lead to your response, you can calculate the variance of a linear combination of predictor variables (in your logistic regression model) using an appropriate theorem from Wikipedia


Is it better to optimize hyperparameters or run multiple epochs?

Count of epochs is also a hyper-parameter. However, if you meant to ask what to choose to work upon, whether increasing epochs or some other methods like feature engineering , then below is my answer.

Increasing number of epochs is often attributed as hammer stroke to train the model where you yourself often don't have to think much about the data and deepNet does it for you generally. However, it comes at a cost of computational complexity, risk of overfitting, etc.

Instead, it is always advisable to work as much on tasks like feature engineering, tuning different other hyper-parameters while training. In fact, a data scientist is supposed to work on these things preferably and not just blindingly utilising the black-box concept of deepNet.

However, even if you choose to increase the count of epochs, you may utilise the technique called early stopping. It basically says to stop the training at a certain epoch if the validation loss does not improve which you can use without much thinking about the impacts of increasing the count of epochs because if the validation loss does not improve, it will stop there.


Creating dummy variables to match fitted model at inference

I think the answer to this question will solve your problem.

import pandas as pd

train = pd.DataFrame(data = [['a', 123, 'ab'], ['b', 234, 'bc']],
                     columns=['col1', 'col2', 'col3'])
test = pd.DataFrame(data = [['c', 345, 'ab'], ['b', 456, 'ab']],
                     columns=['col1', 'col2', 'col3'])

train_objs_num = len(train)
dataset = pd.concat(objs=[train, test], axis=0)
dataset_preprocessed = pd.get_dummies(dataset)
train_preprocessed = dataset_preprocessed[:train_objs_num]
test_preprocessed = dataset_preprocessed[train_objs_num:]

If that doesn't help, a simple solution would be to add columns of all zeros for each country that the new dataset it missing. This will give you the correct shape of data that your classifier is expecting.


What does it mean when your NN model has "multiple" inputs or outputs in Keras?

A Sequential model is not appropriate when:

- Your model has multiple inputs or multiple outputs
- Any of your layers has multiple inputs or multiple outputs
- You need to do layer sharing
- You want non-linear topology (e.g. a residual connection, a multi-branch model)

The docs suggest that you shouldn't use the Sequential API of Keras when you have such requirements as they also provide Functional API.

Assume that you want to caption an Image automatically. Now in the training time, you need to have images and texts both as Inputs at the same time, right? That's multiple inputs to the network.

Again, Assume that you want to do some image classification for some random image as well as predict the bbox coordinates of the desired object. Now you will have a regression output as well as a probability based output layer, right?

Another example for multiple outputs, Suppose you want to classify an image as to some class as well as find out which color has maximum coverage in the image or what's the color of the object (e.g. a black tee shirt, jeans etc). That will have multiple outputs at the very end.

The last variant possible is combination of both, having multiple inputs and outputs together.

Try to avoid it when your requirements are different or slightly involved...
Sample Image From link


Faraz!
Since you have just 8 parameters it is not time consuming to observe all you parameters and how they are represented for both classes.

You can start with simple information about distribution of parameters over your 2 classes. Check this notebook where an author has explored Titanic data. You can start your explanation in the similar way.

For more tips from a community you need to provide us with more data like what is the size of your data set, are the parameters categorical or numerical, etc.
And actually what is the purpose of your EDA? What is your next step going to be?


How to find what events cluster together?

It's just a simple idea but you could calculate the conditional probabilities of an event given another:

library(plyr)

condProbEvents <- function(d) {
  ldply(colnames(d), function(col1) {
    t(ldply(colnames(d), function(col2) {
      nrow(d[d[,col1] & d[,col2],]) / nrow(d[d[,col2],]) # p(col1|col2)
    }))
  })
}

This gives you values which are easy to interpret, e.g. for p(divorce|marriage): "X% of the people who had a marriage also had a divorce"


What kind of images/objects are the most easy for neural networks to detect?

You are describing the field of robust object detection.
It depends greatly on the specifics of the data and model. Similar to person looking for their keys at night only under a street light, most robust object detection research is related to autonomous driving.
The simplest answer might be something out of sample from the training data. If the marker object is 100% synthetic, a model would quickly learn it since there would be no confusion with other inputs. Again, the definition of 100% synthetic would depend on the training set.


Is there a difference if input nodes have discrete or range value

If categorical values are 1-hot encoded, then there is a node for each item in the category. There would be an input note that indicate the presence or absence of a categorical value. There would be an apple node, a pear node, or a orange node. If apple is present, then the apple input node would take a value of 1; 0 otherwise.
Numerical values have one node per feature. The activation node have higher value if the numerical value is higher. Typically, these input node are rescaled between 0 and 1. The activation of an input node can take on any value between 0 and 1.
In the case of temperature, it depends on how temperature is measured. If temperature is measured continuously, then it can be encoded as a numerical value. If temperature can only take a limited subset of values, then can not be encoded as a numerical value. It would be measured on a ordinal scale.


Want suggestions on choosing open source embedded BI tool

You can try Power BI - it can do all mentioned stuff ( and even more, you can plug in R/python code), but its not open-sourced, though you can go for a free 1-user account.

I guess tableau can do the same and also has "community" version, but im a fan of Power BI, so cant tell more about it.

If you need some custom, build-from-scratch solution, you can go for Shiny - fully build on R, fully open sourced and has free hosting option, can be embedded as an iframe ( will prolly look horrible), but fully customizable and can be tuned the way you want it to be.

Similar to Shiny, but with Python: Dash


How to migrate application which has backend running using DLL methods and front end in JAVA to Apache spark?

You will need to use the Java Native Interface (JNI) for this. Refer to a Stack Overflow question for how to call DLL methods via Java over JNI.


In general machine learning algorithms, if feeded with large training datasets are able to deal both with outliers and multicollinearity. PCA is a dimension reduction techniques and surely helps with multicollinearity. Naïve Bayes assumes independence of its input features (the word naïve comes from this property). So after PCA Naïve Bayes has more chance to get better results.
If you find that PCs are still correlated among the fraud cases I don't think it is an issue. However, you could try to preprocessing your data removing highly correlated variables according to some criteria. The caret library has many functionalities for preprocessing and this tutorial cover interesting stuff besides software applications.

https://topepo.github.io/caret/pre-processing.html

About outliers I am always skeptic about any outlier removal except in the case could be due to miscoding.


Can Gaussian Process be fit incrementally?

I think with GPR, the computational cost increases on an order of N^3, so the amount of time with more data increases drastically.

I don't think the current version of sklearn's GPR implements the kind of incremental fit you are expecting. With larger data and iterations, I suggest implementing your own version on a GPU or somethings since GPR implementation is not that difficult.


Are there certain techniques I can use to reduce the probability to below 0.5 in the stacked model so that it isn't classified the way it currently is?

It's generally not a good idea to try to bias the classifier in order to deal better with some specific instances, because it's likely to make it weaker in with some (possibly many) other instances. The way to do that would be oversample in the training set the instances which will help predict the target instance correctly, but that's a terrible idea, don't do it! :)
In general it's perfectly normal to have some errors, the data can contain noise or even sometimes annotation errors.

My other question is if there is even value in making a hybrid model if the accuracy is the same as SVM's?

If the data is really easy to classify, it's totally possible that stacking learners doesn't improve performance: if the performance of a single model reaches the maximum obtainable on this data, clearly there's nothing to improve.
However it's also possible that the benefit of stacking is not visible in this particular test: in this hypothesis the meta-model is indeed better in general that a single learner, but the test set just doesn't contain any instance on which this can be seen.
A way to check this is to reduce the size of the training set: by making things harder for the classifiers, it's possible that the weaknesses of the individual learners will show up.


CNN is a feed forward neural network that is generally used for Image recognition and object classification. So, the answer it is yes.


How to approach an extremely unbalanced time series dataset

Your dataset is extremely unbalanced, and most of the models would just ignore these 37 samples. After all, failing 0.7% of any test seems to be an extremely good result!

There are several ways to address the imbalanced dataset. I suggest two options: (1) Assign a very high penalty on misclassification of positive samples -- your loss function would be weighted L2, (2) Resampling -- when you draw a random row, assign a higher probability to get the positive sample than negative.

See, for example, https://www.kaggle.com/rafjaa/resampling-strategies-for-imbalanced-datasets for implementation. And How to deal with class imbalance in a neural network?


How much imbalance in a training set is a problem?

There is no strict threshold at which a dataset is considered imbalanced. Accordingly, in Foundations of Imbalanced Learning Gary M. Weiss writes:

There is no agreement, or standard, concerning the exact degree of
class imbalance required for a data set to be considered truly "imbalanced."
But most practitioners would certainly agree that a data set where the most
common class is less than twice as common as the rarest class would only be
marginally unbalanced, that data sets with the imbalance ratio about 10:1
would be modestly imbalanced, and data sets with imbalance ratios above
1000:1 would be extremely unbalanced. But ultimately what we care about
is how the imbalance impacts learning, and, in particular, the ability to learn
the rare classes.

A pragmatic approach could be to fit your models on the imbalanced dataset and check if the imbalance leads to large differences in performance between the classes. But keep in mind that the ultimate goal is to minimize misclassification cost. So performance difference between classes are not necessarily a problem if classes have equal misclassification cost (usually for imbalanced datasets the underlying assumption is that misclassification cost are not equally distributed, i.e. misclassification cost for minority classes are assumed to be higher).
To handle imbalanced datasets sampling-based approaches are most common but they are not limited to under- and over-sampling. There are also hybrid (e.g. SMOTE+Tomek) and Ensemble-based methods (e.g. BalancedRandomForest).
Moreover, there are algorithmic approaches which include cost-sensitive learning (e.g. Weighted Random Forest) and skew-insensitive learning (e.g. Naïve Bayes).
Finally, you can adapt the performance metric to be used. AUROC and ROC Curves are commonly used for imbalanced datasets. However, they can be biased too. Which is why some authors suggest to use Precision-Recall-Curves and AUC-PR instead. Moreover, Precision, Recall and F1 score are common as well.
Note however, that simply using a different performance metric for model selection and model evaluation will not make your models optimize for these internally when being trained. Which is why the other approaches and especially sampling are so frequently used.


A good machine learning approach for distribution of a whole?

The example you describe looks more like an optimization problem, possibly related to operations research but I'm not sure.

Naturally ML can be used to approximate the optimal solution(s) for this kind of problem. For example genetic algorithms are a common way to find the "approximately best" solution to an optimization problem.

This kind of problem can also sometimes be formalized as a regression problem, depending on the exact constraints to satisfy.


How to do scatterplot Visualization of Text Classification

You should look at t-SNE for visualising high dimensional datasets such as words : http://lvdmaaten.github.io/tsne/


Back propagation and Structure of a Neural Network in scikit-neuralnetwork

1)
From what I understand, scikit-neuralnetwork tries to automatically determine the correct input and output sizes by the X and y data you give it when  calling nn.fit. Therefore structure should be:

Input layer with shape determined by X_train
Dense layer with 100 units and maxout activation with 2 linear pieces
Softmax classification layer with as many units as needed for y_train

Seems to use input shape from data here:
https://github.com/aigamedev/scikit-neuralnetwork/blob/b7fd0c089bd7c721c4d9cf9ca71eed74c6bafc5e/sknn/backend/lasagne/mlp.py#L183

And output shape from data here:
https://github.com/aigamedev/scikit-neuralnetwork/blob/b7fd0c089bd7c721c4d9cf9ca71eed74c6bafc5e/sknn/mlp.py#L62

However, note that maxout seems no longer supported: https://github.com/aigamedev/scikit-neuralnetwork/issues/142

2) Yes it uses backpropagation by calling appropriate lasagne/theano functions to create/compile the backpropagation training function:
https://github.com/aigamedev/scikit-neuralnetwork/blob/b7fd0c089bd7c721c4d9cf9ca71eed74c6bafc5e/sknn/backend/lasagne/mlp.py#L50-L103

(Actual training seems to happen here: https://github.com/aigamedev/scikit-neuralnetwork/blob/b7fd0c089bd7c721c4d9cf9ca71eed74c6bafc5e/sknn/backend/lasagne/mlp.py#L316-L335)


What is a subspace and what is a shared subspace?

I don't know what you mean by "In multi label classification we have to share the subspace.", but the concept of subspaces is fairly easy to explain.

  In mathematics, a space is a set (sometimes called a universe) with some added structure.

Source: Wikipedia

The most common spaces are $\mathbb{R}$ (the number line), $\mathbb{R}^2$ (the plane) and $\mathbb{R}^3$ (the space we often think in, with $x,y,z$ axes). Lets assume our main space is $\mathbb{R}^3$. Our data are datapoints in this space. However, we have to write a report. This report has to be printed on paper. Hence we project the data points from a 3-dimensional space to a two-dimensional subspace. So a subspace is just a part of the original space.


Feature selection or Dimension reduction in unsupervised learning

I found Auto-encoders to be the best solution for this.
Performing auto encoder before clustering reduces the dimensionality of the high dimensional data and then the encoder results can be extracted and used for whatever method we want to implement like,

supervised classification
unsupervised clustering etc.

Autoencoders using CNN (encoder and decoder) for image:
https://www.datacamp.com/community/tutorials/autoencoder-keras-tutorial#comment-6125

Autoencoders - its types and usage - LSTM:
https://machinelearningmastery.com/lstm-autoencoders/

for my usecase I should be performing an embedding before feeding it into the autoencoder (CNN/LSTM) with only the encoder so that the reduced dimensions can be used for kmeans clustering.

Hope this helps people who have same question, I wonder how none has come across this situation or haven't replied for this.

Thanks
Arav


ggvis vs. ggplot2+Shiny; which one to choose for interactive visualization?

Well, many months have been passed from this help request. I write this answer to my own request in order to share my experience. I learned ggplot2 and then ggvis as well as Shiny. Shiny can work with both of them, but I found ggvis more structured and lucid comparing to ggplot2. Something which is expectable as the former is being developed based on the development experience of the latter. Moreover, ggvis seems much faster than ggplot2 in quick graph/chart generation, it seems much more suitable for 'Shiny' and creating an applet. However, the negative point is the lack of many features in ggvis since the package is under development and has not become matured yet.

And many thanks to comments here. I have checked Gephi, it wouldn't help. I created my applet which works really fine, however I finally reached to this point that I need to use more powerful tools such as d3js, as one has already suggested.


Policy Gradient with continuous action space

Yes, that is possible. It can be done in the following way:

We assume that the action distribution is guassian, i.e. that we need to learn the parameters $\theta$ of $\mathcal{N}(a|\mu_\theta,\sigma_\theta)$. Let's say that $\theta$ is given by the weights of a neural network, which we find by optimizing the objective
$$\max_\theta \mathbb{E}_{p_{\theta}}\left[ R(s,a)p_\theta(a|s)\right],$$
where $p_\theta(s,a) = \mathcal{N}(a|\mu_\theta, \sigma_\theta)$ and $R(s,a)$ is the cumulative discounted reward. The gradient is then per policy gradient theorem simply $\mathbb{E}_{p_{\theta}}\left[\nabla_\theta R(s,a) \log p_\theta(a|s) \right]$.

In practice we design a neural network to output one $\mu$ per action dimension and $\sigma$ can either be learned or kept fixed. If learned, interpret the output as $\log \sigma$, so it can take en value. To sample the action we use this outputs learned by our network.

See e.g. T. P. Lillicrap, J. J. Hunt, A. Pritzel, N. Heess, T. Erez, Y. Tassa, D. Silver, and D. Wierstra. “Continuous control with deep reinforcement learning,” International Conference on Learning Representations, 2016.


Are real analysis and measure theory essential to learn for data science?

Neither of real analysis or measure theory are necessary for data science. Most of the mathematics you need to know is at the undergraduate level and these courses should suffice:

Calculus
Linear Algebra
Probability and Statistics
Optimization

Most of machine learning involved in data science (that deals with application vs creating novel machine learning algorithms), requires a linear combination of concepts learnt in the above mathematics courses. For example, you can understand enough kernel methods well enough if you understood linear algebra (inner products, matrices etc.).

Also, data science has to do with practice and experimentation. A lot of key concepts become clearer only through experimentation and if you need to understand a new method, the best way is to read up specifically about it and then experiment with it. In this respect, I feel studying an entire branch of involved mathematics is not worth it if your goal is to understand a machine learning method -- you can always ask a Guru in such situations to explain what you're missing at a conceptual level :-)