Mapping sequences of different lengths to fixed vector - Python

A recurrent neural network (RNN) is probably what you want to look into. It has exactly that capability of dealing with variable length input sequence. In fact, currently some of the most successful applications of RNN are in the NLP area, where the inputs are sentences of varying size. Just google recurrent neural network LSTM and you will find lots of tutorials.


How to deal with missing values in the survey data to perform Paired sample t test

You simply cannot use these data points for this test, you have to use only the data points for which both variables have a value. This will make the sample smaller, so it's less likely to result in a significant difference.


Struggling to understand GCNNs (Graph Convolutional Neural Networks)

The name "Graph Convolutional Neural Network" is a bit misleading, as no "traditional" convolutions (like in the context of CNNs) take place at all. You are correct that it doesn't really make sense to perform convolutions on the adjacency matrix of a graph. The thing that GCNNs have in common with CNNs is that there is a concept of a "local neighbourhood" which is exploited.

In CNNs, this neighbourhood consists of the surrounding pixels of each pixel. A linear transformation (discrete convolution) is applied to the pixels in the neighbourhood, before being passed through a nonlinearity.

In GCNNs, however, the neighbourhood for each node is given by the set of other nodes that share edges with the node. The representations of each node are averaged with the representations of the nodes in their neighbourhoods before having a linear transformation applied and subsequent nonlinearity. The method for performing the local averaging can be done using some matrix arithmetical tricks with the adjacency matrix, which is perhaps what you got confused about.

In the simplified version, they remove the nonlinearity step which vastly simplifies the computation of the hidden representations and the linear transformation step.


Multilabel user classification based on multiple posts

My first idea would be to concatenate all the posts for each user and create a tf-idf vector which I would use for a classifier, but that way I would lose information from each individual tweet.

This is the way I would do it too, I think there is no way to preserve the individual information of tweets. But it's more valuable to have the summarised information of tweets for an individual person.


improving performance for a limited dataset with noisy images, pattern recognition

There are some techniques that you can research and apply. My first advice would be decrease the number of the neurons that you implemented already on your hidden layers. You can use some regularization and dropout functions. There are some denoising techniques as well if the problem is exactly this denoising data. I would recommend you to detect the real problem because usually there is a method calls "data augmentation" to overcome overfitting problems which increase the dataset with noisy data in a logical way.
As I mentioned above there are some techniques for denoising. Here is the link that you can look for more details about them. Also there are further techniques to approach this denoising but I highly recommend to detect your exact problem and improve your question.
Maybe it is related to your network modelling because 6% is very low. You should get more useful data at the end with this much dataset.


How to find the ranges in Equal frequency/depth binning?

As far as I can see the choice of the bin size /frequency is arbitrary in those examples. Frequency binning is simple choosing you bin boundaries in a way that the bin content size is the same. For the frequency approach it looks like the order the elements by size and calculate the bin edges in the middle between the highest element of bin A and the lowest of bin B.

If you want to be really fancy you can use methods like bayesian blocks that actually choose bin size dynamically with respect of information content.


Website for Datasets - Miles and Shevlin book, "Applying Regression & Correlation"

That page is archived at https://web.archive.org/web/20161024210121/http://www.jeremymiles.co.uk/regressionbook/ , which will take you to https://web.archive.org/web/20160412090429/http://www.jeremymiles.co.uk/regressionbook/data/index.html .
Some of the datasets are available there; I imagine that some others were not crawled. Certainly I successfully obtained data1_1.xls from there. Do feel free to contribute to Internet Archive if you found their service useful.


How can I save my learning rate on each finished epoch using Callbacks?

You may write a Custom Callback and save the LR in a file.
You will get it by - self.model.optimizer.learning_rate
 Custom Callback - Keras docs
class CustomCallback(keras.callbacks.Callback):

    def on_epoch_end(self, epoch, logs=None):

        print("LR - {}".format(self.model.optimizer.learning_rate))

my_callbacks = [ CustomCallback() ]

LR - <tf.Variable 'Adam/learning_rate:0' shape=() dtype=float32, numpy=0.001>


Does it make sense to expand word embeddings so that each array index is a feature input or should the embedding itself be a model input?

Breaking the array you lose distributed representation-point of word embedding.

There is information in other dimensions (words) that are distributed in the word-embedding representation, breaking them up makes no sense.


How does backpropagation work with averaging layers?

Highly unlikely.

Simple thought experiment. If the vertices (graphically == weights) are the same for these two nodes (first cell of the vector for the first word and the first cell of the vector for the second word in context) (what I am trying to say they are fully connected) BUT input values when you feed-fowarded these values were different, not only that this difference spaned accros other layers, hence you can not expect that weight updates via backprop will be same.


Is it possible to make F1_Score differentiable and use it directly as a Loss function?

Yes there is, let's take $F_1$ score  base definition, with :
$$
F_1 = 2 \times \frac{precision \times recall} {precision + recall} \\
F_1 = \frac{2 \times TP} {2 \times TP + FP + FN}
$$
And this is the same as the Sørensen-Dice coefficient, also known as Dice coefficient or Bray-Curtis distance. This is a statistical indicator that measures the similarity of two samples :

$$ Dice(X,Y) = \frac{2|X \cap Y|}{|X| + |Y|}$$

Concerning the implementation of this loss, we can approximate $|X \cap Y|$ as the sum of the matrix obtained using Hadamard product ($\odot$, also known as the element-wise product) between the ground truth ($y$) and the prediction ($\hat{y}$). We can then define $L_{Dice}$ as follows:

\begin{align*}
L_{Dice} &= 1 - Dice \\
L_{Dice}\left(y, \hat{y}\right) &= 1 -
        \frac{ 2\sum y \odot \hat{y}}
             {\sum y + \sum \hat{y}}
\end{align*}

You will often find this loss in the context of segmentation problems, as well as others quite close, such as the Jaccard index (IoU).


pandas: how to change the specific column as index and change index into various columns

For me, when it comes to reshaping a dataframe(switching columns/indices/rows and such) its fairly intuitive using the pivot_table function.

my_df.pivot_table(index='time', columns=my_df.index, values='value')


Encode time-series of different lengths with keras

Figure out the max length you want your time series to be and use linear interpolation to fill in missing values in the shorter series so that time series can be same length.
Example of this is:
def interpolate_to_length(time_series, final_length):
    curr_ts_length = time_series.shape[1]
    idx = np.array(range(curr_ts_length))
    idx_new = np.linspace(0, idx.max(), final_length)
    # linear interpolation
    f = interp1d(idx, time_series, kind='cubic')
    new_ts = f(idx_new)
    return new_ts

df = pd.DataFrame(data = {'col1': [1, 5, 10, 15, 20], 'col2': [1, 6, 11, 13, 15]})
print(df)
transposed_values = df.values.transpose()
print(transposed_values)
print(interpolate_to_length(transposed_values, 10))

Output should be:
   col1  col2
0     1     1
1     5     6
2    10    11
3    15    13
4    20    15
[[ 1  5 10 15 20]
 [ 1  6 11 13 15]]
[[ 1.          2.5743027   4.48331047  6.61728395  8.86648377 11.12391404
  13.34567901 15.55098308 17.76177412 20.        ]
 [ 1.          2.93415638  5.36213992  7.88888889 10.11934156 11.67489712
  12.55555556 13.1399177  13.82304527 15.        ]]


How to understand image of Fourier transform?

The lines connecting the ends seem also parallel to existing lines with a similar pattern but faded a lot more.

I think they are the 2D equivalent of harmonics.

Maybe start with a generated straight line segment at a small angle, e.g. $\pi / 6$ rad.
Not end-to-end, and maybe not even centered.


How do I know what the best number of layers is required to achieve the highest accuracy

The number of layers and the number of nodes in each layer are model hyperparameters that you must specify. So, we cannot directly say this no of hidden layers / this no of hidden units / this learning rate .. are better.  But we can use some techniques :

Intuition:
So based on the complexity of your model, you need to choose a value that you feel suits it the most.

Experiment:
Now, if your intuition fails, then you should experiment and see the nature of the model. So, try to plot the cost function for different values of the hyperparameter and understand the behavior of the model, with which you can probably get the best value for your hyperparameter.

Generally, if your model is expected to learn complex patterns, then you should go for depth.
For no of neurons in a layer, there are some rule-of-thumb methods:

The number of neurons should be between the size of the input layer and the size of the output layer. (or mean of both)
The number of neurons should be : (2/3 the size of the input layer + the size of the output layer)

There are some other rules and formulas, but I think these rules should give you a good start. But still, the key is your intuition and experimentation.


Combining text (NLP), numeric and categorical data for a regression problem

To predict the points variable, we have four features namely review, country, designation and age.

For the review feature,

You can use Doc2Vec to transform the review into a fixed size vector. Similar reviews will lie in a close vicinity.

For the country and designation features,

Assuming these variables have finite values, so you can treat the variable as categorical. We can use one-hot encoding.

For the age feature,

You can treat this variable as numeric.


What exactly means CNN is position equivariant

In your link, the author Jean states:

  Additionally, I believe that if a CNN is trained showing faces only at one corner, during the learning process, the fully-connected layer may become insensitive to faces in other corners.

I also believe this to be correct. The FCN does not in any way add or improve translation invariance. Instead it will treat all outputs - each individual pixel of the "feature maps" - of the last convolutional layer as entirely different features. It must be trained with enough examples in order to generalise well.

