The right Machine Learning solution for this problem

First things first, columns in your dataframe are called as Feature,
So, The right question for you will be
How to find Co-Relation between features?
As mentioned in the question, You want to find co-relation among them,
SO,
What is Co-relation ?
Answer :Correlation is a statistic that measures the degree to which two variables move in relation to each other.
Example: Ice Cream Sales
The local ice cream shop keeps track of how much ice cream they sell versus the temperature on that day, here are their figures for the last 12 days:

And here is the same data as a Scatter Plot:

We can easily see that warmer weather and higher sales go together. This kind of relation is called as a positive co-relation which means if one variable increase the other gets increased too hence both of the Variables are providing the same information.
In general case, it is better to drop one of them.


One-hot encode those three Stage variables instead of including all three of them. And again, include any of those at all, ONLY if they hold relevance so a pre-hand PCA won't be a bad idea overall.


Training binary classifier on only one data point ( Theoritical question)

It may predict either a cat or a dog depending on your descriptor for cats and dogs, and on your learning algorithm. This is illustrated on the picture below. If the mirrored cat happens to be on the same side of the separating line as the training cat, then it will be classified as a cat. Otherwise, it will be classified as a dog.


Reduce serving time complexity for real-time recommender systems

You write ... the model needs to be evaluated against each product in real-time., which gets me thinking that you use a binary classification (sigmoid in the final layer) architecture with negative sampling for the user/item interactions when training your model.
Have you considered using multi-class classification instead? Thus, for the user only predict once for the entire product catalogue, and selecting the top-k candidates from the softmax-layer. This way, you only need to feed-forward once through your neural net during inference.


What is a "variable index" in the Gaussian perspective?

The motivation behind this diagram is to explain how the 2 dimensions of a 2D Gaussian are related to each other depending on the covariance matrix. The author of the article refers to the dimension as 'variable index'. By reading further in the article, the author explains that as the off-diagonal element of the covariance matrix is 0.9, the 2 dimensions are highly correlated. So if we sample a point from this 2D Gaussian, the first variable-index or dimension of the sample will have almost a similar value to the second dimension (=2) in the example. On the other hand, if the off-diagonal element is 0.0 then the two variable-indices or dimensions will be very different.

This example builds up to the idea of defining a kernel function in the Gaussian Process.


What do "compile", "fit", and "predict" do in Keras sequential models?

Let's first see what we need to do when we want to train a model.

First, we want to decide a model architecture, this is the number of hidden layers and activation functions, etc. (compile)
Secondly, we will want to train our model to get all the paramters to the correct value to map our inputs to our outputs. (fit)
Lastly, we will want to use this model to do some feed-forward passes to predict novel inputs. (predict)

Let's go through an example using the mnist database.

from __future__ import print_function
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras.callbacks import ModelCheckpoint
from keras.models import model_from_json
from keras import backend as K

Let's load our data. Then I normalize the values of the pixels to be between 0 and 1.

(x_train, y_train), (x_test, y_test) = mnist.load_data()

x_train = x_train.astype('float32') / 255.
x_test = x_test.astype('float32') / 255.

Now we need to reshape our data to compatible with Keras. We need to add an additional dimension to our data which will act as our channel when passing the data through the deep learning model. I then vectorize the output classes.

# The known number of output classes.
num_classes = 10

# Input image dimensions
img_rows, img_cols = 28, 28

# Channels go last for TensorFlow backend
x_train_reshaped = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)
x_test_reshaped = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)
input_shape = (img_rows, img_cols, 1)

# Convert class vectors to binary class matrices. This uses 1 hot encoding.
y_train_binary = keras.utils.to_categorical(y_train, num_classes)
y_test_binary = keras.utils.to_categorical(y_test, num_classes)

Now let's define our model. We will use a vanilla CNN for this example.

model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3),
                 activation='relu',
                 input_shape=input_shape))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes, activation='softmax'))

Now we are ready to compile our model. This will create a Python object which will build the CNN. This is done by building the computation graph in the correct format based on the Keras backend you are using. I usually use tensorflow over theano. The compilation steps also asks you to define the loss function and kind of optimizer you want to use. These options depend on the problem you are trying to solve, you can find the best techniques usually reading the literature in the field. For a classification task categorical cross-entropy works very well.

model.compile(loss=keras.losses.categorical_crossentropy,
              optimizer=keras.optimizers.Adadelta(),
              metrics=['accuracy'])

Now we have a Python object that has a model and all its parameters with its initial values. If you try to use predict now with this model your accuracy will be 10%, pure random output.

You can save this model to disk to use later.

# Save the model
model_json = model.to_json()
with open("weights/model.json", "w") as json_file:
    json_file.write(model_json)

So, now we need to train our model so that the parameters get tuned to provide the correct outputs for a given input. We do this by feeding inputs at the input layer and then getting an output, we then calculate the loss function using the output and use backpropagation to tune the model parameters. This will fit the model parameters to the data.

First let's define some callback functions so that we can checkpoint our model and save it model parameters to file each time we get better results.

# Save the weights using a checkpoint.
filepath="weights/weights-improvement-{epoch:02d}-{val_acc:.2f}.hdf5"
checkpoint = ModelCheckpoint(filepath, monitor='val_acc', verbose=1, save_best_only=True, mode='max')
callbacks_list = [checkpoint]

epochs = 4
batch_size = 128
# Fit the model weights.
model.fit(x_train_reshaped, y_train_binary,
          batch_size=batch_size,
          epochs=epochs,
          verbose=1,
          callbacks=callbacks_list,
          validation_data=(x_test_reshaped, y_test_binary))

Now we have a model architecture and we have a file containing all the model parameters with the best values found to map the inputs to an output. We are now done with the computationally expensive part of deep learning. We can now take our model and use feed-forward passes and predict inputs. I prefer to use predict_class, rather than predict because it immediately gives me the class, rather than the output vector.

print('Predict the classes: ')
prediction = model.predict_classes(x_test_reshaped[10:20])
show_imgs(x_test[10:20])
print('Predicted classes: ', prediction)

  Predicted classes:  [0 6 9 0 1 5 9 7 3 4]

The code to print the MNIST database nicely

import matplotlib.pyplot as plt
%matplotlib inline

# utility function for showing images
def show_imgs(x_test, decoded_imgs=None, n=10):
    plt.figure(figsize=(20, 4))
    for i in range(n):
        ax = plt.subplot(2, n, i+1)
        plt.imshow(x_test[i].reshape(28,28))
        plt.gray()
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)

        if decoded_imgs is not None:
            ax = plt.subplot(2, n, i+ 1 +n)
            plt.imshow(decoded_imgs[i].reshape(28,28))
            plt.gray()
            ax.get_xaxis().set_visible(False)
            ax.get_yaxis().set_visible(False)
    plt.show()


What is the purpose of reward threshold in OpenAI Gym?

I did some digging in the gym codebase, and at least as of v.0.18.0, gym itself doesn't appear to be using reward_threshold at all (as opposed to max_episode_steps, which is used to compute the Done signal when stepping in the environment).
So one would have to manually access this field from the env if they wanted to use it.


In Affinity Propagation do the cluster centres minimize mean distance to all other points in the cluster?

No.

AP maximizes responsibility, which is a combination of availability and affinity. Distances only serve as an indirect source to input affinities.

If you want to minimize average distance to the cluster center, use PAM It minimizes the sum of distances to the representatives, and that is equivalent because the number of points is constant.


Multi class Imbalanced datasets under-sampling imblearn

If you're looking for a fast workaround to solve this you have to increase n_neighbors parameter in AllKNN, but I wouldn't recommend using this type of undersampling algorithm for what you want to do!

Explanation:

AllKN is an under-sampling technique based on Edited Nearest Neighbors. These techniques try to under-sample your majority classes by removing samples that are close to the minority class, in order to make your classes more separable. The way they work is that they remove samples from the majority class that have at least 1 nearest neighbor in the minority class. The thing is that if the classes are separable enough and the majority samples have no minority nearest neighbors, they can't be removed!

If you want a technique that undersamples your data in order to get exactly the same number of samples from the minority and the majority class, I'd recommend using a different technique (e.g. ClusterCentroids, which you've used is such). ENN-based undersampling techniqes aren't built for that. You can also read this tutorial which compares different resampling algorithms imblearn.

As a final remark, if possible, I'd recommend oversampling...


How to evaluate the "betterness" of competitive good models?

The typical approach would be to compare (cross-)validation performance of the models, at least if accuracy is the selection criterion.

Other criteria could be

simplicity/ease to interpret
how easy the models could be implemented and/or updated in a productive environment


Is there any standard pattern recognition algorithm in predicting an item which a user will be buying next, given I have the history of the purchases

Take a look at association rule learning (https://en.wikipedia.org/wiki/Association_rule_learning). A really common algorithm is the Apriori agorithm. You could use the package apyori, it works great: https://pypi.python.org/pypi/apyori/1.1.1

Generate association rules over all items bought by a user, not in a single transaction/purchase.


Scikit learn kmeans with custom definition of inertia?

K-means cannot optimize arbitrary measures.

The mean optimizes squared errors. It does not optimize, e.g., Euclidean distances, Manhattan distances, etc. It won't crash, but the solution will not be optimal (not even locally) because the centers are not well placed.

So it makes little sense to add support for another "inertia" inside k-means (nor other distances), as it can't optimize that.

If you want to optimize other distances, there is for example the PAM algorithm, and k-medians (for Manhattan).

There is nothing wrong with computing such a quality afterwards though, but then it belongs into the evaluation package, not in the KMeans class.


Scripting code for class imbalance in Biolabs Orange

With some help from the Orange team, I was able to solve the problem!
Link to thread on github

The following code can be pasted into a Python Script widget, and will balance your classes before training a classifier in Orange:

# Get libraries
import Orange
import numpy as np
from Orange.data import Domain, Table
from imblearn.over_sampling import SMOTE

# How Orange passes data to widget
df = in_data.copy()

# set variables for SMOTE
sm = SMOTE(random_state=42)

# get table of data (X) and class variables (y)
X, y = df.X, df.Y

# resample data and classes
X_res, y_res = sm.fit_sample(X, y)

# Get the target and feature variables
d = Domain(df.domain.attributes, df.domain.class_vars)

# Create a new Orange Table object with the appropriate headers
# This is how Orange passes the data on to the next widget
out_data = Orange.data.Table(d, X_res, y_res)


How can I reduce the volume of data (No column to be dropped)?

You are the domain expert on this, but these are the two practical approaches, I have utilized depending on the use case and effect on performance:
1. Downsample: Let say, randomly choose 5,000 out of 80,000 records. To maintain the same proportion of classes as in the population, go for stratified random sampling.
2. Reduce the precision of measurements (i.e. less decimal points) and aggregate data to capture the frequency of similar records as a new feature. If you have repeating records you can do this without compromising on the precision too.


Linear regression has no way of knowing if features have significance or not. It will find the βs that produce the smallest squared error. That will usually not be zero even if the data is just noise. More features, regardless of significance, give more ways of describing the target variable and get a lower error.
Here is an example where you can see that this holds true even if all features have no significance at all:
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score
import numpy as np
import matplotlib.pyplot as plt

# generate data that is just noise
X = np.random.randn(100, 100)
y = np.random.randn(100, 1)

r2_scores = []

# fit 1-100 features on noise and calc r2
for i in range(1, X.shape[1]+1):
    x = X[:,-i:]
    lr = LinearRegression()
    lr.fit(x.reshape(100, -1), y)
    coef_sum = lr.coef_.sum()
    r2 = r2_score(y, lr.predict(x.reshape(100, -1)))
    coefs.append(lr.coef_)
    r2_scores.append(r2)

plt.plot(r2_scores)
plt.xlabel('Number of features')
plt.ylabel('r2 score')

Which will give you something like:


Alternatives to linear activation function in regression tasks to limit the output

Don't use that activation function shown in the question.  It doesn't do what you think it does.  Instead:

If you want the output to be in the range $[-1,1]$, you can use a sigmoid or tanh activation function in the final layer.

If you want the output to be in the range $[-100,100]$, do the same, then multiply the final output by 100 (a hardcoded constant).

If you want the output to be in the range $[-50,150]$, do the same, then multiply the final output by 100, then add 50.

Hopefully you can now see how to handle any desired range.

After some edits, I see some misconceptions in your question:

Contrary to what you write, there is no reason that the last layer of a regression model has to use a linear activation function.  It's not like there are "regression police" who are going to arrest you for using a different activation function.

You say it is customary to use a linear function at the output of a regression model.  That's not really because those models are doing regression; rather, that's more because they are solving a task where you want range of possible outputs to be $[-\infty,+\infty]$, so of course they're not going to use an activation function that restricts the range.  Now you have a new setting where you do want to restrict the output range -- so it is reasonable to use a different activation function.  You're have a non-customary regression task, so don't be surprised if this means you might benefit from an activation function that is non-customary.
Sigmoid and tanh have been used in other contexts because they do have other useful properties, but that doesn't mean they're not also useful here.  An activation function can have multiple useful properties, some of which are relevant in one setting and some of which are relevant in another.

Sigmoid (also called softmax) is often used in classification partly because in classification we want the output to be in the range $[0,1]$, so it is natural to pick an activation function that ensures that range; and partly because there are some statistical reasons to choose sigmoid (aka softmax).  The former is relevant here; the latter is not.  You're allowed to use the sigmoid function for your task for a different reason than why people use sigmoid for classification.
It's true that some sources have used tanh because of its derivatives, but that doesn't mean it's the only allowed reason to use tanh.  You're allowed to use tanh because of the way it restricts the output range rather than because of properties of its derivatives.

Contrary to what you wrote, sigmoid can be used at the last layer of regression tasks.

Ultimately, I think you are prematurely rejecting plausible approaches without a good reason for doing so.

It's also possible to experiment with approaches where you penalize outputs that are outside the range, instead of changing the last-layer activation function.  Indeed, as long as all outputs in the training set are in-range, a standard loss function (like squared loss) will already do that.  However, it's hard to say how well that will work, or whether it will work better than a clever choice of activation function for the last layer.  The only way to find out is to try it and see.


How to draw neural network diagrams with this particular style?

I asked me something similar as well as I thought that a lot of papers use rather high quality images but it seems that all the authors generate them individually: https://graphicdesign.stackexchange.com/questions/114886/software-to-draw-schemes-quickly
For NNs, there is already an answered question: How to draw Deep learning network architecture diagrams?
Have a look at https://www.quora.com/What-tools-are-good-for-drawing-neural-network-architecture-diagrams and https://softwarerecs.stackexchange.com/questions/47841/drawing-neural-networks


If the model is overfitting you can either increase regularization or simplify the model, as already suggested by @Oxbowerce: remove some of the convolutions and/or maybe reduce the dense layers.

Given that you already have several different types of regularizers present, I can suggest another one for convolutional layers: spatial dropout. By using SpatialDropout2D available in Keras, you can drop entire features from convolutional layers. You can try using it after the first convolutions after C5,C6 and C7 for starters.

But given that you have a very small dataset, I am not sure if there is a lot of room for improvement. It would be easier to comment if you also share the training and test accuracy graphs directly. Anyway, the best way to approach image recognition problems with small datasets is via transfer learning. I suggest you look into it if you do not have to build the model from scratch for some other reason.


np.shape[::-1] reversal of dims and np.moveaxis splitting array

Note that when you do:

pic.shape[::-1]

You only reverse the elements of the shape are of pic. So pic.shape is (3,4,5] and reversed, it's (5, 4, 3).

What happens with the multiple assignment is just that you can assign the elements along the first index to individual variables. For example:

pic = np.array( [['x1','x2','x3'],['y1','y2','y3']])

The first index can be 0 or 1, the second index can be 0, 1 or 2. I can assign the x-vector to a and the y-vector to be like this:

a, b = pic

In [18]: a
Out[18]: array(['x1', 'x2', 'x3'], dtype='<U2')
In [19]: b
Out[19]: array(['y1', 'y2', 'y3'], dtype='<U2')

The call to moveaxis reformats the image, by moving axis 0 to position 2 in the array of axes. My pic doesn't have a position 2 (since it only has 2 dimensions), but I can swap axis 0 with axis 1:

In [11]: np.moveaxis(pic, 1, 0)
Out[11]:
array([['x1', 'y1'],
   ['x2', 'y2'],
   ['x3', 'y3']], dtype='<U2')

And now I can assign (x1, y1) to a, (x2, y2) to b and (x3, y3) to c:

a, b, c = np.moveaxis(pic, 1, 0)

In [14]: a
Out[14]: array(['x1', 'y1'], dtype='<U2')

There is no call to split anywhere here. I think what confused you is just the multiple assignment from a numpy array, which allows the direct assignment of columns to individual variables. In combination with moveaxis this would allow you to split the red, green and blue images in a single command.


Choosing One vs All and One vs One for Multiclass SVM

The main consideration is the number of classes, assume you have $N$ different classes: "one vs all" will train one classifier per class, so $N$ classifiers in total. For a given class $c_i$ the classifier assumes samples with $c_i$ as positives and the rest as negatives. Obviously, this leads to imbalanced datasets, moreover, in "one vs all" the outputs must be calibrated to produce comparable results.

In "one vs one" you train a separate classifier for each different pair of classes, so $\frac{N(N - 1)}{2}$, obviously this is computationally expensive.

For more details see this: 1 and 2.


Visualize performance, % of goal implementation

What information should be shown on the charts are based on what the viewer wants. From your sample charts, the x axis indicates 'date'. For time serial analysis, people usually want to know the trending of the metrics and to predict the performance in the future.

Here are 2 suggestions:

People may want to know how it will perform in the future. Add a trendline. Trendline could help people to predict the performance in the future.
http://onlinehelp.tableausoftware.com/current/pro/online/mac/en-us/trendlines.html
People may want to know how far away from goal. When people mouseover on the points on the metric line, you can try to show how far from current metric to the goal.

Try to understand what information people want to know and visualise them. Hope my answer could help you.


alternatives to pyspark to query a csv file locally (no distributed computation needed)

pandas can do it. It can read in a csv file with a single line and put the data in a dataframe that you can manipulate.


What could be possible features of a textual word?

That is a rather broad question. If you are on a document level, you could (after removing stop words) determine the most important words in your corpus by calculating the tf/idf measure https://en.m.wikipedia.org/wiki/Tf–idf
Then you could define a vector over the top n words and represent every document as a vector of the relative frequencies of the top n words in that document and work on these vectors.
On a sentence level that could work as well, on a word level obviously not. Anyway, information retrieval and computational linguistics are a rather large research area. Maybe the best way would be to start with a book that provides a good overview.

Since you asked for some more specific recommendations:

If you can get access to (or actually want to buy it), definitely this one: Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition.

You can also take a shot this: Sentiment Analysis and Opinion Mining this is probably not your focus, but it covers feature representation to some extent and is for free.

More like a handbook with practical approaches is: Programming Collective Intelligence, look for it at Google, it is also available for free.

Otherwise if you want to look for yourself for books at a library or so, your keywords are "Computational Linguistics" and "Natural Language Processing".

Hope this helps


In industry, what type of new data science algorithms does one develop?

I am no data scientist, only an aspiring one for two years, moving from my background in software engineering and mathematics. So I took some courses, had some interviews, read a lot on the subject online. My opinion:

New algorithms are developed in research centers and at universities. And even then, most algorithms used in companies are already developed, and just optimized even more.
Don't get your hopes up or be afraid that you have to reinvent gradient descent backpropagation.

With developing algorithms they most likely mean data extraction, data cleaning, data preparation for reporting statistics and presenting graphs. Maybe programmatically, maybe just using tooling.

The presented data may give more insights in simple relations in the domain, and maybe insights in more complex questions that can be asked.

You may get to define data flows, get to compare and select machine learning algorithms and tune its parameters. And continuously evaluate model performance in practice.


What is the classification accuracy of a random classifier?

The equation of the classification accuracy for a random classifier (Random guess) is as follows:

Accuracy = 1/k (here k is the number of classes).
In your case, the value of k is 2.

So, the classification accuracy of the random classifier in your case is 1/2 = 50%


Require Guidance - Identifying risk factors

1) I have two classes (Admitted & Not-admitted) 2) Around 25 input variables 3) Run a logistic regression (Statsmodel logit or Scikit-learn?) Do we always have to predict the outcome class to know the risk factors that lead to admission/hospitalization? 5) Then identify the significant risk factors based on p-value.