However, the feature maps are not themselves simple, clean detectors of objects as the simplified explanation of CNNs might imply. In a deep network they can be very complex and respond to a wide range of stimuli. They will also respond somewhat fuzzily, so that e.g. an eye or the side of a head showing an ear can trigger multiple feature map pixels (to the feature map's kernels, the same object slightly translated will look like distorted version of the same feature, and will still match enough sub-components of the object to trigger a positive response). The last layer will not necessarily detect full objects, but significant chunks of objects, areas of important texture etc. So position can still be quite fluid, and the "head detector one pixel off in last convolutional layer" scenario is not particularly realistic - although it may affect relative strength/confidence of predictions.

This can still be a problem if you need your network to generalise. If you suspect that your training data might not be covering enough variations in position, orientation etc of images, then a common approach is data augmentation. As a reflected, rotated or cropped image of an object should usually be classified as the same object, then you can pre-process your training data using those transforms to make many random variations of the input images. Some deep learning frameworks will allow you to do this continuously, generating fresh images for each and every batch.


How to interpret FPR and TPR in ROC curve?

As explained here in the docs of the function returning the ROC Curve
they return a array because when you interpret a ROC curve what you're looking the performance of the predictor given a threshold. So, it means that, if I'm looking for only classifications that the model is above 80% sure, the ROC curve will have a different TPR/FPR than a threshold of 90%.

If you have further questions, a great link explaining it: http://www.dataschool.io/roc-curves-and-auc-explained/


If the order of the heroes doesn't matter, I would go for the boolean columns.
The reasoning is the following: We have two possible cases: we always order the player hero ids in a team, or we don't necessarily do that.

If we order hero ids: let's say a team has players 1,2,3,4,5 and another team has players 2,3,4,5,10. The teams are very similar (we've only changed one player), but the features are completely different. In machine learning we want similar entities to have similar representations in terms of features.
If we don't order hero ids: then, it's even worse, as the team 1,2,3,4,5 has the completely different features from 5,1,2,3,4, and they are the same team.

If we do the boolean encoding: if we reorder the heroes we have the same representation, and if we change only a player only a feature of the 200 changes.


Binary classification and numerical labels

If you’re going to have more than two labels, you need to go with a softmax activation and a loss for multi class classification, ie cross entropy loss.
Also, be cautious for multi-class versus multi-label (below).

Multi-class
One-of-many classification. Each sample can belong to ONE of $C$ classes. The model will have $C$ output neurons that can be gathered in a vector $s$ (Scores). The target (ground truth) vector $t$ will be a one-hot vector with a positive class and $C−1$ negative classes. This task is treated as a single classification problem of samples in one of $C$ classes.
Multi-label
Each sample can belong to more than one class. The model will have as well
$C$ output neurons. The target vector $t$ can have more than a positive class, so it will be a vector of 0s and 1s with $C$ dimensionality. This task is treated as $C$ different binary $(C′=2,t′=0 \ or \ t′=1)$ and independent classification problems, where each output neuron decides if a sample belongs to a class or not.
source: https://gombru.github.io/2018/05/23/cross_entropy_loss/


What is the better way to predict classes for the models developed using the functional API in Keras

Is this a multi-label problem or a pure classification problem? If it is just classification change the activation function in the final layer to softmax. When you do predictions select the output with the highest probability as the class. Alternatively use model.evaluate(.....). versus model.predict Documentation is here,


It simply depends on what is the goal of the task:

If the final goal is still to predict Y after detecting anomalies (i.e. probably using the output of anomaly detection as a feature), then Y cannot be used since it wouldn't be available in a realistic test set.
If it's just a completely different task in which Y is available as an input, then why not use it.

With 500k instances, A single additional variable with 3 possible values has an extremely low risk of causing overfitting.
Note that since classification didn't work, it's likely that there is little relationship between the features and Y (otherwise there was some mistake in the classification experiment).


How would I approach training a model and encoding this categorical data