Not necessary, you can just perform clustering. Than remove features until classes are not distinct anymore. At this point the features that are left are the most important risk factors.


Is there a link between Training, Test errors based on k fold CV and not doing CV?

It is expected that accCV < accTrain: the former is the accuracy on the test folds (averaged over all the splits), so represents models' scores on unseen-to-them data.  Similarly, you would expect accTrain > accTest.

There are two main reasons to evaluate a model, whether by k-fold cross-validation or simple train/test split: for hyperparameter optimization / model selection, or to estimate future performance.  (N.B., k-fold should generally give better predictions than simple train/test split.)  If you make any decisions based on the scores, then they no longer represent unbiased estimates of future performance.  If, in your setup, you make no decisions based on step 2, then you should expect accCV ~ accTest, and there's no real reason to include that step.  If you do make decisions based on step 2, you may expect accCV > accTest, though the gap is probably substantially smaller than the gap in accTrain > accTest.  You may see discrepancies here, due to natural variation in the datasets, or perhaps data leakage.


how to build a predictive model without training data neither historical data

If you do not have data then I think the problem is more of research than  Machine Learning.
Ask your research team to gather primary data about the product by conducting surveys, polls,etc.

Depending upon the data you get from research, you can use some statistical methods like hypothesis testing to solve the problem.


Predicting a timeseries that includes categorical and numeric data

What you are looking for are time series models that are called "dynamic regression models." These can include forecast distance models like linear models or tree-based methods.

While it is possible to do classification with time series models, it is rarer still to do multiclass classification for time series. If you have a high number of classes to predict, it might be difficult.


Convey time lag information to a linear regression model

Linear regressions have fixed number of variables. An alternative could be to run a separate regression for each item group, and add a different number of time lags for each. If you can't do that, I suggest you to find an optimal number of time lags to be chosen for this general model. You can take a look at ACF, and specifically PACF plots to understand how much memory (time dependency) your time series have.

In theory, adding a more time lags should't result in a problem: if the n-th time lag is not relevant to explain your y, then it's parameter will show no statistical significance.


how to identify the unknown class in machine learning?

I have come across a very similar problem lately. It is a case of novelty/anomaly detection as you have mentioned.

There are broadly 2 "working" solutions to these type of problems:

You can check the softmax-posterior probability value of the output layer for all classes and threshold it(say 0.5). If the probability is < 0.5 for all other classes, then definitely this test case is an outlier(our unknown class in this case).
Adding a Garbage class and training it. But, collecting/randomly generating the features for this unknown class may sometimes become tedious and difficult. It is dependent on the application and on the number of classes. If you have smaller number of classes(<10), then you could try this too.

Best would be to try both and see which one best fits the purpose of your application and which increases your prediction accuracy positively.


Class asks me to give self for Naive Bayes Model python

b = BernoulliNB()
b.fit(b, X_train,y_train)

This doesn't work because you're calling the fit method of the BernoulliNB class object you instantiated with BernoulliNB(). This argument says you have an extra parameter because it only accepts X, y.

It's hard to diagnose your second issue without seeing your data. But your y_train is probably formatted incorrectly.


A quick answer.
Note: Checking the references I could access fully, there are no discrepancies between the definitions as long as the terms are translated correctly.
Some definitions:
Relevant items: Are items the user(s) have themselves established as relevant with their actions.
Recommended items: Are items which the recomendation system predicts will be relevant to the user(s).
Concerning your example:

Let’s understand the definitions of recall@k and precision@k, assume
we are providing $5$ recommendations in this order — 1 0 1 0 1, where 1
represents relevant and 0 irrelevant. So the precision@k at different
values of k will be precision@3 is $2/3$, precision@4 is $2/4$, and
precision@5 is $3/5$. The recall@k would be, recall@3 is $2/3$, recall@4
is $2/3$, and recall@5 is $3/3$.


Feature extraction from web browsing history of one website

What you describe uses the data that the paths can offer. You can easily generate features from the data and time. For instance, given the date, you can generate a categorical variable denoting the weekday (Monday, Tuesday, etc..). Given the timestamp, you can generate binary variables to partition the day in four or more partitions: is_morning, is_afternoon etc.. Somebody may only read in the morning or at night, and the aim of these features is to capture this.

Further, you can get the interactions between weekdays and day partitions. Such features may help to distinguish users that in the Sunday mornings read about sports while Monday mornings they are at work and read financial news. Be careful of the overfitting though. Note that trees have been shown to capture such complex interactions; given them explicitly is beneficial though.


NLP Library or routine for Quantitative relationships

It depends on how "generalized" you want your methods. If you have known and fixed set of quantitative relationships (=, <=, >=, …), then you can consider it a classification problem. Given some input string, which category does it most likely belong to? The same goes for entities. Are you assuming it will always be two entities?

If the system should handle an unlimited number of entities with unknown and possibly infinite number of relationships than the problem quickly becomes intractable.

If you assume there will always two entities, then you can apply Resource Description Framework (RDF). RDF goal is to find semantic entities and their relationships. RDF finds triples: a subject, a predicate, and an object. The predicate is "quantitative relationship" between the subject and object. There are a variety of frameworks for extracting RDF from a sentence. The most effective ones depend on building a parse tree of the natural language.


What is difference between "cv2.filter2D" vs Keras "Conv2D" function

So from an architectural viewpoint you are right, both are 2D Convolutional Kernels with size of (3,3).

But there are some major differences. While cv2.filter2D(image, -1, kernel_sharpening) directly convolute the image dis2 = Conv2D(filters=64, kernel_size=3, strides=2, padding='same')(dis1) only constructs a Conv2D Layer which is part of the Graph ( Neural Network). So Keras Conv2D is no operation for directly convolute an image.

Also the weights are different. In the cv2 Part [0,-1,0],
                              [-1, 5,-1],
                              [0,-1,0] are your weights.

dis2 = Conv2D(filters=64, kernel_size=3, strides=2, padding='same')(dis1)

has standard weight initializer which is glorot uniform. so the weights would not even match.

Additionally the weights of a Conv2D Layer which represents the Keras way, will be learned during training stage of the neural network.

However if you neural network would have only this convolution layer and yields the same weights as the cv2 convolution, the result should be exactly the same.


How to make a neural network output a specific number out of a certain range?

There are two ways to do that:

Scale your output data from [0, 2] to [0, 1] and apply Sigmoid activation at the end.

Make your own custom activation function that output everything in [0, 2]

I strongly suggest you no. 1, it's way faster to implement.


How to interpret fit from regression (decision) tree which has used 0 variables

It is hard to tell what is going on without knowing the data and your actual approach/method/model/code.

Just some remarks. Linear regression is parametric and results hinge on the assumptions behind the parameterization. So maybe not too good in a noisy setup.

Single trees are often weak learners. The advantage of trees however is, that there is no parameterization behind. So they are in principle rather flexible. It is state of the art to combine many trees to one ensemble (random forest).

Especially with noisy data, boosting (also tree based) is really good. Boosting makes a lot of very small trees and (by updating weights to specific observations), it focusses on cases which are hard to predict. I guess this would be a thing to try if you work with predictive modeling.

Here are some very basic Python examples for boosting if you want to give it a try: https://github.com/Bixi81/Python-ml


All 3 algorithms are giving very similar results. And looking at evaluation sample size I think training sample is not too large. It indicates me that if there is any opportunity, it's
a) in feature engineering
b) in not predicting for less confident cases
c) getting more data to train more complex algo
a) Feature Engineering - TFIDF or count vectorizer has a real world problem of having test words outside of training vocabulary. If you can use general language vocabulary for embedding both train and test sets, then results should improve. There are open source pretrained embeddings like USE, Glove etc. to do so.
b) Prediction Confidence - Along with class prediction you can also get probability of classification. Then check - below which cutoff of probability your F1 score gets too low. Don't predict for those low probability cases. Most practical systems accept limitation of AI.
c) More data will allow you to learn through more complex algorithms like boosting which may improve results. Hopefully you are already crossvalidating.
Also, based on the cost of error, you can decide whether FP or FN should be prioritized. Accordingly optimize precision/ recall.


best python library for finding sequential rules mining?