You need to encode categorical variables as dummies.
This means to create new features for each type of category and then assigned either a 1 (where a record has that category) or 0 (to each record that doesn't have that category). With some examples, this should look something like this
                        good  clean  hotel  enjoyed  stay  here
I am good               1     0      0      0        0     0
My face is clean        0     1      0      0        0     0
This is a clean hotel   0     1      1      0        0     0
I enjoyed a good meal   1     0      0      1        0     0
Don't stay here         0     0      0      0        1     0

In python you can use the pandas function pd.get_dummies()


how to handle outliers for clustering algorithms?

If you have outliers, the best way is to use a clustering algorithm that can handle them.

For example DBSCAN clustering is robust against outliers when you choose minpts large enough. Don't use k-means: the squared error approach is sensitive to outliers. But there are variants such as k-means-- for handling outliers.


Algorithms for Anomaly Detection of Event Sequence Data [Python/R]

A simple comparison is to use the reconstruction error as the anomaly score.
This can be done instead of, or in addition to, the Local Outlier Factor that you have now.
You can also try other ways of computing the anomaly score from the latent feature vector. Some popular alternatives are:

Mahalanobis distance on the
Fitting a Gaussian Mixture Model, and use the probability density function

A completely different approach would be to use a self-supervised training setup instead of the autoencoder. Such as Skip-Gram or predicting future time-frame.


Why is Reconstruction in Autoencoders Using the Same Activation Function as Forward Activation, and not the Inverse?

I don't think that your assumption $w' = w^T$ holds. Or rather is not necessary, and if it is done, it is not in order to somehow automatically reverse the calculation to create the hidden layer features. It is not possible to reverse the compression in general, going from n to smaller m, directly in this way. If that was the goal, then you would want a form of matrix inversion, not simple transpose.

Instead we just want $w_{ij}$ for the compressed higher-level feature representation, and will discard $w'_{ij}$ after auto-encoder is finished.

You can set $w' = w^T$ and tie the weights. This can help with regularisation - helping the autoencoder generalise. But it is not necessary.

For the autoencoder to function it doesn't actually matter what activation function you use after the layer that you are pre-training, provided the last layer of the autoencoder can express the range of possible inputs. However, you may get varying quality of results depending on what you use, as normal for a neural network.

It is quite reasonable to use the same activation function that you are building the pre-trained layer for, as it is the simplest choice.

Using an inverse function is possible too, but not advisable for sigmoid or tanh, because e.g. arctanh is not defined < -1 or > 1, so likely would not be numerically stable.


correct setting of eval_set in multiclass classification xgboost python , error is “ Check failed: preds.size() == info.labels_.size()”

This looks like a bug in the 0.80 version.

It works when upgraded to xgboost 0.82.


Time series analysis vs linear regression

The data you are having is panel data which is a combination of both cross sectional data and Time series.

You can try with regression models by giving time stamp to your data .Like maintaining one feature based your weekday (1 to 7).or if you have trends and seasonality in your data you can go to giving week number as feature like (0 to 53) weeks.


Create a measure that converts minutes into hours

Ok, I got an answer from the powerbi community. Here it is:

lead time (hrs) = SELECTEDVALUE(Dataset[lead time])/ 60

I hope this helps someone.


sub_compiler.merge(sub_opt, how='inner', on='instruction')

This is how to do table join on your table.

Another option if it is already aligned and you just want to concatenate you can do

pd.concat([sub_compiler,sub_opt[['opt']]], axis=1)

This is naive column-wise concatenate.

Finally just proceed with to_csv.


Does my prediction improve when I use more, but worse classifiers?

I would approach the problem as follow:
Start by splitting your dataset into a test dataset and a training dataset. You would then proceed by building a classifier for each antibody (feature) using only the training dataset and then measure the success of your model on some test dataset (using the measure that you care about e.g. accuracy).
Usually you cannot repeat the process I described above for all combination of antibodies (features), due to time constraints. Their is a variety of methods you can consider which can be found if you search for feature selection techniques e.g. wrapper, embedded, filter etc.
Since it sounds like you already have a good idea of which features (antibodies) are important, I would recommend trying forward features selection. The idea is that you start building multiple models using only 1 feature (antibody) and determine which one is the best. Let's refer to these as selected features from now on.
For each unselected feature

Build a model using the selected features and one of the unselected features (in this case we will build a model using your best antibody and one other antibody)
Measure the performance of the model on the test set and store it

Once you are done you check if by adding only one feature did it improve the performance in comparison to using only one antibody. If it did you add the best antibody to your original best antibody, so now your model has two selected features.
You can repeat this process, until the performance starts to drop. The method does not search the whole space, but it still gives some descent results.


Given a list of thresholds in descending order will the corresponding FPRs and TPRs lists always be in ascending order?

From sklearn Documentation: roc_curve returns fpr and tpr, which are increasing; and thresholds which is decreasing. Also check the examples below the definitions.


Why would removing a variable in adaboost decrease error rate?

Imagine that one of the column is just random data -- then it's not informative at all, so no classifier will be improved by including it.

However, ada's stochastic boosting implementations will always have some chance of including that variable in the classifier it generates. As a result, removing it has the potential to improve the classifiers generated.

(In your case, you might check whether that variable is part of the final model generated.)


I think the short mathematical intuition would be to show that Deeper offers more flexibility.

Imagine we want to fit an impossibly complicated function, like this:

... but in an n-dimensional space - we obviously cannot visualise such a function. But we can agree is is complicated

Basic math analogy

The goal of the neural network would be to map the raw input data (e.g. images to a convolutional network) to some output, by approximating the complicated function.

So if we have some input, and apply a non-linear function $f$ to it, we transform it into something else:

$$output_1 = f(input)$$

Perhaps that gave us a curvy function, but it doesn't get close to matching the complicated function, so we endow the model with another chance, by applying a second non-linear function:

$$output_2 = g(output_1)$$

Giving a second function is almost like offering another degree of freedom (or flexibility) to the model.

We continue like this until the chain of non-linear functions is able to map out the output space sufficiently well. Perhaps we end up with this:

$$output_6 = k(j(i(h(g(f(input)))))$$

In this framework, imagine every single non-linear function as one of the layers in a deep network. The deeper the network gets, the more functions we are applying and the more we mould and transform the input to something else; perhaps in different ranges, by different magnitudes and so on.

This should (in a very hand-wavey manner) convince you that more functions applied gives more possibilities in the final output space. So more layers gives us more power to express more and more complicated functions.

A practical note: the more layers we add, the more powerful the model and the larger the tendency to either:

be very difficult to train
eventual overfit the training data completely
the longer the model takes to train
the greater the level of regularisation that is likely required to obtain a reasonable validation metric on unseen data

image source


What does from_logits=True do in SparseCategoricalcrossEntropy loss function?

The from_logits=True attribute inform the loss function that the output values generated by the model are not normalized, a.k.a. logits. In other words, the softmax function has not been applied on them to produce a probability distribution. Therefore, the output layer in this case does not have a softmax activation function:
out = tf.keras.layers.Dense(n_units)  # <-- linear activation function

The softmax function would be automatically applied on the output values by the loss function. Therefore, this does not make a difference with the scenario when you use from_logits=False (default) and a softmax activation function on last layer; however, in some cases, this might help with numerical stability during training of the model. You may also find this and this answers relevant and useful about the numerical stability when from_logits=True.


AlphaGo (and other game programs using reinforcement-learning) without human database

I'm no expert but it looks like AlphaGo Zero answers your question.
https://deepmind.com/blog/alphago-zero-learning-scratch/

  Previous versions of AlphaGo initially trained on thousands of human
  amateur and professional games to learn how to play Go. AlphaGo Zero
  skips this step and learns to play simply by playing games against
  itself, starting from completely random play. In doing so, it quickly
  surpassed human level of play and defeated the previously published
  champion-defeating version of AlphaGo by 100 games to 0.


Welcome to the community.

You can use the following code:

import weka.filters.supervised.instance.SMOTE;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
import weka.filters.Filter;

Instances data = DataSource.read(".../file.arff"); //Dataset

SMOTE smote=new SMOTE();  //create object of SMOTE
smote.setInputFormat(data);
Instances data_smote = Filter.useFilter(data, smote); //Apply SMOTE on Dataset


How to Combine tfidf with LSTM in keras?

The goal of text_to_sequence + embedding in traditional LSTM is to transform text to word vectors.

If you already have the tfidf transformation, the idea is usually to get rid of the embedding layer in your LSTM when you are constructing the model, and directly connect the input (i.e., tfidf matrix) to the layer followed by the embedding layer.

Not sure if it's a good approach but that's for you to figure it out :P.


I've been using tree-based enesembling methods such as random forests and gradient boosting for several years now, and I have to say that I've never seen that behavior.

Some packages measure variable importance solely based on trees' final splits rather than candidate/surrogate splits, so if you have two important inputs that are correlated, but one is consistently a tiny bit better than the other, the less important input might never get selected as a final split and thus look as important as some of the less valuable inputs. However, this phenomenon is independent of the number of trees/ensembling, so I don't think it fully explains the behavior you're seeing.


I'm building a movie recommendation system based on genre, where the user will enter his choice and will receive recommendations based on his choice:

First of all, your question is very general and missing crucial information - you should highlight which language and dataset you are planning to use. You should also include it in tags of the post.
Anyway, I suppose that you are working with one of the IMDB datasets. I can personally recommend this article and this article. The authors explain the basic techniques how to build a recommender system in Python using scikit-learn library including cosine similarity.


Can you use two different datasets as train and test sets with countVectorizer and test_train_split?

You're doing a big mistake in your code, which is applying the vectoriser before the train/test splitting. The vectoriser should be fit only on the training dataset, then the learned counts should be applied to the test set. Instead you applied the vectoriser to the whole data which you then splitter into train and test.

# THIS IS OK
# train_data = np.concatenate((train_data, validation_data))
X = cv.fit_transform(train_data_text).toarray()
y = pd.get_dummies(train_data_labels)
y = y.iloc[:, 1].values

# NOT OK
# Train Test Split
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=0)

# CORRECT WAY
X_train = X  # already good as it is
y_train = y  # also good

# I suggest to use pandas to read the txt files
X_test = cv.transform(test_data['text']) # <-- APPLY VECTORIZER TO TEST DATA USING TRANSFORM ONLY

Then you can procede as you did in the rest of your code.


How do I encode the categorical columns if there are more than 15 unique values?

[edit] See also Carlos' answer, I think it's better than mine.
You should use one hot encoding for the categorical features. Replacing categorical values with numerical ones would be a bad idea, because it introduces order between the values and the model would try to find patterns based on this order (e.g. 'x < 4').
If there were really too many different values then it's often a good idea to remove or replace the least common ones, but it doesn't seem to be an issue with this data.
For the record, more than 15 different values is nothing to be afraid of. For example when working with text data it's common to work with thousands of values for a word.


Converting a speech recognition model from CNNs to GRUs

I think your network's design is fine but need change the way you feed training data.
In essence you try convert a classic CNN (having "image" data, but spectrograms) to a sequential time-domain type of network (recurrent one, having GRU or LSTM at the heart).
To be able to do that you have to reconsider the way you feed the input data:

Input data should not be the "image" snapshots of spectra (as expression of audio spectra in a time-window) but instead have to feed evolving sequences like text ones (the .wav audio samples in sequential way).

If still would like to feed with spectrograms and not raw sequential wave samples, try feed the spectrograms by cloning each of them into time evolving variants having offset by t, t+1, t+2, t+N variants of same audio snapshot (recompute FFT as many times) thus recurrent GRU unit may have chance to capture sequence information out if it.

Also:

BatchNorm & Relu was added, a good way to improve generalization and overfit, at the price that might requires more data to see benefits.
Pooling & Flatten summarisation was replaced by GRU recurrent unit, but these units learns only when capturing from time evolving data.
Very Conv2d in front of GRUs helps generalization but Conv2d x times x GRU also means lots of combinatoric space opened up, implict might require more input data or prolonged training.

Anyway is a fun experiment worth trying !


I think I've worked something out. Basically I'm looking for an approach that works in a map/reduce type environment and I think this approach does it.

So,

suppose I have b bands of r rows and I want to add another AND stage, say another c ANDs.
so instead of b * r bits I need hashes of b * r * c bits
and I run my previous procedure c times, each time on b * r bits
If x and y are found to be a candidate pair by any of these procedures it emits a key value pair ((x, y), 1), with the tuple of IDs (x,y) as the key and the value 1
At the end of the c procedures I group these pairs by key and sum
Any pair (x,y) with a sum equal to c was a candidate pair in each of the c rounds, and so is a candidate pair of the entire procedure.

So now I have a workable solution, and all I need to do is work out whether using 3 steps like this will actually help me get a better result with fewer overall hash bits or better overall performance...


Orange 3 Heatmap clustering under the hood

It appears the widget uses hierarchical clustering. I guess the metric is Euclidean distance by default and there doesn't seem to be a way to specify another one (except by using Distances widget and connecting it into the Distance Map widget).

I don't think it is possible to export the widget's workflow as pure code, but you can look at what the widget does in the source code (seems pretty low-level, though). What you can do, however, is select subsets of data (can be saved with Save Data widget) for further analysis if that's of any help.


On the properties of Hyperbolic Tangent Kernel

Sigmoid kernels owe their popularity to neural networks, which traditionally used the sigmoid activation function. Sigmoid kernels de-emphasize extreme correlation. In a way they behave a bit like correlation coefficients, which also has a limited range, emphasizing similarity in orientation. $c$ shifts the operating point on the sigmoid, affecting the relative emphasis of the angle between the inputs. Perhaps this visualization (for $c=0$) might help mentally visualize this:

Your first reference states that sigmoid kernels behave like RBFs for certain parameters. This makes them suited to nonlinear classification. You probably know that the sigmoid kernel is only conditionally PSD, and thus sometimes does not correspond to the kernel function of any implicit feature map per Mercer's theorem.

Someone this interested in kernel methods should have a copy of Learning with Kernels!


Classifying text documents using linear/incremental topics

If you want these output dimensions to be continuous, simply convert your size and relevance metrics to real-valued targets.  Then you can perform regression instead of classification, using any of a variety of models.  You could even attempt to train a multi target neural net to predict all of these outputs at once.

Additionally, you might consider first using  a topic model such as LDA as your feature space.

Based on the values, it sounds like the "relevance" might be a variable best captured by techniques from sentiment analysis.


Understanding ROCs in imbalanced data-sets

So your data-set of 155000 records has 403 records where B=1, and B=0 for the remaining 154597 records.

You could try splitting your data-set into 2:1 training/test sets sampled by each class of B. After you've done this, then only for the training set use SMOTE to over-sample the records with B=1 along with under-sampling the B=0 training records to bring the class ratio to something like 4:1.

Over/under sampling for the test set is not required as it is supposed to mimic real world uncertainty to test your model's performance.

Your model's AUC will definitely get reduced since (as rightly pointed out by stmax), you've leaked test records into the training set by over sampling B=1 cases before splitting the train-test sets.

The answers to each of your questions are:

Yes, class imbalance does effect a random forest model's accuracy. How severely depends on the severity of the imbalance as well as the nature of the data-set itself.
Yes, you are biasing the training by over sampling the minority class, but if these are large enough samples in the original set, then hopefully they are close representations to the entire population.
I would recommend two metrics/techniques you could use here: Kappa Statistic (refer to this article) and the precision-recall curves to compare different models.


How to predict unknown(hidden) value by incomplete value or partly recorded value

Actually you can use almost any regression model. When you do not want to go too much into theory simply use a gaussian process provided by sklearn. This model gives you predictions and uncertainties.


Which ML method would be best for deriving a rough formula for prediction based on existing data?

If you want "the easiest" for "a simple formula", then for sure it will be a linear regression on the battle score, or a logistic regression on "win/lose". That way you'll have the coefficients of the model, and they will be interpretable (which you won't get from a neural network with hundreds of parameters).


r - How to determine the correlation between unordered categorical variables and individuals?

If you have data sets $X_1,\cdots,X_n$ and $Y_1,\cdots,Y_n$, then you can compute their correlation with the following formula:

$$Cor(X,Y) = \frac{\sum (X_i-\bar{X})(Y_i-\bar{Y})}{\sqrt{\sum (X_i-\bar{X})^2\sum(Y_i-\bar{Y})^2}}$$

(where $\bar{X}$ denotes the average value of the $X_i$'s).  This is accomplished in $R$ with the following command:

cor(x,y)

That being said, it is unclear what two data sets you are trying to find the correlation for.  Finding the correlation between a type (A,B,C) and a condition (copper, gold, etc.) would not make any sense.  You could, however, find the correlation between two different types (A and B, for example), or between conditions (copper and gold).

Edit: I think you might want to do a test for independence between categorical variables...if this is the case then this is what you are looking for.


What is the branch of data science that deals with generating data? Looking for tutorials

This is known as generative models, they basically infer the probability of the data based on the training examples. Algorithms usually are discriminative, i.e they perform prediction by estimating:

$$
p(Y|X)
$$

so given your data they are able to predict a label.

Generative models are interested in $p(X)$ i.e. how is the data generated. Once the model learns this, it can produce "fake" images that look like your inputs.

You can look at:

Generative Adversarial Nets (which have had a lot of attention lately)
Variational Autoencoders (were in vogue before GANS were introduced)


The ability of the model to predict negative value for the housing price depends on the data. On the large amount of data, where there are no negative pricing, the model does not predict a negative number. However, in rare case, where the model is not trained well or has not seen such samples, then it is still possible.

The models prediction on the positive value can be still controlled post predictions. Just like using a treshold. y = y if y>0 else 0; Where the housing cost (y) is as it is if it's positive, 0 otherwise.

ReLu function, works in the way you desire. Negative values gets converted to 0 by the activation.

I am not very sure about the Poisson  loss, you may try it.


ARIMA models are basically linear models, so they can only work if the relation is linear (or linear integrated). They are easy to estimate.

LSTM can model more or less any relationship, but at the cost of additional computation and require more data to be trained.

So start with ARIMA if you don't know anything about our data, if it doesn't work, use a simple LSTM model and then complexity it to match what you need with the test set.


Why can't i normalize my data using preprocessing.normalize?

Sklearn.preprocessing.normalize is vector norm normalization. By default it use L2 Norm which is $x_{norm}=\sqrt{\Sigma{x_i^2}}$. For example, if there's one vector $(1,2,3)$, then the $x_{norm}=\sqrt{1^2+2^2+3^2}=3.7416$, then if you normalize the vector, it would be $(\frac{1}{3.7416},\frac{2}{3.7416},\frac{3}{3.7416})$.

If that's what you want, try

# convert to numpy array with shape(rows,1)
df_array = df['Miles'].values.reshape(-1,1)
df['Miles'] = preprocessing.normalize(df_array,axis=0)

Note that setting axis=0, otherwise it would be done column-wise and you will get all 1 vector.

I think you may want to scale the vector rather than normalization, try mean-std scale by sklearn.preprocessing.scale, max-min scale by sklearn.preprocessing.minmax_scale. Be sure that you reshape the array first.


How to think about prediction error that is not convex in hyperparameter, or over the course of training

The underlying true performance is likely convex or at least likely only has one minimum, but you don't know the true underlying performance, you only get a stochastic sample with a tiny sample size because you apply cross validation. The performance is a random variable where you are interested in the expected value, but you only get k samples where k is the number of folds. I think if you would increas k your curve would look more smooth. That said, even if your hypothesis counts in general, for this specific set there might be some weird data points that make random settings perform worse than expected still.

The problem with your suggested approach is that you are treating this noise as signal. If you have a normally distributed random variable, you sample 1000 times from it and take the max value, this will be much higher than the true expected value. An alternative explanation could be that it is not noise, but that you are actually overfitting. Then your approach makes more sense, and if the samples surrounding it during training are also relatively low then this is actually a good strategy, it is called early stopping, a different form of regularization and commonly used in Neural Networks.

EDIT: I think you are right that I didn't explain that analogy very well, we are trying to optimize a function g(x) where x is our hyperparameters and g(x) is a random variable function, let's say it had a true underlying value f(x) and additive noise $\epsilon$. If $\epsilon$ is Gaussian distributed with a high variance compared to the underlying value, if we take the max without looking at anything else we could take one that had lucky noise. I think what we are seeing in your graph is relatively high variance due to low sample size of your data (which means small validation sets in your folds) whih will lead to non-convex behaviour. That said, your explanation of early on seeing lower validation losses does imply overfitting which early stopping can help with.


R's mice imputation alternative in Python

You can use the library HERE. You are able to impute the values of your dataset using linear models with an Sklearn type interface.


Feature selection using feature importances in random forests with scikit-learn

You can simply use the feature_importances_ attribute to select the features with the highest importance score. So for example you could use the following function to select the K best features according to importance.

def selectKImportance(model, X, k=5):
     return X[:,model.feature_importances_.argsort()[::-1][:k]]

Or if you're using a pipeline the following class

class ImportanceSelect(BaseEstimator, TransformerMixin):
    def __init__(self, model, n=1):
         self.model = model
         self.n = n
    def fit(self, *args, **kwargs):
         self.model.fit(*args, **kwargs)
         return self
    def transform(self, X):
         return X[:,self.model.feature_importances_.argsort()[::-1][:self.n]]

So for example:

>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import RandomForestClassifier
>>> iris = load_iris()
>>> X = iris.data
>>> y = iris.target
>>>
>>> model = RandomForestClassifier()
>>> model.fit(X,y)
RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
            max_depth=None, max_features='auto', max_leaf_nodes=None,
            min_samples_leaf=1, min_samples_split=2,
            min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=1,
            oob_score=False, random_state=None, verbose=0,
            warm_start=False)
>>>
>>> newX = selectKImportance(model,X,2)
>>> newX.shape
(150, 2)
>>> X.shape
(150, 4)

And clearly if you wanted to selected based on some other criteria than "top k features" then you can just adjust the functions accordingly.


How to determine what algorithm to apply in the following dataset (included)

Note that doing a dimensionality reduction with the target can lead you to the manifold problem. You can see in the image. What ends up happening is that the target information is lost.

The information that you provide is not enough to make a guess of what algorithm will be better.

Normally reducing the dimensionality of the problem to a lower dimension space in order to plot where you want to have the decision boundaries is not a good idea.

It's really hard to have a human understanding of how do these algorithms do the decision boundaries in a large scale dimension, that is why it is just better to have an empirical approach. Try a few of them, select a metric, and choose the one that has a higher score.


There are two broad classes of problems in machine learning, classification and regression. As in this answer, Regression involves estimating or predicting a response (the dependent variable is continuous). Classification is identifying group membership (the dependent variable is discrete).

Your problem is a regression problem, you must try to estimate the real number of sales. You can look here for a similar problem and techniques to solve it.


Where did this NY Times op-ed get his Google Search data?

Google AdWords.  That has absolute search volumes.


How are weights represented in a convolution neural network?

In convolutional layers the weights are represented as the multiplicative factor of the filters.

For example, if we have the input 2D matrix in green

with the convolution filter

Each matrix element in the convolution filter is the weights that are being trained. These weights will impact the extracted convolved features as

Based on the resulting features, we then get the predicted outputs and we can use backpropagation to train the weights in the convolution filter as you can see here.


DQN - how is it possible to train separate outputs for each action?

The output of your network should be a Q value for every action in your action space (or at least available at the current state). Then you can use softmax or epsilon-greedy (or other strategies) to select the final action. The network will learn to predict which action should return the maximum reward from your current state. Also we update the network after we have collected a specific amount of experience and we use batches from that experience buffer in order to update the network. We do not feed back any value in the vanilla DQN (no recurrence).

There are many good implementations online that can help you understand the algorithm.


Why is KNN better at K-Fold Cross Validation than XGBoost or Random Forest?

It's not that KNN is better at k-fold cross validation.
Its just that KNN doesn't do any training apart from storing a footprint of the training data within the model.
KNN's logic resides in its inference step i.e. the predict() call where it determines the k nearest neighbors for the newly supplied instance from previously supplied training data and makes a prediction for the label.
So it's likely that KNN is faster than most other models for small to medium sized datasets.


Although you might find a way to apply machine learning (ML) to this optimisation problem, it does not look necessary, and is probably a distraction. ML might help if the scoring system was complex or if you had incomplete data for most matches, and needed to compute matching score estimates from some more limited set of attributes.

Instead here you seem to have a combinatorial optimisation problem. A well known example of this is the Travelling Salesman Problem.

There are many possible algorithms to attack these kinds of problem. Which to choose may depend on other traits of the data, such as how quickly you can calculate the scores - both for the whole set and for individual changes. If calculating for changes is fast enough, you can use optimisers that work from a complete (but not yet optimal) solution and make changes.

There is a free PDF/book called Clever Algorithms (Nature-Inspired Programming Recipes) covering selection choice amongst all the varied optimisers. This may allow you to find something optimal in terms of speed and reliability of algorithm.

Here's a simple thing you could try though

Create a "greedy" solution

Shuffle one set of items that need to be paired
For each item in turn, pair it with the best scoring partner
Calculate the score for this solution

Refine the solution

Sample some subset of pairs (e.g. 2, 3, 4, 5 pairs). You could do this deterministically for small enough dataset, or stochastically, or use some algorithm to filter to "at least has some chance of improving".
Find the best score amongst all permutations in this small subset (i.e. brute force all 24 pairings amongst 4 couples)
Put the best subset back into the solution
Repeat until no improvement found after some number of tests

This routine can be altered in various ways to take advantage of aspects of your problem. A nice thing in your case, making this easier that the Travelling Salesman Problem, is that you don't have any constraints on valid pairings. In TSP you care about making a single circuit, and not multiple separate loops which limits how you can make changes, whilst in your case each of your pairs is entirely separate.

One example of possible algorithm improvement: You could pre-calculate the scores for the top N matches for each person, and only search amongst those when considering local changes.


Prepending Input layer to pre-trained model