Probably you could try Conditional Random Fields (https://github.com/scrapinghub/python-crfsuite) or a Long Short term Memory RNN (Keras+Tensorflow backend)


Best is to start from pre-trained encoding. Please check TFHub (https://tfhub.dev/google/collections/image/1).
I have worked myself with encoding of shoes for a sport fashion companies. Remember that there are many different ways images might be seen as being similar, e.g. shape, color(!) etc... You might need to make a pre-processing choice first to drop some aspects, such as working with gray images, blurring some patterns on the shoes etc...


I don't think k-means is the correct approach to this problem. You should look at doing topic modelling using latent semantic indexing.


Accuracy drops if more layers trainable - weird

Accuracy is not a function of number of features. You might have heard about feature selection processes, and that is the reason we use feature selection or dimensionality reduction.
There is huge theory behind this, but in very generic terms, we need to find out the best features, to make our model least complex, still keeping all relevant features in the model.
One example, can be adding a new feature reduces accuracy, which is highly biased towards one out come and hence it creates inaccuracy in your results.

This may also happen, if all your features are not normalised, and hence the newly added features is biasing your results and hence introducing inaccuracy.


When should we start using stacking of models?

Stacking is going to help most when individual models capture unique characteristics of the data. It is often the case that different architectures perform similarly, if somewhat differently, on the same data. In those cases, ensembling/stacking will only offer slight incremental benefits. In the limit, of you only care about prediction, you can wire up as many different approaches as you can think of. However if interpretability is key, each additional component model will further complicate things.

Your specific question of when to know if it’s worth it or if you’ve reached the limit can be treated like anything else - is your incremental r-square/error/classification accuracy significantly better versus a simpler approach?


Load data from multiple dataframes containing both path and labels in keras

I believe the training will continue if you don't recompile and we put dataset only in the last step.
So, something similar to this snippet should work
train_datagen = ImageDataGenerator(rescale = 1./255, shear_range = 0.2, horizontal_flip = True)

training_set_1 = train_datagen.flow_from_dataframe(dataframe=df, color_mode='grayscale',target_size = (28, 28,1), batch_size = 2)
training_set_2 = train_datagen.flow_from_dataframe(dataframe=df, color_mode='grayscale',target_size = (28, 28,1), batch_size = 2)

model = keras.models.Sequential([ ... ])

optimizer = keras.optimizers.SGD(lr=0.2, momentum=0.9, decay=0.01)
model.compile(loss="binary_crossentropy", optimizer=optimizer,
              metrics=["accuracy"])

for i in list(range(10)):
    history = model.fit(training_set_1,epochs=1)
    history = model.fit(training_set_2,epochs=1)

Definitely, learning can be very noisy based on the difference in variance in datagens.
 Also,history will be reset everytime.


There is no certain answer, only trial and error. Though it should help.

Let me elaborate. Feature importance shows the impact of features on the quality of the model: the number of times there was a split using this feature or gains from splitting on this feature. The better is the feature, the higher is the importance.
But some features could be important due to interactions with other features. Also if some features have a high correlation between them, the importance value could be split between them.
In general removing low importance features should have a small impact on the metric. It could be positive or negative. Just try and see :)


Question about AlphaGo Zero's Neural network architecture?

This sounds like the t means time and the eight features are the latest 8 board states.

That is correct. The description in the article is clear.

I have the feeling the eight features should be the combination of rotated (4) and reflected (2) board states of the current board state. Please correct me if I am wrong.

That is wrong.
This data augmentation can be done by modifying state data stored from each episode, and applied during weight update step (either randomly or exhaustively), because any rotation/reflection of a board should have the same expected value. It is not necessary to provide that augmentation at the feature level.

Board repetition can be easily prevented by keeping tracking of all previous board states and when a new move is attempted, just compare against all previous board states.

A game engine can do that, as could bespoke code added to the agent that was specific to Go. However, a neural network cannot do that unless those previous states are part of the input.

The same is for komi.

If you want the board to correctly predict the value of a state, the nerual network needs to have the current player identity encoded in some way. Having it tracked outside of the neural network's inputs (i.e. outside of state representation) does not help with this.

What if the repetition happened to the last 9th board state?

Most typically in Go, the repetition rule has effects over a relatively short duration, because moves add stones in new positions. The relevant rules are called ko and superko, with superko being optional. When applying the standard ko rule, the repetition that it blocks is only likely to be achievable through play on short timescales (2 steps) that are covered by the AlphaGo Zero representation.
In the unlikely event that a play is blocked due to superko rule and repetition from earlier than 8 steps ago, the game engine would prevent a play that the agent may have assigned a high value to, and the agent could get the value wrong. I suspect that this has little or no impact on performance, as loops in Go board state of this duration are rare and do not occur much in practice.


Algorithms and tools for ranking text as a job description

If I understand the problem correctly, there are several approaches that can be taken.

We'll begin with the least deep learning oriented solution first and slowly move into the spectrum of Deep Learning. This choice is primarily for cost and difficulty reasons. The amount of bugs that you can find with a deep learning solution can be very difficult to understand in certain situations and that results in slower prototyping and ultimately slower time to production.

At the very base, your problem deals with ranking the jobs with respect to how relevant they are to a particular job. The literature for ranking problems is vast and I will suffix my answer with links to these papers or studies. I will also say that instead of dealing with this as a ranking problem there may be another way of going about it. However, this is hinged on the type of data you possess. If you know that each query is certainly looking for a particular type of job. Then, you can break this down into a multi-task problem, where one of the tasks is figuring out whether there is a vacancy or not and the second is figuring out if the vacancy relates in any way to the search query.

Solution 1: Take the dataset and handcraft a set of features that you think are relevant to the process of classifying the output. To do this effectively, you should know certain core features that you think relate the input features to the final label (here I use input features to represent the features that you think represent your features well. For example, some features that may be relevant is information about the person or entity posting the title (in stage 2), if they are a well known company in the domain (this can be accesses through some intelligent web scraping and text retrieval methods). Then, it is possibly more likely for it to be a posting, right? Let us assume now that you have constructed this set of features. Now, for each of the set of features, you have a corresponding label to whether there is a vacancy or not. To turn this approach into a ranking problem is very simple. All you have to do is observe the confidence (the softmax probability is good enough) and the one which has a higher probability is ranked higher). This solution is an easy one to accomplish using even simple feed forward neural networks. You would also benefit from testing out simple classifiers like SVMs or Random Forests. It must also be remembered that the actual sentence must be embedded into some numeric space, like a sequence of vectors in $R^n$. This solution does not detail all of the explicit steps but provides a general framework with which you should be able to attack the problem.

Drawbacks The above method requires a lot of time spent in handcrafting the feature set and there is going to be a lot of iteration because the feature set is never going to be perfect. There is always going to be something that you possibly missed out. Secondly training a good word embedding is not a very easy task. You may have to spend a lot of time getting that running, especially if you want the embedding to be somehow related to your words.

Solution 2 This solution begins to touch the fence of Deep Learning. This solution is a comparison of the attention encodings within the source utterance and the target utterance. The source utterance is, a phrase like "need janitor". Now you should train an attention model over the sequence of words and observe what is the word(s) being given the maximum attention to. Once you know this, the problem becomes a question of consolidating the attentions in some meaningful manner and comparing the distance between the source and target through some metric space. So you should certainly pay attention to attention based models (haha!). Again, there are going to be hiccups in the process of figuring out how much attention actually affects the output and whether it is a good model for your data. Distances between attention will return a vector and you can consider the $\mathcal{L}_2$ norm or any other map from $\mathbb{R^n} \rightarrow \mathbb{R}$.

Drawbacks Attention distances are a good metric, however, they are extremely data centric. For example if the ads are very long, it may be true that the model does not pick up the appropriate words to attend to.

Now we get to some resources that may be useful to go through in order to understand exactly how the different components of the answer work.

https://en.wikipedia.org/wiki/Learning_to_rank
http://www.shivani-agarwal.net/Events/SDM-10-Tutorial/sdm10-tutorial.pdf
https://towardsdatascience.com/learning-to-rank-with-python-scikit-learn-327a5cfd81f
http://times.cs.uiuc.edu/course/598f16/l2r.pdf
https://www.stat.uchicago.edu/~lekheng/meetings/mathofranking/slides/agarwal.pdf

Now for the posts about attention:

http://www.wildml.com/2016/01/attention-and-memory-in-deep-learning-and-nlp/
http://akosiorek.github.io/ml/2017/10/14/visual-attention.html
https://medium.com/syncedreview/a-brief-overview-of-attention-mechanism-13c578ba9129

Finally, my last component of the answer will deal with evaluating exactly how well you have done using metrics. I have added some metrics above in my Answer, however there is another metric which in particular represents the similarity, syntactically between the input query and the output query.

https://en.wikipedia.org/wiki/BLEU


The partial derivative of the cost function with respect to the neuron $i$ ,in  the layer $Z_2$ defined in your questions above, is $\frac{\partial L}{\partial z_i}$, where $L$ is the cost function.

please note that the derivation will be on the neuron level not at the layer level, where $z_i$  is the neuron number $i$ in the output layer/softmax layer/ $Z_2$ layer. In other words $Z_2$ layer consists of 2 elements $z_0$ and $z_1$ and the derivation will be w.r.t the neurons/elements.

I re-arrange your equations to keep things as simple as possible: combining equations 5,6,7 yields:

$L = -\ \sum_{n} \dot{y}_n$ x $ log(y_n)$

Here is a brief derivation

$$\frac{\partial L}{\partial z_i}=-\sum_n\dot{y}_n\frac{\partial \log y_n}{\partial z_i}=-\sum_n\dot{y}_n\frac{1}{y_n}\frac{\partial y_n}{\partial z_i}$$

The softmax function $y_n$ is defined as
$$y_n = \frac{e^{z_n}}{\sum_ke^{z_k}}$$

when n=i
$$\frac{\partial y_n}{\partial z_i} = \color{blue}{y_i(1-y_i)}$$
when n <> i
$$
\frac{\partial y_n}{\partial z_i} = \color{red}{-y_ny_i}$$

now let's substitute $\frac{\partial y_n}{\partial z_i}$

$$\frac{\partial L}{\partial z_i}=-\dot{y}_i\frac{1}{y_i}\color{blue}{y_i(1-y_i)}-\sum_{n\neq i}\dot{y}_n\frac{1}{y_n}\color{red}{({{-y_ny_i}})}$$
$$
\\=-\dot{y}_i(1-y_i)+\sum_{n\neq i}\dot{y}_n({{y_i}})\\=-\dot{y}_i+{\dot{y}_iy_i+\sum_{n\neq i}\dot{y}_n({y_i})}
\\={y_i\left(\sum_n\dot{y}_n\right)}-\dot{y}_i=y_i-\dot{y}_i$$ where $\sum_n\dot{y}_n = 1$

For detailed derivation and explanations please see
https://deepnotes.io/softmax-crossentropy


In Reinforcement Learning can I randomly assign next_states from the state space to my agent while creating transition set?

It depends on your environment. For example, If you environment is a straight line. Let's say that the states are 1, 2, 3 ... 10. The agent here can either move left or right. Now, if the agent is at state 4, and it moves right, according to the logic of the environment, next_state has to be 5.

Now, if you include some sort of a condition that, if the agent reaches state 5, the agent will be randomly moved to any other position, then you can return the next_state to be any random number.

Long story short, the next_state is dependent on what the environment is.


Extractive text summarization, as a classification problem using deep networks

TL;DR:

  Is something like this feasible? (I know that nothing can be said for sure in data science unless tried out, but is it worth the shot?)

Yes

  What kind of features should I feed into the classifier? I already know of word frequency distribution(TF-IDF), sentence position, co-occurance stats, but will these be enough? What additional features should I consider? Or should I consider directly feeding in word vectors?

Feed in word vectors. Deep learning has it's way of figuring out good features like tf-idf,co-occurence etc.

Longer Version:

Input:

Convert all the words to word vectors with a word embedding algorithm like Word2Vec or Glove.
This is usually a good idea since this allows you to represent words in a better semantic (dog, cat, cow,etc will be close) and syntactic (November,December,etc will be close) sense.

(Using tf-idf as a feature hasn't worked for me. I used it to supervise extractive summarization with a neural net.)

How to manage inputs:

This depends very much on how your data is. (Please let me know which dataset)
I assume you have something like [sentence1, sentence2,...] as inputs and an output like [True, False, ...] which implies sent1 is in the summary and sent2 isn't.

If your data isn't in this form, you should convert it into this form.

You haven't specified whether it's Unsupervised or Supervised.

for Supervised:

Use an LSTM. Feed the LSTM the sentence word by word. Once the sentence has ended (marked by a token say  or a full stop) make the LSTM make a prediction whether the sentence should be in the summary or not. Train it based on this.

This is kind of similar to how you would do sentiment analysis: feed in the sentence and then ask if the sentiment is positive or negative.

You can experiment with stacking LSTMs or changing hyper parameters to get better results.

for Unsupervied:

This is a bit difficult.
You could convert the sentences to vectors (Sent2Vec) and hope that important sentences cluster together because they contain important words.

Or you could train an RNN to predict the next character and hope that one of the neurons learns to predict important words/sentences as done by OpenAI's unsupervised sentiment neuron which learnt to predict the sentiment.

The general "Deep" architecture followed these days is : Embed, encode, attend, predict

Check out the links I have posted (in blue), they might work for you.

Note: If possible, please mention your dataset and also how you managed to make abstractive summaries (considering that it is a lot harder than extractive)


How to run a pyspark application in windows 8 command prompt

I'm fairly new to Spark, and have figured out how to integrate with with IPython on Windows 10 and 7. First, check your environment variables for Python and Spark. Here are mine:
SPARK_HOME: C:\spark-1.6.0-bin-hadoop2.6\
I use Enthought Canopy, so Python is already integrated in my system path. Next, launch Python or IPython and use the following code. If you get an error, check what you get for 'spark_home'. Otherwise, it should run just fine.

import os

import sys

spark_home = os.environ.get('SPARK_HOME', None)

if not spark_home:

raise ValueError('SPARK_HOME environment variable is not set')

sys.path.insert(0, os.path.join(spark_home, 'python'))

sys.path.insert(0, os.path.join(spark_home, 'C:/spark-1.6.0-bin-hadoop2.6/python/lib/py4j-0.9-src.zip')) ## may need to adjust on your system depending on which Spark version you're using and where you installed it.

execfile(os.path.join(spark_home, 'python/pyspark/shell.py'))


Using Trainable=True in Keras Embedding obtained better performance

It depends upon where do you want to submit your results that you claim, and what is the submission criteria.

First, it is unclear if "lower error in regression" is training or validation/test error. I am sure that letting Embedding layer to be trainable will adapt it to fit the training set better, but it might cause overfitting and cause higher error on validation/test set.

If for your set of tasks were you use Embedding layer you consistently get lower test error, and the requirement does not specifically say so to use trainable=False for Embedding layer - why bother? It is not cheating.


Why spectral clustering results in disjointed cluster?

First, please note that spectral clustering is very sensitive to the affinity kernel. With the standard RBF kernel, my experience is that spectral clustering often isolates outliers (in the spectral space), leaving clusters with numerous observations which can be separated by great distances. This is a major difference with direct k-means: there is no notion of distance anymore, it's just about connectivity.

In the case shown in your example, the results are "strange" because of the low dimensionality: 1D is typically a case where spectral clustering does not provide "logical" results. In addition, you are quite unlucky on several aspects:

The numbers of clusters (4): try it out with different numbers of clusters, and you will find more trivial results
The positions of observations: move #0 to the left and you may find results that make more sense
The low number of observations: #6 is not considered as an outlier, due to its vicinity to the #5, #8, #9 triplet. Indeed, the more points there are in an area, the largest its influence is. This is also how #4 and #7 can be considered part of the (#5, #6, #8, #9) cluster, rather than the (#2, #3) cluster. Try removing #9 and see how the results suddenly make sense.
The chosen kernel (not tried on my side, but it is likely that the results may vary a lot if you increase the gamma value or change the kernel shape)

TL;DR: your case is an example of how spectral clustering can go wrong with low number of observations and dimensions.


You should look at the Jaccard Index, is the de facto similarity between set of items, where the sets are represented using a boolean vector. In this boolean vector each coordinate represents an item, 1 means the item is present, 0 otherwise. For example: for an universe of items banana, orange and apple. the set banana, orange will be represented by (1, 1, 0). The Jaccard Index is the intersection of the sets over union the sets so for a set (1, 1) it's value is 1.

Cosine similarity is for real-valued vectors, but whether cosine similarity is better than the Jaccard index and vice versa depends on the application. You should do a test on your data and verify which is better, for a discussion see this question


How can I determine the relationship between spam and weekdays?

(started as a comment but it turned out to be longer than expected)
With a dataset like this a simple barplot could be very insightful: on the X axis the days of the week, on the Y axis the frequency, with two bars (spam/not spam using different color) for each day. A slightly more advanced version: two boxplots, one for weekdays the other for weekends. A boxplot is kind of overkill for only 5 (mon-fri) and 2 (sat-sun) values but it's easy to do and shows the big picture.
In order to test whether any difference (e.g. weekdays vs weekends) is significant I think this is a good case for a chi square test.


Are Support Vector Machines still considered "state of the art" in their niche?

SVM is a powerful classifier. It has some nice advantages (which I guess were responsible for its popularity)... These are:

Efficiency: Only the support vectors play a role in determining the classification boundary. All other points from the training set needn't be stored in memory.
The so-called power of kernels: With appropriate kernels you can transform feature space into a higher dimension so that it becomes linearly separable. The notion of kernels work with arbitrary objects on which you can define some notion of similarity with the help of inner products... and hence SVMs can classify arbitrary objects such as trees, graphs etc.

There are some significant disadvantages as well.

Parameter sensitivity: The performance is highly sensitive to the choice of the regularization parameter C, which allows some variance in the model.
Extra parameter for the Gaussian kernel: The radius of the Gaussian kernel can have a significant impact on classifier accuracy. Typically a grid search has to be conducted to find optimal parameters. LibSVM has a support for grid search.

SVMs generally belong to the class of "Sparse Kernel Machines". The sparse vectors in the case of SVM are the support vectors which are chosen from the maximum margin criterion. Other sparse vector machines such as the Relevance Vector Machine (RVM) perform better than SVM. The following figure shows a comparative performance of the two. In the figure, the x-axis shows one dimensional data from two classes y={0,1}. The mixture model is defined as P(x|y=0)=Unif(0,1) and P(x|y=1)=Unif(.5,1.5) (Unif denotes uniform distribution). 1000 points were sampled from this mixture and an SVM and an RVM were used to estimate the posterior. The problem of SVM is that the predicted values are far off from the true log odds.

A very effective classifier, which is very popular nowadays, is the Random Forest. The main advantages are:

Only one parameter to tune (i.e. the number of trees in the forest)
Not utterly parameter sensitive
Can easily be extended to multiple classes
Is based on probabilistic principles (maximizing mutual information gain with the help of decision trees)


Model to detect specific semantic content without labeled data

First, this is not sentiment analysis, which is about quantifying "affective states", i.e. something along the lines of "like / don't like". This would rather correspond to a specific application of general text classification: predicting whether a sentence contains a contact request.
Now about the specific problem: you're right, it could be a good idea to start by identifying some clearly positive sentences using pattern matching. There are many approaches which can be used to expand this initial set of positive sentences:

semi-supervised learning
Using semantic similarity between words (for instance with word embeddings) to find more candidate terms for pattern matching
Using similarity between sentences to find potential new positive cases, then label these manually (this could be done iteratively)

Note that all the above approaches could work but they are biased in favor of the known positive cases, i.e. they risk missing positive cases which have little similarity with the original ones. The only option to avoid this issue is to take a random subset of sentences and label all of them as either positive or negative.


What is the reward function in the 10 armed test bed?

The reward function in the Chapter 2 test bed is simply the "true" mean value for the chosen action, plus a "noise term" which is normal distribution with mean 0, standard deviation 1.

The noise has the same distribution as the initial setting of "true" values. The difference is you set the true values at the start and do not change them, then add noise on evaluation of each reward. The goal for the learner is then to find the best "true" value whilst only seeing the reward.

This matches your understanding as I read it from the question. You could write it like this:

Initialisation:

$\forall a \in A: q_*(a) \leftarrow N(0,1)$

Evaluation:

$R_t = r(A_t) = q_*(A_t) + N(0,1)$

Where $N(\mu,\sigma)$ is a sample from the normal distribution, mean $\mu$, standard deviation $\sigma$

  Why is the reward function chosen this way in the test bed and how does the reward function affect the value estimations and the graphs ?

For a bandit problem to be non-trivial, the reward function needs to be stochastic, such that it is not possible to immediately discover the best action, there should be some uncertainty on what the best action to take is, even after taking many samples.

So the noise is there to provide at least some difficulty - without it finding the best action would be a trivial $argmax$ over the 10 possible actions. The noise does not represent uncertainty in the sensing (although that could also be a real world issue), but variability of the environment in response to an action. The test examples could have almost any distribution (e.g. $p(-1.0|a=1) = 0.9, p(9.0|a=1) = 0.1$ for $q_*(a=1) = 0.0$), the authors made a choice that was concise to describe and useful for exploring the different techniques in the chapter.

The specific reward function will affect the learning graphs. The test bed has been chosen so that ratio of noise to magnitude of "true" values is high. In turn, this means that value estimates will converge relatively slowly (as a ratio to the true values), and this exposes differences between different sampling and estimation techniques when they are plotted by time step.

To answer your concern:

  I guess the reason i'm asking this question is because i'm not
  completely clear how a reward looks like in the real world where i
  don't know anything about q*(a).

In the real world you may need to sense or receive the reward from the environment. Obviously that complicates the test scenario, and doesn't add anything to the understanding of the maths, so the test bed just generates some imaginary distribution for the environment inside the problem. The "sensing" in the test is just assumed with a reward amount defined by the test.

To qualify as a simple (and static) bandit problem, the reward has to be immediately apparent on taking the action, and have no dependency on current state or history. That constrains the problem somewhat - it is not the full reinforcement problem. So real-world examples tend to be about gambling with limited choice on independent repeatable events.


What is the best method for classification of time series data? Should I use LSTM or a different method?

I would not use the word "best" but LSTM-RNN are very powerful when dealing with timeseries, simply because they can store information about previous values and exploit the time dependencies between the samples. That said, it is definitely worth going for it.
It has been proven that their performance can be boosted significantly if they are combined with a Convolutional Neural Network (CNN) that can learn the spatial structures in your data, which in this case is one-dimensional.
Take a look at this state-of-the-art method that combines LSTM and CNN, published in 2019.


How to encode a time series as an image to feed it into CNN?

You can encode time series to images using image encoding methods like Recurrence Plots (RP), Gramian Angular Field (GAF), Markov Transition Field (MTF).

See the following article:

Estebsari, A.; Rajabi, R. Single Residential Load Forecasting Using Deep Learning and Image Encoding Techniques. Electronics 2020, 9, 68.
https://doi.org/10.3390/electronics9010068


Interpreting machine learning coefficients

Neural Networks are notoriously good at performance and bad at interpretability, i.e. it's very difficult (almost impossible) to explain why a particular prediction was made. It's even more difficult to link the prediction with the features, since the NN does a lot of intermediate calculations where all the features play a role.
The notoriously good models for interpretability are the simple ones: a decision tree is very intuitive to interpret, assuming the tree is not too large. A human can actually follow the tree based on the conditions on the features.


How to add bias consideration into logistic regression code?

If I understood correctly, by bias you mean the intercept term in your model, that is, $\alpha$ in the equation
$$
p(y=1|x) = \frac{1}{1+e^{-(\alpha + \beta_1 x_1 + \beta_2 x_2 + ... + \beta_k x_x)}}
$$

If it is the case, you can easily incorporate intercept by adding a colum of ones into your X:

X = np.hstack([np.ones([X.shape[0],1]), X])

So the first colum of $X$ is always one. Then, your model will look like

$$
p(y=1|x) = \frac{1}{1+e^{-(\beta_0 x_0 + \beta_1 x_1 + \beta_2 x_2 + ... + \beta_k x_x)}}
$$
where $\beta_0$ is your bias term and $x_0$ always equals $1$. Thus, your model would be equivalent to the one with explicit intercept.


Would K-means be Appropriate to Use with Four or More Variables?

You can use k-Means clustering in all the dimensions you need. This technique is based on a k number of centroids that self-adjust to the data and "cluster" them. The k centroids can be defined in any number of dimensions.

If you want to find the optimal number of centroids, the elbow method is still the best. You iterate the algorithm changing the value of k each time, and record how much error the clustering is producing; once you're done you plot the error levels against each k value and check the optimal k visually. There is plenty of tutorial on it, you can start here for example.


How can I get total sum of each group by using pandas

Assuming you have the above dataframe as df:

df.weight = df.weight.astype(int)
df.weighted_hour = df.weighted_hour.astype(int)
df["Total_WH"] = df["weight"] + df["weighted_hour"]

df1 = df.groupby(['size'], as_index=False).sum().assign(ind='Total')

df = pd.concat([df, df1]).sort_values('size')


I've done my Masters in Analytics from National University of Singapore.

The answer which I'm going to give is based on my experience.

Ofcourse all the topics are important in the above mentioned list but if you need to prioritize from the topics which you have mentioned above I think the following are very important for any person who is working in a Data Science field. :

Various Probability and Data Distribution: Here you can give basic intro on Probability. You don't need a separate Probability class. A bit more its applications.
Single variable calculus/Multi variable calculus: There are very important, when you try to forecast something this plays an important role.
Graphical Models: Yes, these are helpful in implementing all kinds of community detection algorithms, social networking and many more.
Bayesian Network: This is one of the basic techniques which is important and should be known by all statisticians.
Statistical Models: They need to be exposed to different statistical models as you know there are many models which can perform better in different scenarios, It comes only by practice.

Rest are not so important at the start, you can conduct another session if necessary based on the outcome of the 1st session. Where you can cover all the topics like Linear Algebra (advanced),  Vector calculus, Optimization techniques, Maximum likelihood methods. As you know these techniques would come into play after getting the basic models ready and you would use these if you want to improve the accuracy of the model or tweaking the model WRT to your Business Problem.

I hope this answer may help you.


Can a Neural Network Measure the Random Error in a Linear Series?

This problem is naturally hard. The underlying function that we try to learn is
$$\mathbf{X}=i+s+\mathbf{e} \rightarrow Y=\left \| \mathbf{X} - i - s \right \|_1 = \left \| \mathbf{e} \right \|_1=\sum_d|e_d|$$

where $i$ and $s$ are unknown random variables. For large $i$ and $s$, $\left \| \mathbf{e} \right \|_1$ is naturally hard to recover from $\mathbf{X}$. I found a working example (training error almost zero) by setting the intercept $i$ and slope $s$ to zero!, drastically shrinking the network size to work better with a small sample size (800), and increased the number of epochs to 800, which was crucial. Also, (true value, error) is plotted at the end for training data.

You can work up from this point to see the effect of increasing $i$ and $s$ on performance.

import numpy as np, matplotlib.pyplot as plt

from keras import layers
from keras.models import Sequential
from keras.optimizers import Adam
from keras.backend import clear_session

## Simulate the data:

np.random.seed(20190318)

dimension = 50

X = np.array(()).reshape(0, dimension)

Y = np.array(()).reshape(0, 1)

for _ in range(1000):

    i = 0   # np.random.randint(100, 110) # Intercept.

    s = 0   # np.random.randint(1, 10) # Slope.

    e = np.random.normal(0, 25, dimension) # Error.

    X_i = np.round(i + (s * np.arange(0, dimension)) + e, 2).reshape(1, dimension)

    Y_i = np.sum(np.abs(e)).reshape(1, 1)

    X = np.concatenate((X, X_i), axis = 0)

    Y = np.concatenate((Y, Y_i), axis = 0)

## Training and validation data:

split = 800

X_train = X[:split, :-1]
Y_train = Y[:split, -1:]

X_valid = X[split:, :-1]
Y_valid = Y[split:, -1:]

print(X_train.shape)
print(Y_train.shape)
print()
print(X_valid.shape)
print(Y_valid.shape)

## Graph of one of the series:

plt.plot(X_train[0])

## Sample model (takes about a minute to run):

clear_session()

model_fnn = Sequential()
model_fnn.add(layers.Dense(dimension, activation = 'relu', input_shape = (X_train.shape[1],)))
model_fnn.add(layers.Dense(dimension, activation = 'relu'))
model_fnn.add(layers.Dense(  1, activation = 'linear'))

# Compile model.

model_fnn.compile(optimizer = Adam(lr = 1e-4), loss = 'mse')

# Fit model.

history_fnn = model_fnn.fit(X_train, Y_train, batch_size = 32, epochs = 800, verbose = True,
    validation_data = (X_valid, Y_valid))

# Sample model learning curves:

loss_fnn = history_fnn.history['loss']
val_loss_fnn = history_fnn.history['val_loss']
epochs_fnn = range(1, len(loss_fnn) + 1)

plt.figure(1)
offset = 5
plt.plot(epochs_fnn[offset:], loss_fnn[offset:], 'black', label = 'Training Loss')
plt.plot(epochs_fnn[offset:], val_loss_fnn[offset:], 'red', label = 'Validation Loss')
plt.title('FNN: Training and Validation Loss')
plt.legend()

## Predict.

plt.figure(2)

Y_train_fnn = model_fnn.predict(X_train)

## Evaluate predictions with training data.
sorted_index = Y_train.argsort(axis=0)
Y_train_sorted = np.reshape(Y_train[sorted_index], (-1, 1))
Y_train_fnn_sorted = np.reshape(Y_train_fnn[sorted_index], (-1, 1))
plt.plot(Y_train_sorted, Y_train_sorted - Y_train_fnn_sorted)
plt.xlabel("Y(true) train")
plt.ylabel("Y(true) - Y(predicted) train")
plt.show()


Deep learning: Training from COCO/imagenet weights or from a class-specific trained weights when classify 2 similar objects

If you have a previously trained model to classify only cars, you can use it considering the fact that you have less data. The trained model for cars classification that you have already, would have been fine-tuned on the Imagenet or COCO in the first place. This way I think you would be able to train the model in less amount of time compared to fine tuning on Imagenet weights. Try both the methods once and try to find out the amount of performance increase in terms of time and accuracy over each other.


Basics: What is the correct sequence for preparing simple data for ML?

The same encoding needs to happen on both the train and the test set. So, encode before splitting.


Why do we need to use sysfunc when we call a SAS function inside a SAS macro

Without the sysfunc(), the expression will not be evaluated. You will not be assigning the value of the expression trim(&num) to the macrovariable, but rather the whole expression.

If you want to store the result of an expression, you need to execute that function with sysfunc()

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#z3514sysfunc.htm


How does joint probability generate new data in generative model

The difference between discriminative and generative models is a common question which has some very good answers on Cross Validated, in particular here and here.

  But the question is why; infact HOW? How does joint probability give rise to new data meanwhile conditional probability just works on current dataset?

The word "generative" in generative models doesn't mean that the model generates actual new data additionally to the dataset. It refers to the nature of the theoretical model, in the sense that the generative approach assumes that any sample of data is generated from some distribution, and it tries to estimate this distribution. Once the distribution is estimated the model could be used to actually generate instances following this distribution, but:

usually that's not the goal, the goal typically being to predict the probability of a new instance using the model (inference)
normally this data should not be reused for estimation (i.e. training), since it is artificial data. Additionally it would be pointless since the best that can be achieved is to re-estimate the same model.
naturally the model obtained from estimation is only as good as the assumptions made for its design, and there are usually many such assumptions.


Most of the commonly used techniques are based on time series data (predict tomorrows value based on the values from yesterday, last week, last month, etc)
Since you have some features in your dataset that are not time series (feature_1), you may want to look at Causal Forecasting along with classical time series forecasting. One example of Causal Forecasting the Vector Auto Regressive model (VAR), combined with Granger Causality to look at the relationship over time between different time series and build a model to predict future events.
Definition of causal forecasting:
"Causal forecasting is the technique that assumes that the variable to be forecast has a cause-effect relationship with one or more other independent variables. Causal techniques usually take into consideration all possible factors that can impact the dependent variable"
reference:
https://www.brillio.com/insights/choosing-the-right-forecasting-technique/
other references:
causal:
https://towardsdatascience.com/granger-causality-and-vector-auto-regressive-model-for-time-series-forecasting-3226a64889a6
https://courses.edx.org/asset-v1:MITx+CTL.SC1x_1+2T2015+type@asset+block/w4l1_causalmodels_ANNOTATED_FINAL.pdf
classical:
https://machinelearningmastery.com/time-series-forecasting-methods-in-python-cheat-sheet/


What is the first tool to learn start your your data science projects?

This question was probably asked million times. Please try to find answers berfore you ask "where to learn start".


Eigenvectors and eigenvalues for natural language processing

Latent Semantic Analysis (LSA) relies on linear-algebraic decompositions (e.g. SVD), which in turn involve eigenvectors/values (see here).

Not sure if this is quite what your question is driving at, but in general, eigenvectors are useful in data analysis because they define some "natural" direction in the data. For example, the eigenvectors of the covariance matrix of some data are all perpendicular to one another, and the i'th one points in the direction of i'th greatest variance in the data. In other words, the first eigenvector points in the direction where the data's variance is greatest, the second one in (perpendicular) direction of second-greatest variance, and so on.
This is why eigenvector-based decompositions can be so useful in feature selection and dimensionality reduction. In informal terms, they transform the data into perpendicular features that are aligned with some "natural" axes in the data.


In general, the average reward setting replaces the discounted setting in continuous tasks. It relies on there being a long term stable distribution of states under any particular policy (this is called ergodicity) - and in this will usually be true for continuous MDPs that don't have absorbing states.

If you see an update rule in the discounted setting that looks like this (for Q learning):

$$Q(s,a) \leftarrow Q(s,a) + \alpha(r + \gamma\text{max}_{a'}Q(s',a') - Q(s,a))$$

Then you replace the discounted TD error by the differential TD error:

$$Q(s,a) \leftarrow Q(s,a) + \alpha(r -\bar{r} + \text{max}_{a'}Q(s',a') - Q(s,a))$$

where $\bar{r}$ is the mean reward per time step under the current policy. You can estimate this simply from the rewards seen so far.

  I searched a few articles, but could not find any practical answer.

See Reinforcement Learning: An Introduction (Second Edition) chapter 10, sections 3 and 4 for a more thorough description and more examples.


Why does PCA assume Gaussian Distribution?

TL;DR

PCA does assume normal distribution of features  See p.55 SAS book1 or Rummel, 19702 or Mardia, 19793.
If you expect the PCs to be independent, then PCA might fail to live to your expectations.
Assuming that the dataset is Gaussian distributed would guarantee that the PCs are independent.

Long Answer
PCA doesn't assume the dataset to be Gaussian distributed
Most of the sources I have found (e.g. wikipedia) don't list Gaussian distribution as a requirement of PCA.
Moreover, it seems that Shlens himself doesn't believe that anymore:
I found 2 more versions of Shlens' tutorial: version 2 and version 3.02. The latter seems to be the current version (as Shlens' web page links to it), so I will refer only to version 3.02 in my answer.
In version 3.02, the paragraph you quoted was removed from the "Summary of Assumptions" section, so that currently, the section lists only the following assumptions:

Linearity
Large variances have important structure.
The principal components are orthogonal.

When might PCA fail to live to our (false) expectations?
In page 10 Shlens gives an example for when one might see the result of PCA as a failure, and then explains why PCA didn't really fail:

The solution to this paradox lies in the goal we selected for the
analysis. The goal of the analysis is to decorrelate the data, or
said in other terms, the goal is to remove second-order dependencies
in the data. In the data sets of Figure 6, higher order
dependencies exist between the variables. Therefore, removing
second-order dependencies is insufficient at revealing all
structure in the data.

i.e. PCs are guaranteed to be uncorrelated, so that's exactly what we should expect them to be. However, if we expected the PCs to be independent, then we would consider PCA to fail when the PCs aren't independent (e.g. the examples in figure 6).
(See this answer for another explanation of this paragraph.)
How can the assumption of Gaussian distribution help with our (false) expectations?
If we assume that the original dataset is Gaussian distributed (i.e. the features are jointly normally distributed), then by definition every linear combination of the original features is normally distributed.
Each of the PCs given by PCA is a linear combination of the original features. Thus, also every linear combination of the PCs is a linear combination of the original features, and so every linear combination of the PCs is normally distributed.
So, by definition the PCs are jointly normally distributed. PCA guarantees that the PCs are uncorrelated, and therefore they are also independent.
(Note that in the original paragraph quoted in the question, Shlens seems to claim that each of the original features should be normally distributed. However, I believe that was a mistake, and he actually meant that the original features should be jointly normally distributed (I deduced that's what he meant mainly from footnote 7 in page 10 in version 3.02). This answer explains why these conditions are not equivalent in the 2D case. Similarly, they aren't equivalent for any dimension $>1$.)
Thus, under the assumption that the original dataset is Gaussian distributed, PCA guarantees that the PCs are independent.


Traditional Predictive Analytics vs Machine Learning Methods

This question is very hard to answer because ML is very new and not as semantically and academically defined as statistics.

However, it helps to see the problem a bit different by focusing on tools and methods as well as goals and use cases.

Per se machine learning uses statistical and mathematical algorithms to solve computational problems and specifically problems of prediction. This is true for traditional predictive analytics and tools as well.

A random forest model is not intrinsically traditional or ML and indeed I can fit it in SPSS as well as in python.

So what if any are the differences:

First, we have to understand that ML comes from a different domain than classical statistical analysis. For many cases, there will be no real difference but a CS student may call it ML while a Sociologist will call it predictive analysis.

So let's look at more specific questions of you:

Why not use STATA and SPSS?

You can! Indeed STATA and SPSS do have ML capabilities themselves and could be used to model modern ML algorithms. However, for many specific use cases in the ML domain, STATA and SPSS lack computational power and the ability to model large data sets efficiently.

Why not use traditional models like linear regression, etc. all the time?

Not every problem and every type of data fit classical methods. Linear regression, for example, cannot cope with sparse data and large instances of NAs, it cannot predict nonlinear relations and collapses really fast if we use a lot of predictors (a simple image can be converted to 786 predictors for example).

Additionally ML methods are just updating classical predictive analytics by implementing them using state of the art technology. ML is different from traditional statistics mainly in usage, where we have stuff like incremental learning and self-optimization, etc.

Also please understand that there is a huge difference between classical ML algorithms like boosted trees, random forest, Naive Bayes, etc. and deep-learning which is really, really different.


Standardization of variables in log-scale

There are many ways to do feature scaling, and it's hard to know which one is better (if you find any white paper on this please comment below). I would say that if you have outliers, nonlinear transformers such as applying the log are good options, but there are many others (see this great sklearn documentation page on this).

Regarding your question, it depends. You must do some exploratory analysis to check the variable's distribution on each configuration. If you see that your variable's histogram is "good enough" (in terms of a well-defined distribution -- sorry to use too general language), then go ahead and use it without further standardizations.


How to calculate the Probability for the Unconditional Node in the Bayesian Belief Network?

As the comment says, Burglary and Earthquake only have prior probabilities in the Bayes net. These priors are not calculated from other variables/distributions. They are just assumptions in this example, or, sugarcoated, expert knowledge. In fact, it is often hard to find good priors (from expert knowledge). Extracting them from large non-biased datasets can help. Anyway, one needs to understand the dataset and the context/circumstances/constraints of its collection.


Recurrent Neural Networks Over Multiple Documents Over Time

A simple implementation of such a network would be:

Input -->
Embedding layer -->
LSTM layer -->
Softmax layer

This would allow the embedding layer to learn your document representation, and the lstm layer to learn states based on the observed sequences of those embedding instances, and finally the softmax layer to interpret these states at the account level as "good" or "bad".


The Dropout layer induces randomness (noise) in the training, because random neurons get disabled in every epoch. This leads to slightly different results per training, but the overall performance should be similar, especially for a large amount of epochs.

In order to set the seed for the Droupout layer, you should modify the seed=None argument when you initialize the layer as keras.layers.Dropout(rate, noise_shape=None, seed=None), as explained in the official webpage.


Predicting binary target value based on unlabelled features

You have lots of choices here. You did not say whether the Fi are categorical or numeric. If numeric, logistic regression is a simple and obvious place to start. Logistic regression also works with categorical variables, but best if the number of such variables is not large and the number of categories is small. The logistic regression will let you know if anything is going on at all, but it may not give you the best predictive power.

For a small number of categorical variables, I would try a log-linear model.

Assuming more variables:

If categorical, then I would try a decision tree. Decision trees also work with numerical variables or both -- so it's a good second choice either way, but more suited to categoricals.

If you are getting nice results from the tree and the number of variables is large, I would then move to a random forest. These don't add much, in my experience, when the number of variables is small (say 30 or less), but they can greatly improve the stability and predictive power of your model when you have a large number of variables.

If the variables are numeric, a support vector machine, or a Gaussian classification model, would improve on your logistic regression.

Note. I have a statistics background, rather than a machine learning background, so I tend not to take my explanatory variables at face value. It's nice to get the children off the street, so if the number of variables is not super huge, I might try a lasso regression to see if I can drop any of the variables. If a number of your explanatory variables do not actually give much information about the target, they will basically add noise and instability to your model. But I'm old fashioned. A lot of people just throw everything in the hopper and leave it at that.


Is LSTM a proper implementation for sequence classification

So, from what I gather, the task is to identify positive and negative sequence of digits, which abide by certain rules.
Depending on the rules themselves: for example if there are a small number of explicit and primitive rules (like each sample sequence must only have one of each digit), then might be better to hard-code the rules into a function and feed sequences through that function.
Machine learning is ideally used when you do not know the rules (function) for how the input is translated into the output.
 If you do not know the rules, then an LSTM would be a good idea since it will account for the sequence of digits themselves, when classifying the sequences. The input would be the sequence of digits (possibly normalised [i.e. divide by largest digit = 9] e.g. 1 would e represented as 1/9, etc.)
Then this would be a many-to-one architecture, where you feed in to the model the whole sequence of digits and then feed this output into a final softmax layer over the two classes to give you a probability distribution of the classes (i.e. how likely is this sample to be positive?)
A standard neural network would not be recommended since when you feed input into a neural network, the data is fed in parallel and does not take into account the ordering of the digits, which appears to be fundamental to your task.
If you did want to use a neural network, you could potentially use positional encodings so that you can factor for ordering of the digits (https://medium.com/nlp-trend-and-review-en/positional-embeddings-7b168da36605 in the context of Natural Language, but same would apply to your problem).


Feature relevance in PCA + kmeans algorythm

If they are highly correlated, probably you can not easily tell which feature leads to a happy country. My suggestion is to perform multicollinearity test before fitting any model to remove highly correlated features. After that, there a chance that you be able to get more insights about the pattern in your data.


SVM SMOTE fit_resample() function runs forever with no result

This is expected and is not related to SMOTE sampling.

The computational complexity of non-linear SVM is on the order of $O(n^2)$ to $O(n^3)$ where $n$ is the number of samples. This means that if it takes 0.8 seconds for 7.5K data points, it should take [3, 48] minutes for 115K, $$[(115/7.5)^{2} \times 0.8, (115/7.5)^{3} \times 0.8]s=[3,48]m,$$and from 16 hours to 175 days, 11 days for $O(n^{2.5})$, for 2M data points.

You should continue using sample sizes on the order of 100K or less. Also, it is fruitful to track the accuracy (or any other score) as a function of samples for 1K, 10K, 50K, and 100K samples. It is possible that SVM accuracy stops improving well before 100K, therefore, there will be not much to lose by limiting the samples to 100K or less.


How to train neural network that has different kind of layers

The different layers you describe can all have gradients calculated using the same back propagation equations as for a simpler MLP. It is still the same recursive process, but it is altered by the parameters of each layer in turn.

There are some details worth noting:

If you want to understand the correct formula to use, you will need to study the equations of back propagation using the chain rule (note I have picked one example worked through, there are plenty to choose from - including some notes I made myself for a now defunct software project).
When feed-forward values overlap (e.g. convolutional) or are selected (e.g. dropout, max pooling), then the combinations are usually logically simple and easy to understand:

For overlapped and combined weights, such as with convolution, then gradients simply add. When you back propagate the the gradients from each feature "pixel" in a higher layer, they add into the gradients for the shared weights in the kernel, and also add into the gradients for the feature map "pixels" in the layer below (in each case before starting calculation, you might create an all-zero matrix to sum up the final gradients into).
For a selection mechanisms, such as the max pooling layer, you only backprop the gradient to the selected output neuron in the previous layer. The others do not affect the output, so by definition increasing or decreasing their value has no effect - they have a gradient of 0 for the example being calculated.

In the case of a feed-forward network, each layer's processing is independent from the next, so you only have a complex rule to follow if you have a complex layer. You can write the back propagation equations down so that they relate gradients in one layer to the already-calculated gradients in the layer above (and ultimately to the loss function evaluated in the output layer). It doesn't directly matter what the activation function was in the output layer after you backpropagate the gradient from it - at that point the only difference is numeric, the equations relating deeper layer gradients to each other do not depend on the output at all.
Finally, if you want to just use a neural network library, you don't need to worry much about this, it is usually just done for you. All the standard activation functions and layer architectures are covered by existing code. It is only when creating your own implementations from scratch, or when making use of unusual functions or structure, that you might need to go as far as deriving the values directly.


What are named entity advantages over strings?

The comparison between named entity and string is irrelevant, because the concept of named entity doesn't belong to data types such as string or numeric values. Of course a named entity is usually represented as a string but so is a text document, a cryptographic key or a translation of a text to Vietnamese: what matters here is the semantics, not the technical representation.

The reason why named entities (NEs) are often offered special treatment is because they are particularly relevant for certain tasks and are notoriously difficult to detect and analyze:

The task of Named Entity Recognition (NER) consists in detecting named entities in a raw text document. It's not a trivial task, the problem is still an active area of research.
Even after having been identified, named entities are often difficult to disambiguate. The same entity may appear under many different variants for various reasons:

"John Smith", "J. Smith" and "John A. Smith" may or may not be the same person.
"The president" and "Donald Trump" may or may not be the same entity.
"Big Apple" and "New York" represent the same entity, but not "big apple" and "New York".
...

Of course when one is provided with the result of the NE recognition/disambiguation process, they can process NEs like any other piece of information... but that's because all the hard work about NEs has been done before.


Partial Derivative - Pattern Recognition Bishop section 2.3

$$\frac{\partial}{\partial \mu} (x_n^Tx_n)=0, $$$$\frac{\partial}{\partial \mu}( -\mu^Tx_n)=-x_n$$
$$\frac{\partial }{\partial \mu}(\mu^T\mu) = 2\mu$$
Note that if $A$ is symmetric, then $$\frac{\partial }{\partial y}(y^TAy)=2Ay.$$

\begin{align}\frac{\partial }{\partial \mu}\left(-\frac12 (x_n-\mu)^T\Sigma^{-1}(x_n-\mu) \right)&=-\frac12\frac{\partial }{\partial \mu}\left( (\mu-x_n)^T\Sigma^{-1}(\mu-x_n) \right)\\
&=-\frac12\left(2\Sigma^{-1}(\mu-x_n) \right)\\
&= \Sigma^{-1}(x_n-\mu)\end{align}


Low prediction/classification accuracy due to imbalance in data feeding

When the data is highly imbalanced, accuracy could be a bad measure of model performance. Instead consider precision and recall values, which separately takes into account the no of positive and negative samples. One idea to improve the performance is to use class weights (generally inversely proportional to the no of samples in that class) while calculating loss metric. This makes the model understand that class with less samples should be given more priority while training.


Tools suitable for semi-automatic video labeling?

You could use some tracking lib. Adrian Rosebrock gives nice overview on his blog.


Max depth for a decision tree in sklearn

There is an assumption in the statement if I make a split in the middle. The assumption is the tree will always split at the middle value = the median value so half the values go right and the other half go left. The split could be anywhere. And importantly the split focuses on the number of records at each value (think histogram).

Lets take the 100K values and 1m records. The root split could be, the records with the max value goes right, all other records go left. Then the next split on the left says the records with the max value of those 99,999 values go right, all other records go left. And so on. In this case it peels off one value, and all records with that value, at each split.

That is an extreme example but it illustrates the point. The split could be the min, max or anywhere in between. The number of records at each value is what is important.

You can research the answer to your tree by exporting the tree which will show you the splits and the split statistic for each node.


TypeError: 'GridSearchCV' object is not callable - how do I use a pickle of an SVM (Scikit-learn)?

Most sklearn model instances are fitted using the fit method.
Same goes here - https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html.

Change the last line to model.fit(cv.transform(X)) and it should work.


Hinton advocates tuning dropout in conjunction with tuning the size of your hidden layer. Increase your hidden layer size(s) with dropout turned off until you perfectly fit your data. Then, using the same hidden layer size, train with dropout turned on. This should be a nearly optimal configuration

  A good initial configuration for the hidden layers is 50%. If applying dropout to an input layer, it's best to not exceed 25%.

By intuition I'd like to dropout fewer neurons on the layers next to the input and drop more when approaching the end layers

If I were to try to generalize, I'd say that it's all about balancing an increase in the number of parameters of your network without over-fitting. So if e.g. you start with a reasonable architecture and amount of dropout, and you want to try increasing the number of neurons in some layer, you will likely want to increase the dropout proportionately, so that the same number of neurons are not-dropped. If p=0.5 was optimal for 100 neurons, a good first guess for 200 neurons would be to try p=0.75.

Also, I get the feeling that dropout near the top of the network can be more damaging than dropout near the bottom of the network, because it prevents all downstream layers from accessing that information.

As to why 0.5 is generally used, I think its because tuning things like the dropout parameter is really something to be done when all of the big choices about architecture have been settled. It might turn out that 0.10 is better, but it takes a lot of work to discover that, and if you change the filter size of a conv-net or change the overall number of layers or do things like that, you're going to have to re-optimize that value.
So 0.5 is seen as a sort of placeholder value until we are at the stage where we are chasing down percentage points or fractions of a percentage point.

Original Paper and the opening paragraph is from the original paper...