The issue is that you shouldn't flatten the images into 1-dimensional vector because the VGG16 contains 2D convolution layers (e.g. spatial convolution over images), which require the input to have the shape of (number_of_images, image_height, image_width, image_channels), given that keras.backend.image_data_format() returns 'channels_last'. If your image_data_format is 'channels_first', change the input data shape to (number_of_images, image_channels, image_height, image_width).

Here is your fixed code (tested with Keras 2.0.4):

x_train = x_train.reshape((x_train.shape[0], 480, 720, 3))
x_test = x_test.reshape((x_test.shape[0], 480, 720, 3))

initial_model = VGG16(weights='imagenet', include_top=False)
input = Input(shape=(480, 720, 3), name='image_input')
x = Flatten()(initial_model(input))
x = Dense(200, activation='relu')(x)
x = BatchNormalization()(x)
x = Dropout(0.5)(x)
x = Dense(1)(x)
model = Model(inputs=input, outputs=x)
model.compile(loss='mse', optimizer='adam')

model.fit(x_train, y_train, epochs=20, batch_size=16)
score = model.evaluate(x_test, y_test, batch_size=16)


Is it better to have binary features rather than class ones

In general, it’s better NOT to binarize them if the decision tree algorithm that you are using supports categorical features, as variables with fewer levels are less likely to be used in splits. Note however that not all implementations in all software are able to use categorical features without one-hot encoding – for example, most R implementations of decision trees and tree ensembles support categorical features natively, whereas scikit-learn’s and spark’s do not.

Here’s a blog post with a comparison of categorical as-is vs. one-hot encoded for random forests:
https://roamanalytics.com/2016/10/28/are-categorical-variables-getting-lost-in-your-random-forests/


Linear combination of weak estimators over fuzzy classifiers?

You might find a solution for this by checking out Viola & Jones face detection algorithm (and object detection in general) http://www.cs.ubc.ca/~lowe/425/slides/13-ViolaJones.pdf. Particularly the AdaBoost algorithm for building a strong classifier from weak classifiers. https://www.cs.princeton.edu/~schapire/papers/explaining-adaboost.pdf

In this algorithm this is used particularly for feature selection, where it is wanted to select just the features that grouped together classify better, discarding the other as noisy features.

The approach to obtain this strong classifier is having a set of examples X, a set of weights W and a set of expected results (classifications) Y. For a two-class example (e.g. face o no face image) the first weak classifier is selected and then the classification error is found between this classifier and the expected output. For the samples that were misclassified their weights are incremented, so the next weak classifier to find is more biased to neglect this wrong classification.

The algorithm (AdaBoost) converges when the sign of the sum of classifications for each sample outputs the correct classification.

For example:

Y = +1 -1 +1 +1

WC1=+1 +1 +1 +1
WC2=-1 -1 -1 -1
WC3=+1 -1 +1 +1

So the strong classifier is WC1+WC2+WC3:

SC=+1 -1 +1 +1 == Y

Hope this solves your question.


How to get the best combinations of features for a sale optimization problem?

Whenever you have an optimization problem the first question that you have to ask yourself is.

Can I make it a Linear Programming problem?

For python I normally use Gurobi. Here is a basic example to get started: https://www.gurobi.com/resources/food-manufacture-i/

You can also do Machine Learning with it, that is the hot topic nowadays, but if you can make it a linear programming problem you will achieve optimality.


Anomaly detection k-means in Time Series

I don't suggest to use k-Means clustering for outlier detection. You can check the outlierness of observations by taking the standardized distance of each observation from the series' trend.

Alternatively, you can use DBSCAN algorithms: they are clustering models specifically designed to isolate outliers. I don't know if it makes sens on time series data. I'd go for the first method.


If I understood your question right -
you've created a new feature age<55 - which gets True/False, hence, there is no need for the second feature since it has a perfect (negative) correlation with the first one (i.e False in every record that the other new feature got True..).

2 last notes:

Note that the second feature ain't addeing any new information to the first one.
Note that you've missed the recodes with age==55

I would suggest:

df['is_old'] = df['age'].apply(lambda x: x>55)


Is it possible to run clustering methods by only knowing the distance between pair of points?

K-Medoids

It would be possible with an adapted semi-supervised K-Means, also known as K-Medoids.

The tricky part with K-Means is that you do not know the centroids. However, you could hot start by assuming that some of your data points are centroids. Then, when figuring the new centroid at each iteration, instead of figuring out the "imaginary" central position, pick the point in the cluster that minimizes the sum to all other points in the cluster.

Hierarchical Clustering

You could also try a hierarchical clustering method. One example is the AgglomerativeClustering from Scikit-Learn. The idea is that you start merging points that minimize their linkage distance. Then, there is a certain criteria for determining points that are "too far away" and a new cluster should be created.

This is the fit() method documentation. Notice how you can either pass the instance features or the distance matrix between instances.


I end up implementing something like this:

def tweedieloss(y_true, y_pred):
    p=1.5
    dev = 2 * (K.pow(y_true, 2-p)/((1-p) * (2-p)) -
                   y_true * K.pow(y_pred, 1-p)/(1-p) +
                   K.pow(y_pred, 2-p)/(2-p))
    return K.mean(dev)

which I don't know how right it is, for now it seems to be working.


We can break down the task into two parts.

In the first part, our aim will be to localize regions where the bibs could be found. This is an object detection task, so you can use YOLO, Faster RCNN etc. YOLO could be a better choice as it is fast and efficient. We don't need semantic segmentation here. A number of GitHub repositories are available which enable to train a custom dataset for detecting bibs in images.

In the second part, as mentioned in the question, a CNN trained on MNIST will not be enough. We will need an OCR ( Optical Character Recognition ) which would get the text ( number ) from the image.

  The localizer will produce bounding box coordinates. The image will be
  then cropped by those coordinates. This cropped image could be passed
  into an OCR engine and finally, you will get the number present on the
  bib.

For training YOLO on a custom dataset, see here.

For an OCR engine, see here.


Removing correlation between independent variables

can we remove this correlation by multiplying or dividing the values
of one of the variables with random factors (E.g., multiplying the
first value with 2, the second value with 3, etc.)

No you can not decorrelate 2 variables by multiplying or dividing them by a random factors, you can use one of the following methods instead if you want to keep the 2 variables:

Divide a and b: new_a = a / b
Powering up a: new_a = a^2, a^3, ...
PCA
...


Machine Learning - Choice of features for determining hypothesis

There are algorithms that use Feature Selection to utilize only the "best" features for the given dataset (variants of adaboost for example). There are also algorithms randomly use subsets of the features (such as random forest). Finally there are algorithms that learn weigh your inputs and use them accordingly (Neural networks and the like)
There is "common knowledge", but it is more related to the type of features and classification problem that you are facing (i.e. regression vs. classification, continuous vs discrete, binary vs. multi-class, etc.).

If you have a specific problem that you can model using such a function then it is a completely reasonable approach to design such a function.
Once you have modeled your problem with such a function and defined your loss function - you could use any optimization method that seems reasonable.
However it is beneficial to try and find similar problems that others have solved before and understand how their solution relates to your problem.


What kind of research can be done with genomic data?

Determine the function of genes and the elements that regulate genes
throughout the genome.
Find variations in the DNA sequence among people and determine their
significance. The most common type of genetic variation is known as a
single nucleotide polymorphism or SNP (pronounced “snip”).  These
small differences may help predict a person’s risk of particular
diseases and response to certain medications.
Discover the 3-dimensional structures of proteins and identify their
functions.
Explore how DNA and proteins interact with one another and with the
environment to create complex living systems.
Develop and apply genome-based strategies for the early detection,
diagnosis, and treatment of disease.
Sequence the genomes of other organisms, such as the rat, cow, and
chimpanzee, in order to compare similar genes between species.
Develop new technologies to study genes and DNA on a large scale and
store genomic data efficiently.
Continue to explore the ethical, legal, and social issues raised by
genomic research.

Source: https://ghr.nlm.nih.gov/handbook/genomicresearch?show=all


Assuming that you normalized the pixel-values as it is done in the tutorial, your inputs were vectors of numbers betweeen 0 and 1. Now, if your weight matrices are also randomly drawn numbers between 0 and 1, the input to the hidden layer will be sums of 783 numbers between 0 and 1, i.e. probably something > 100. Now, check out the sigmoid function and its derivative

As you see, it saturates quite quickly for input values > 5. If you choose the initialization as you did, all hidden neurons should be very close to one, while at the same time the derivative should be very close to zero. This would explain how all outputs of the softmax were equally close to 0.1 and since the gradient was close to zero, the network probably didn't learn anything.

Once you changed the weight initialization to something between -1 and 1, the inputs to the hidden layer should be sums of numbers fairly evenly distributed around 0, thus the sigmoid output was about 0.5 and, most importantly, the gradient was non-zero so your network actually got trained.

As you already noticed, choosing the initialization wisely is crucial for getting decent results. Initializations should also take the number of input neurons into account, otherwise you initialize the network in such a way, that the gradients will be close to zero.

A similar problem can occur if you do not normalize the input data properly, e.g. if you feed the pixel-values between 0 and 255 directly to the model.

I'm not sure about papers on this, but maybe start with the original work on Glorot initialization or checkout the initializers Tensorflow has to offer. On that site under "Functions" they list common initializers and also link to the respective papers.

I hope this was helpful.


AUC higher than accuracy in multi-class problem

I think the question can se splitted to three parts. The first part is about comparing accuracy and AUC of the same model, the second is about comparing models and the third is about multi-class problems.
First part - I think that accuracy and AUC are not comparable metrics, I don't think that there is special meaning to the case where one is higher than the other.
Second part - ROC plot and AUC are good for understanding model and choosing model types, but in the end of the day you usually want to evaluate your final model with specific threshold so accuracy, precision and recall are the relevant metrics.
Third part - I think the answers to the previous parts above are valid both for binary classification and multi-class classification. Why do you think it have different meaning here?


How to deal with version control of large amounts of (binary) data

What I am ending up using is a sort of hybrid solution:

backup of the raw data
git of the workflow
manual snapshots of workflow + processed data, that are of relevance, e.g.:

standard preprocessing
really time-consuming
for publication

I believe it is seldom sensible to have a full revision history of large amount of binary data, because the time required to review the changes will eventually be so overwhelming that it will not pay off in the long run.
Maybe a semi-automatic snapshot procedure (eventually to save some disk-space, by not replicating the unchanged data across different snapshots) would be of help.


Your assumption is in part correct, as your model will see 120000 images (i.e. the size of the whole dataset) in 10 epochs.

However, because keras' default generators shuffle the dataset at the end of each epoch, it is very unlikely that the model will see each image once after 10 epochs.

My suggestion would be to set steps_per_epoch=5000.


Looking for algebras designed to transform time series

It seems like you are overthinking this and getting caught up in your own head a little.

We can define a restricted set of time series as those which are well behaved (non-asymptotic) and single valued.  These time series then form a time series algebra which have additive, multiplicative, commutative, and associative properties.  There is an identity element (straight line with value 1) and a zero element (straight line with value 0).  We even have a well defined inverse member for all time series not crossing zero.  I believe this even forms an Abelian group.

Further, previous posters are correct that this group can be perfectly represented by various orthogonal vector spaces such as polynomials and Fourier space.  This is true whether we are talking about Lagrange polynomials, Fourier series, or Gauss-Lobatto-Legendre polynomials.

The point then becomes... where does this get you? You got caught up in the suggestion to employ Fourier series in that you didn't want to remain in frequency space, but this is entirely unnecessary.  You can, for instance, Fourier transform into frequency space, apply a high frequency filter, and then transform back into the time domain.  This is incredibly effective in removing noise (although band pass filters tend to work better).

Stepping back from the question a little, it seems like you might really be asking:  Given typical time series and typical time series operations (smoothing, de-seasoning, de-trending, etc) do the time series and their typical operations constitute a group with a well defined algebra?  The answer is, yes.  All of these operations just involve finding other time series which can be added, subtracted, multiplied, or divided by the original time series in order to yield a more physically tractable (interpretable) representation.


It's quite a weird problem, at least for me... Following your approach you'll end up with $5^5$ classes, which is an intractable problem with typical Neural Networks. You can visist this paper, which shows a solution with mathematical rigour:

https://arxiv.org/pdf/1806.02507.pdf

I'll also expose three possible naive solutions, awating for people who have faced a similar problem:

Convert your 5 columns into binary columns (3 bits for 5 levels) and treat the problem as a multi-label classification with 15 classes https://en.wikipedia.org/wiki/Multi-label_classification.
You can fit 5 multi-class models for each column (divide and conquer navie approach, it seems to be the state-of-the art phylosohpy)
I've never tried beta-regression, but it would make sense: you can convert your target labels to frequencies of occurrence, think about pruning targets with really low probability. Then, you can perform a preliminary beta regression to predict the occurrence-target. Further on, you may have other classification models depending on the probability given by the beta regressor, let's say 5 models for targets between 0-10%, 10-20% and so on...
Treat your problem as a regression problem, but some questions arise: is '11111' truly close to '11112' in your dataset? i.e. are your labels a ordered set?

  So my question is if I should go on with the approach or are there better ideas? It is possible to use ANN to predict several properties (i.e. classes) at the same time?

Yes, an ANN can output more than one class for a sample (but will not work in such a large scale):

https://www.researchgate.net/publication/3297607_Multilabel_Neural_Networks_with_Applications_to_Functional_Genomics_and_Text_Categorization
https://arxiv.org/pdf/1312.5419.pdf


Python - Logistic (Logit) Regression - why am I getting an Endog error?

The error comes from attempting to fit a classifier (logistic regression) on a regression problem. If you are trying to predict prices (continuous outcome), you should use linear regression.


How to predict orders with a range of items? And total orders which sum up to the total?

You should munge the data until you have a target value that aligns with the goal of the project. Then fit a model.
It sounds like you want the target to be a binned number of items {(1-10), (10-20), (20+)}. Each row should be unique Order_ID with one of those three target values.


Discarding correlation among inputs in a neural network

You could try some feature selection techniques if you want to choose 3.

That said, have you tested the data for multicollinearity?  Maybe you have but I don't think that a1+a2+a3+a4=1 implies a high degree of correlation.

To answer your question though, it really doesn't hurt to try and train a neural net with the four variables.  If one of the inputs is unnecessary, the NN training may well set the weight on one to close to zero without you having to choose one.


Using the Datumbox Machine Learning Framework for website classification - guidelines?

You can make use of the text classification class for your task.first make sure how you are going to classify the websites.(i.e as sports site,health and wealth site etc).Get some training data and train them & Done


Can macro F1 score be greater than micro F1 score?

Yes, it can.

Example with Precision

Class A: 1 TP and 1 FP
Class B: 10 TP and 90 FP
Class C: 1 TP and 1 FP
Class D: 1 TP and 1 FP

Here, $P_A = P_C = P_D = 0.5$, $P_B = 0.1$

Macro-F1 is: $P_M = \frac{P_A + P_B + P_C + P_D}{4} = 0.4 $,
while micro-F1 is: $P_m=\frac{TP_A+TP_B+TP_C+TP_D}{TP_A+TP_B+TP_C+TP_D+FP_A+FP_B+FP_D+FP_D} = 0.123$, hence $P_M > P_m$.


Format for time series data with non-trivial sampled data

Based on this article about Data Formats in Data Science, the short answer to your question is: use JSON.

This may seem natural next step after csv and no more, but it is actually quite interesting:

JSON is widely supported in many programming languages, it is a valid MIME type in Internet standards (application/json, data stream mentioned in your question) and it has several standard and non standard extensions (geoJSON, binary json). If there is not a standard structure, JSON makes it easy to invent your own, because it is easily modifiable.

According to the article JSON works as value in HADOOP. For HADOOP it is suitable, because basically JSON is plain text when you think it as a data item.

Also article mentions JSON more efficient than CSV.


Reduce size of a network graph for bipartite projection

I think the problem is not with the data size, but with the presence of large degree nodes (the degree of a node is its number of neighbours).
Indeed all neighbours of a node in the bipartite graph are linked together in the projection; they form a clique (complete sub-graph) in the projection. This is terrible, as the number of links in a clique of $d$ nodes is $\frac{d\cdot(d-1)}{2} \sim d^2$.
In concrete words, a node of degree 2,000 in the bipartite graph will induce almost two million links in the projection... A node of degree 20,000 will induce almost two hundred million links...
For more discussion of the problems with projections of bipartite graphs, you may have a look for instance at this paper: Basic Notions for the Analysis of Large Affiliation Networks / Bipartite Graphs


How do I get Kera's to use more than 1 core?

If you are using tensorflow >= 2.0.0, you can try set the number of threads
tf.config.threading.set_intra_op_parallelism_threads(1)
tf.config.threading.set_inter_op_parallelism_threads(112)

or you can look thread limit number of cores


Is there a benefit to using hadoop with only one node?

If you are testing or building something that will eventually be run on a distributed cluster, yes it make sense. If you're playing around to learn, yes. Otherwise no I don't see much value.


What is the advantage of a tensorflow.data.Dataset over a tensorflow.Tensor?

The main advantage is in domains where you can't fit all of your data into memory.
However, I've seen improvements in performance even in cases where I have all my data into memory. I think two reasons contribute to this:

One is caching, where some operations (e.g. a mapping OP) will be cached and performed only in the first epoch. This, obviously is applicable if you have such a function.
Another one is prefetching. While a the model is being trained on a batch in the GPU, the CPU loads and prepares the next batch. This can help save a lot of time.

Some other capabilities are allowing for the vectorization of user defined functions (e.g. for data augmentation) and their parallelization.
You can take a look at some benchmarks here. They are a bit unrelated, as they refer to cases where the dataset isn't all loaded into memory, but they might interest you nevertheless.


Similarity measure for ordered binary vectors

One thing you could do is fuzzify your vectors: replace each 1 by (for example) 0.4 in its position, 0.2 in the neighbouring positions, and 0.1 in the second position over. Then add up what's in each position.
With these fuzzified vectors, you can apply a similarity metric either based on a distance or one like cosines similarity.
Your example would produce: (showing only first decimal)

0000011100 -> 0001378731

0000011110 -> 0001378873

1000011100 -> 4211378731

cos(x1, x2) = 0.9613,  cos(x1,x3) = 0.9469


Any tool to load large csv files quickly on windows 7

notepad++ will open a file of that size very quickly.


Run the lower casing operation before running stop-word removal since it is case sensitive.
Your window size, currently set to 2 is probably too low. Run it with default setting of 5. It will allow more natural similar pairs to be discovered (words frequently found in similar context but with distance more than 2). It would be also helpful to increase the minimum count threshold to weed out low frequency words which can give rise to spurious correlation.

In general, word2vec needs some manual tuning before the results start subjectively making sense (unless your dataset is very large).


Can clustering my data first help me learn better classifiers?

It is absolutely a way to improve your classifier's accuracy. Actually a "strong" enough classifier such as a neural network could be able to learn by itself these clusters. However, you would need a substancially deeper network.

The "smartest" way to do this, if you know there are many groups/clusters in your data is to actually perform a 2-steps process:

Cluster your data
Train X models, one for each of your clusters

A nice way to visualise this is the following problem, you want to build a recommendation engine for a Netflix-like application, you don't want to build one model per person, how would you do this ?

First find clusters of similar users (geeks, SF fans, teenagers, etc.)
Fit one model for each of these clusters


No - GPT-3 API is not currently public.
However once you get access, the documentation can be found at https://beta.openai.com/api-ref.


In any commerce setting, the concept of item similarity is very not straightforward. Two users usually buying same kinds of products can be considered as similar, but we cannot say the same about two items bought by same user.

There are two different concepts of item similarity for recommendation purposes. One is, if the two items are physically similar, for example : Blue Reebok Shoes and Red Reebok Shoes, and other is if they have functional dependency on each other, for example: Reebok Shoes and Reebok Socks.
For finding physically similar items, one can create a dictionary of attributes defining the product and do Jaccard similarity on those attributes.
For example:

Item A = {color: Blue, size: 10, material: Cotton, brand: Reebok}

Item B = {color: Red, size: 10, material: Cotton, brand: Reebok}

Thus, the intersection of sets would be number of attributes that match up, i.e.

Intersection(A,B) = {size, material, brand}

Union(A,B) = {color, size, material, brand}

Jaccard Index = 3/4 = 0.75

For finding behaviorally dependent items, one proxy that is generally used is more the two items are bought together in same session, more dependent they are for each other's functioning, thus more valuable recommendation. For this setting, one can create a matrix of products a user buys in a single session. For m users and n products it would be sparse m X n matrix. If we read the same matrix column wise, that would be set of users who bought the item in a particular session.

Thus,

Item A = {Ua, Ub, Uc}

Item B = {Ub, Ud}

Jaccard Index = 1/4 = 0.25


General question on the approach to optimise numbers

For this, you can treat output provided by "person in charge" as ground truth. I assume that you have historical records of :

Numbers generated by this person
Parameters that were fed into the model to generate numbers

treat these 400 parameters are train_x and numbers generated by the person as train_y.

Once you have this data in CSV, you can explore various Algo to find a model that can match train_y with minimal error.

Since no details are available on "how" either of these outputs are produced, you need to pick a tool that enables quick experimentation.

I will suggest Weka since this is a UI tool and does not require any coding. Once you identify an Algo, you can implement it in Python.

Some tutorials :

https://www.youtube.com/watch?v=6tDnNyNZDF0

https://www.youtube.com/watch?v=kFKxUQDnLV8

https://www.youtube.com/watch?v=COpXNK0O8As


Rank feature selection over multiple datasets

An easy one to try would be average ranks, where you take the mean of the ranks for each feature. For your example,

$
\begin{array}{cc}
  \textbf{Feature} & \textbf{Avg. Rank} \\
  1 & 1.5 \\
  3 & 2 \\
  2 & 2.5 \\
  4 & 4 \\
\end{array}
$

You could also weight the ranks by the size of the dataset, if the datasets that you are testing on are not the same size.


K-means clustering of word embedding gives strange results

Word embeddings are trained by substitutability, not similarity.

If you consider a sentence like "This food is unflavored." Then a good substitute word would be "flavored", and the sentence will still be "correct".

In many cases, substitutability arises from similarity (crunchy, crispy) but it does also arise from opposites. You may consider "king" and "queen" to be opposites, too.

You probably should use a supervised approach then.


How to extract data from an API every hour in Python?

Assuming that example is working for you, trying to write the data every 3 seconds, you need to just change the scheduling to be

schedule.every(1).hour.do(write_to_excel)

You are currently writing the data at each interval to the same file, so you will overwrite the file every time. You could do a few things here:

Open the excel file (e.g. into a pandas DataFrame), append the new data and save it all back to disk. This is pretty inefficient though and will have problems once you have a lot of data.
Write the data to a database, extending it every hour. This is the most professional solution.
Write a new file to disk each hour, including e.g. the timestamp of the hour in the filename to make each file unique. This is simple and just means you iterate over the files one-by-one when reading them later to do analysis or plotting etc.

You could change your function to be like this, implementing the first option above:

def request_data_and_save(excel_file: str = "air_quality.xlsx"):
    request = requests.get("https://api.waqi.info/feed/paris/?token=?")
    request_text = request.text
    JSON = json.loads(request_text)

    filterJSON = {
        'time': str(JSON['data']['time']['s']),
        'co': str(JSON['data']['iaqi']['co']['v']),
        'h': str(JSON['data']['iaqi']['h']['v']),
        'no2': str(JSON['data']['iaqi']['no2']['v']),
        'o3': str(JSON['data']['iaqi']['o3']['v']),
        'p': str(JSON['data']['iaqi']['p']['v']),
        'pm10': str(JSON['data']['iaqi']['pm10']['v']),
        'pm25': str(JSON['data']['iaqi']['pm25']['v']),
        'so2': str(JSON['data']['iaqi']['so2']['v']),
        't': str(JSON['data']['iaqi']['t']['v']),
        'w': str(JSON['data']['iaqi']['w']['v']),
    }

    # Get a writer and append data to the file
    with pd.ExcelWriter(excel_file, mode="a") as xl:
        df = pd.DataFrame.from_dict(filterJSON)
        df.to_excel(xl)

if __name__ == "__main__":
    schedule.every().hour.do(write_to_excel)
    while True:
        schedule.run_pending()

NOTE: this code is not tested


If you have imbalanced classes (for example, if you have 3 classes and 100 examples of class 1 and 1000 examples of class 2 and 5000 examples of class 3), then yes, I would weight the loss function (I would use weighted categorical cross-entropy).

If you mean some classes have a higher probability than others, then this is normal and expected behaviour. For example, if you were doing a 10-class classification problem like on MNIST, and you're trying to predict a given image, if the image has some rounded sections then it's much more likely to be a 3 or an 8 than a 1.


This is called sequence classification. An approach to attack this problem is to deploy an LSTM-RNN. The key is the preprocessing of the dataset; how you encode a written question into appropriate input for the network.

The answer to this is called word embedding and detailed instructions of how to implement it can be found in this tutorial, hope it helps :)


Using a loop to predict longer vectors with a LSTM

I'm going to answer to myself since I managed to fix that issue. The problem is that my model was overfitting waaaay too much and I had to add a dropout between each layer.

Now the result is better :

I will now re-tune my model and improve it a bit.

note to myself : don't be lazy Julien, plot the validation loss next time

EDIT :

I trained it during 36 mn with more neurons per layer. Without overfitting, it's way way better.

Now I can predict 8 days of datapoints with a better accuracy.


You should save the scaler params used to fit the training set and use the same ones to transform all other data used with the model from then on - whether CV, test or new unseen data.

  After training/testing my algo, I will make new predictions using new actual data which will not be scaled or normalized.

No that won't work. Once you add scaling/normalisation to the training pipeline, the exact same scaling (as in same scaling params, not re-calculated) should be applied to all input features.

The scikit-learn scalers like e.g. StandardScaler have two key methods:

fit should be applied to your training data
transform should be applied after fit, and should be used on every data set to normalise model inputs.

fit_transform can be used on the training data only to do both in a single step.

If you need to do the training and predictions in different processes (maybe live predictions are on different devices for instance), then you need to save and restore the scaling params. One basic, simple way to do this is using pickle e.g. pickle.dump( min_max_scaler, open( "scaler.p", "wb" ) ) to save to a file and min_max_scaler = pickle.load( open( "scaler.p", "rb" ) ) to load it back.


Usually you have to add a Dense layer after the LSTM unit. That will try to understand how to use the output of LSTM.

For example in Keras:

model = Sequential()
model.add(LSTM(4, input_shape=(1, 5)))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam')


How can I filter and balance a Windowed Tensorflow dataset with a binary classification label, based on the label?

Figured it out. Had to specify the position of y[0] instead of just y as I guess it's not just an integer but rather an array or tuple with one item, and the filter had to be done after the flatmap.

tensor= tf.data.Dataset.from_tensor_slices((tf.constant(DFrame[DFrame.columns.values[:-1]].values), tf.constant(DFrame[DFrame.columns.values[-1]].values)))

tensor = tensor.window(hindsight,1,1,True)

tensor = tensor.shuffle(1000)

tensor = tensor.filter(lambda x,y: tf.equal(y, 0))

tensor = tensor.flat_map(lambda x,y:tf.data.Dataset.zip((x.batch(hindsight), y.batch(1))))

tensor = tensor.batch(Batch_size).prefetch(1)

TypeError: Failed to convert object of type <class 'tensorflow.python.data.ops.dataset_ops._VariantDataset'> to Tensor. Contents: <_VariantDataset shapes: (), types: tf.int64>. Consider casting elements to a supported type.


What causes the Shape (convex or non-convex) of the cost function?

The cost function is convex if its Second Order Derivative is positive semidefinite (i.e. $\geq0$ ).

But this definition depends on the function with respect to which you take the derivative. This convexity changes when we are talking about Neural Networks, as in that case, our derivatives are taken with respect to the weights.

Refer: Why Cross Entropy is convex, but not necessarily in neural nets and Why RMSE is convex but not necessarily in neural nets


What is the use of @ between two matrices

According to here,  the matmul function implements the semantics of the @ operator introduced in Python 3.5 following PEP465.

Hence, rather than np.matmul(a,b).

We can use a @ b instead.


MOOC or book on Deep Learning in Python for someone with a basic knowledge of neural networks

Since you like Keras, the main author has written a book on deep learning with Python. You can check out the sections to see if it covers all the topics you want.


How to use auxiliary target variables only present in train data

It is not possible to predict outcomes of ideas like this with certainty. Too much depends on the specifics of your problem and dataset. You will have to do the experiments yourself. With a decent auto-differentiation engine like TensorFlow or PyTorch, you could try all your different ideas really quickly, with a few variations.

Here is what I think will happen from an intuitive guess:

  Should I try to predict y1, y2, y3, then calculate Y and pass it to a loss function

I think this has potential to be the strongest model, as it incorporates knowledge that you have of the problem into the structure of your model, whilst not adding more hyperparameters. This may also allow you to use less parameters to achieve the same accuracy, plus may work as a form of regularisation.

  Should I try to predict Y standalone and ignore y1, y2 and y3?

This should be considered the default/benchmark model, and you will want to run that anyway. If you only make one model, make this one.

If you run comparisons, you will want to compare best model of this type with best model(s) of other types. Don't just try the same network with an altered top layer to change the prediction mechanism - that will not explore your idea well enough to give you an answer.

  Should I try to predict the 4 of them and penalize my model when Y != y1 * y2 * y3 ?

I expect this would be the hardest to train. Although it may still add some regularisation effect, your problem is that the "best" model in this category may rate consistency over accuracy - you will need to play with different weightings of the penalty metric to find a compromise loss function.

Remember to use cross-validation and test data in order to search parameters and get fair unbiased measures of performance of the best model from each of the approaches at the end.


Regression Trees - Splitting and decision rules

Short Answer

1.Yes feature variables are needed for split. No the best 2 subsets for mse reduction are not created.
2.Yes

Long answer
Decision trees are greedy algorithms that choose a feature and split at each node and use that feature and cut to divide the data.

So as you mentioned in point 2 the tree starts building with all y values in the first node and iterates over all combinations for each feature and selects the best feature and value split to divide into 2 groups which are further split.

The termination conditions would be number of observations in the leaf node and/or the threshold for decrease in mse from in the split.


In general, you can't. You can find a matrix that will minimize $||\tilde{A}^TB-C||$, and another that minimizes $||\tilde{A}-A||$, but, in general, the two matrices you find won't be the same. In fact, the matrix that solves the second problem is always $\tilde{A} = A$, and, if $||{A}^TB-C||$ is not the minimum of the first function, then your problem doesn't have a solution.

However, what would a machine learning practicioner do? Instead of finding a matrix that solves both of the problems (that might not exist), you can aim to solve a combination of the two problems. You can aim to find the matrix that minimizes
$$||\tilde{A}^TB-C||^2 + ||\tilde{A}-A||^2
$$
or, in general, the matrix that minimizes
$$||\tilde{A}^TB-C||^2 + \lambda ||\tilde{A}-A||^2
$$
for some $\lambda >0$. If $\lambda \approx 0$, then you are just solving the first problem, and if $\lambda >>0$, then you are just solving the second one.

And, this is just a quadratic optimization problem, that can be solved using gradient descent and will provide a unique global maximum.


Can we use machine learning to generate a text output based on the input strings

Yes, sequence 2 sequence models attempt to do this. This can be used in a number of domains, from typo fixing to machine translation. They are encoder -> decoder based, which means you have a part that encodes your input and then a decoder that generates a new sequence based on this encoding (and usually some attention). In this case your encoder would likely be two recurrent neural networks of which the output would be concatenated and then a decoder that takes this concatenated output and turns this into a new sequence. If you want to use attention you need to adapt the standard attention a bit because you have two textual inputs, but if you understand how it works this would not be too difficult to adapt.


How can I deal with circular features like hours?

The question was already posted, you can find the answer there :

What is a good way to transform Cyclic Ordinal attributes?

The idea is to transform your time feature into two feature : it's like if you represent the hour as the angle of the hand on the clock, and use the sin/cos of the angle as your features


Calculating Rank Ordering Error Metric for implicit recommendation

I found a video called "Evaluating Implicit Ratings Models" by Datacamp. It is an explanation of evaluation of recommendation engines that use Implicit Ratings. Although they refer to the metric differently by calling it Rank Ordering Error Metric, the formula they give is identical to the one defined in the paper I linked in my question. Following along with the examples in the video and plugging in the values from their examples, I get the same result they do. I guess it seems slightly less than intuitive but I appear to be understanding how it works correctly anyway.


How does the descending gradient know what weights to adjust?

In general (or at least the basic implementation for the gradient descent), you apply for each iteration the update rule for each weight, using the partial derivative of the loss function with respect to that weight, as follows:


I do not think you can estimate the effect of a variable without adding it to the model. This is because the effect of a variable on the model's discriminatory power depends on

the strength of association between the outcome variable and the new variable
whether the new variable are collinear with some of the old variables

You could in principle estimate both strength of association and collinearity, but it probably is bad practice and would result in overfitting.

Also in general I think it is best to not use accuracy to evaluate a logistic regression (see ref) but rather a proper scoring rule like Brier Score.

Further, when comparing two nested models (i.e. where one model contains a subset of the variables of the other model) I believe that best practice is to compare the AIC or BIC, or perform a likelihood ratio test.


Hindsight Experience Replay: what the reward w.r.t. to sample goal means

...  the reward is now a function of action taken in state given the sampled goal.

I believe the action taken is that from the original goal, not from the newly sampled goal (as you say you understand). Otherwise I think you have everything more or less correct.

We see in the first block of the algorithm, that each action $a_t$, given the current goal, g, results in the reward, $r_t$ (as usual). This is stored, along with the new state $s_{t+1}$ concatenated with the current goal (shown by the || symbol). This is highlighted as being standard experience replay.

In the second block, using the sampled (virtual) goals $g'$, we receive a virtual reward for our performance using the same action as previously $a_t$. This is repeated for some number of simulated goals, selected by a sampling strategy, of which several are discussed in Section 4.5.

I myself was wondering how many replays are sampled, as it seems that the key there is to sample enough, so that the buffer itself sees the right balance of additional goals (to reduce the reward density), but not so much that the virtual HER recordings from the second for-loop do not outnumber the real performed goal-action pairs from the first loop. In the paper (Section 4.5), this seems to be around the $k=8$ mark, where $k$ is the ratio of sampled/virtual goals to the original goals.

So I believe the sampled goals that are indeed visited states from the original goal, would indeed receive a non-negative reward.

I think the following is a key statement to help explain the intuition:

  Notice that the goal being pursued influences the agent's actions but not the environment dynamics and therefore we can replay each trajectory with an arbitrary goal assuming we have an off-policy RL algorithm like DQN ...

This is very true in life. Imagine you try to throw a frisbee straight across a field to a friend. It doesn't make it, instead flying off to the right. Although you failed, you could learn that the wind is perhaps blowing left to right. If that had just so happened to be the task at hand, you would've received some positive reward for it!
The authors sample many additional goals, which in my analogy, may be the flight dynamics of that particular frisbee, the air density/humidity etc.

The main contribution of this paper, is a method to increase the density of the reward function i.e. to reduce how sparse the reward is for the model while training. Sampling these additional goals after each attempt (failed or otherwise) gives the framework the opportunity to teach the model something in each episode.

In the grid-based example, if for example the agent doesn't reach the final goal (as its original goal), it records -1 to the replay buffer. Then other goals are sampled from the possible next steps according to a sampling strategy, $\mathbb{S}$. For If you were close to the goal, it would make sense that sampling from future states selected at random from the same episode - after the transition - that you would likely end up at the goal. It is important here to realise that the goal has changed, which allows reward to be received. I point this out because the goal usually doesn't change in grid-based games; however, the experiments in the paper were performed on a robotic arm with 7-DOF in continuous space (only the reward was discrete).

EDIT

Below is a sketch of an example path, where we reach the final goal after 10 transitions (blue arrows). I set $k = 4$, so in each of the states $s_t$, we also have 4 randomly selected goals. We then take the corresponding action $a_t$ for the current state, which is the blue arrow. If the randomly sampled goal, $g'$, happens to be the same as $s_{t+1}$, we get a non-negative reward - these are the orange arrows. Otherwise, a negative reward is returned: the green arrows.

This is an example of the random sampling strategy, as my sampled goals $G$, are states that have been encountered in the whole training procesdure (not just the current episode), even though you cannot see it in my sketch.

So here we see there are 4 sampled goals, whch do indeed return non-negative reward. That was chance. The authors do say that:

  In the simplest version of our algorithm we repla each trakectory with the goal $m(s_T)$, i.e. the goal which is achieved in the final state of the episode.

In that case, it would mean $k=1$ and is always simply where the episode ended. This would mean negative rewards in the HER portion of the algorithm for all time steps exluding the final, $t=T$, where we would reach the sampled goal.

That would indeed equate to the model having learned from an otherwise failed episode. In every single episode!


F1 maximization with convolutional neural net. for an imbalanced dataset

I have a paper where we try to maximize F1 score by using different techniques. We hoped that a ranking algorithm like RankNet would be able to get better F1 score than the others. But as you can see looking at our table, regular neural networks, without even using a cost matrix, were good enough. Creating synthetic samples until classes were balanced and even using MetaCost was also largely irrelevant.

We did have a F1 gain when using RankNet, but that was likely due to our post-processing where we convert the ranking score into classes. But that is a pain. I think you can get similar results by, instead of using 0.5 as your threshold for choosing the positive class, choosing a threshold that maximizes the F1 score by just using the training data.

After working on class imbalance for awhile, I think this topic is a great way to get many publications easily, but, in the real world, a post-processing step and/or using a cost matrix to balance priors is more than enough.

ps: Please do not take this results as holy grail. Neural networks are notoriously difficult to optimize, especially across a range of very different datasets. Some cross validation was performed as mentioned in the paper, but, due to lack of time, not as much as we should have. And we did not allow that many iterations. I would try in your own code to introduce weights and some simple things to see if it makes a difference. Do let me know how it works please.


You have to read the file line by line, you can find a detailed answer in this question of stackoverflow


How to deal with a sparse matrix when using a perceptron based recommender system?

Recoding the NAs to 0's is not what you want. Think of what this means: a missing value on an item for a particular user means that said user hasn't seen or listened to or bought (depending on what kind of data you have) that item, while a zero value means that the user disliked that item; so they have completely different meanings.

The goal of a recommender system is basically to fill those NA values in a way that "makes sense". It is very common to have sparse matrices in recommender systems. I don't know exactly what kind of approach you're using or why you're using a perceptron, but I would recommend you to check how matrix factorization for recommender systems works ("Matrix factorization for recommender systems" by Robert Bell, Chris Volinsky and Yehuda Koren is a good paper) and see if this approach works for your problem.

You can also try first a simple baseline model that takes into account the biases of the users and the biases of the items; Bell, Volinsky and Koren's paper is a good start.


Why dont you have a look at the following example?
http://bl.ocks.org/mbostock/2066421

You can also find a fiddle here: http://jsfiddle.net/boatrokr/rk2s5/

Pay attention to the part where the links are defined.