One multilabel classifier or one for each type of label? Let's say I need to classify addresses with scikit-learn, so if I want my classifier to be able to classify addresses by the street name, and post/zip code, should I do a OneVsRest classifier, or separate them into two different classifiers (for the same training set)?

I have tried both, and it seems like having multiple classifiers might be a better choice, as it feels faster to train multiple smaller classifiers. Is this how it is supposed to be done?

Both ways are valid and both are commonly used. Sometimes, a classifier that claims to be multilabel may just be separating the labels into multiple OneVsRest classifiers under-the-hood and conveniently joining the results together at the end.

However, there are cases where the methods are fundamentally different. For instance, in training a neural net with multiple targets (labels), you can setup the structure of the network such that there is shared structure. The shared nodes will end up learning features that are useful for all the targets, which could be very useful.

For example, if you're classes (labels) are "cat-pet", "cat-big", and "dog", you may want an algorithm that first learns to distinguish between any cat and any dog, and then in a later step learns to separate cats that are pets from cats that are big (like a lion!). This is called hierarchy, and if your classifier can exploit hierarchy you may gain better accuracy. If your classes are completely independent however, it may not make any difference.

I suggest you start with the method that is easiest (i.e. OneVsRest), and see if the performance is suitable to your needs, then move to more complicated methods (multilabel, hierarchical methods, etc) only once you need better performance.


How hidden units are conditionally independent in restricted Boltzmann machines Why explaining away concept is not applicable in restricted Boltzmann machines? Their hidden units form a V structure from which probabilistic influence can flow given the observed visible variable. Why is this a problem in deep belief nets?

It would be too lengthy to do the derivation here. Would highly recommend watching this video, where Hugo Larochelle has derived the conditional independence of hidden units in RBMs.

Hope this video answers all of your questions, which seem to spur from conditional independence of RBMs. If not, it would be helpful if you could elaborate your question and provide some more context.


Should I scale my features? I have a dataset that looks something like this;

ID    | Location | Job_title | blue_jumper | red_jumper | yellow_jumper | green_jumper | Target(purple_jumper)
-------------------------------------------------------------------------------------------------------------------
B7372 | Rome     | Builder   | 2           | 1          | 0             | 9            | 1
D9823 | London   | Lawyer    | 0           | 1          | 8             | 3            | 0
E8718 | Rome     | Teacher   | 3           | 0          | 2             | 3            | 1

etc etc.....

What I would like to do is to use this information to predict whether a person will have a Purple jumper (Target 1 or 0)

Things to note about this dataset I think are the following;

I have an ID that relates to the individual
I have a number of catergorical features
I have some information relating to features that are of the same type (jumpers) but differing by some aspect (colour)
These features are of the same type as the Target (e.g jumpers)
The target is binary (e.g. I am not looking to predict how many Purple jumpers a person has, just whether they have one or not)

As the Target is binary I know I could use a classification method but I have decided to use Multiple Linear Regression. I like this algorithm because it gives me a measure out that is equivalent to how much like a 1 or 0 my record is.

I have generated dummies for my categorical features but what I am struggling with is whether or not to scale my other features in a situation like this.

It is not necessary to scale your numerical values when using linear regression. However, people still do it since it can speed up training if the algorithm uses gradient descent and it might make your coefficient and intercept terms more interpretable.

You can read more about it here: https://stats.stackexchange.com/questions/185624/feature-scaling-normalization-in-multiple-regression-analysis-with-normal-equa

On another note, there are a lot of binary classifiers that will give you a probability instead of a binary output. For instance, in sklearn many binary classifiers have a predict_proba method that does just this. I can recommend random forest.


Extract imperative sentences from a document(English) using NLP in python I am very new to NLP, hence require some help on extracting imperative sentences from a document. I am working on a project where I need to get all the imperative sentences from the entire document(English documents). I understand I need to use POS tagging. But how do I proceed further.

Thanks.

In order to maximize accuracy you would need to use not only a POS tagger but also a syntactic parser. Nevertheless for this task POS tags can probably give you reasonable results indeed, here is a general method:

Segment the data into sentences and tokens
Apply the POS tagger (it predicts a POS tag for every token)
A sentence is (likely) imperative if the following conditions are satisfied:

the sentence ends with a full stop or exclamation mark
the POS for the first token corresponds to a verb

This heuristic is probably all you need, but if you want to go further you could generate instances containing these features (and possibly add a few others)  for every sentence, annotate a training set and train a supervised model.


ANN applied to Boston Housing dataset returns negative value This example is taken from the book Deep Learning With Python from Jason Brownlee. It  applies a fully connected neural model with one hidden layer  (13, 13, 1) using Keras library and the Tensorflow backend.

1 - Import the packages

import numpy
from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasRegressor
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import KFold
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.datasets import load_boston

2 - Load the dataset

boston = load_boston()
X = boston.data[:,0:13]
Y = boston.target

3 - Define base model

def baseline_model():
    # create model
    model = Sequential()
    model.add(Dense(13, input_dim=13, \
                    kernel_initializer='normal', activation='relu'))
    model.add(Dense(1, kernel_initializer='normal'))
    # Compile model
    model.compile(loss='mean_squared_error', optimizer='adam')
    return model

4 - Fix random seed for reproducibility

seed = 7
numpy.random.seed(seed)

5 - Fit & evaluate model

estimator = KerasRegressor(build_fn=baseline_model, epochs=10, \
                           batch_size=5, verbose=0)
kfold = KFold(n_splits=10, random_state=seed)
results = cross_val_score(estimator, X, Y, cv=kfold)

6 - Value of results parameter

Out[63]:
array([-13.89524042, -14.2215869 ,  -6.21156782, -42.65242339,
       -26.58890147, -56.30860755, -28.6575911 , -89.67339525,
       -27.7172946 , -22.67604859])

Which returns a mean negative value

print("Baseline: %.2f (%.2f) MSE" % (results.mean(), results.std()))

It returns about -30 and it should return about +30 according to the book. I've tried both Theano and Tensorflow with no success.

I've also tested this code both on Windows and Linux, having obtained the same bad result.

The problem seems to be in the cross-validation part, because if I don't run cross validation, I get more sensible results.

7 - Without cross-validation

model = Sequential()
model.add(Dense(13, input_dim=13, kernel_initializer='normal', \
                activation='relu'))
model.add(Dense(1, kernel_initializer='normal'))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(X, Y, epochs=150, batch_size=10)

Now if I evaluate the model I get a more sensible value

In [68]: model.evaluate(X, Y)
506/506 [==============================] - 0s 58us/step
Out[68]: 27.778296670423664

What can be happening here? Why is the cross-validation procedure returning negative values?

"This is to be expected. sklearn has changed their API to invert their cost functions. Nothing to be concerned about."

I got this answer from Dr. Jason Brownlee.


Making predictions / Loading model in TensorFlow 2.0 I use TensorFlow/Keras on a daily basis to make predictions for a project. Everything works fine but I was getting regular warnings about the transition to TensorFlow 2.0 and I thought this week I would finally make sure my code works in the new version of the library as well. I did not encounter any problems during training or saving a model, but when it comes to making predictions I got the following warning:

  WARNING:tensorflow:Your input ran out of data; interrupting training.
  Make sure that your dataset or generator can generate at least
  steps_per_epoch * epochs batches (in this case, 10 batches). You may
  need to use the repeat() function when building your dataset.

Turns out it still does the prediction as expected, but the warning slows down the process considerably. I was able to overcome this by passing steps=1 argument to model.predict(), but this seems like a roundabout way of doing things, which was not needed in the previous version of TensorFlow.

I wonder if I am missing something trivial here. Also, it seems like TensorFlow now fails to figure out that I am doing prediction not training, which also was not an issue before. On a related note, it was probably in the documentation before as well but I never thought about the batch_size argument in model.predict() and the purpose it serves.

Update:

Now that Google Colab changed their default version to TensorFlow 2, I decided the give it another shot. Now, the code is still entirely the same, but there is an error when I try to load a model:

  WARNING:tensorflow:Error in loading the saved optimizer state. As a
  result, your model is starting with a freshly initialized optimizer.

There is an open question on TensorFlow github page on this issue:

https://github.com/tensorflow/tensorflow/issues/37968

I will update again when it is resolved.

I had the same problem in TF 2.1. It has something to do with the shape/ type of the input, namely the query. In my case, I solved the problem as follows: (My model takes 3 inputs)

x = [[test_X[0][0]], [test_X[1][0]], [test_X[2][0]]]
MODEL.predict(x)

Output:

  WARNING:tensorflow:Your input ran out of data; interrupting training.
  Make sure that your dataset or generator can generate at least
  steps_per_epoch * epochs batches (in this case, 7 batches). You may
  need to use the repeat() function when building your dataset.

array([[2.053718]], dtype=float32)

Solution:

x = [np.array([test_X[0][0]]), np.array([test_X[1][0]]), np.array([test_X[2][0]])]
MODEL.predict(x)

Output:

array([[2.053718]], dtype=float32)


Nearest neighbors search for very high dimensional data I have a big sparse matrix of users and items they like (in the order of 1M users and 100K items, with a very low level of sparsity). I'm exploring ways in which I could perform kNN search on it. Given the size of my dataset and some initial tests I performed, my assumption is that the method I will use will need to be either parallel or distributed. So I'm considering two classes of possible solutions: one that is either available (or implementable in a reasonably easy way) on a single multicore machine, the other on a Spark cluster, i.e. as a MapReduce program. Here are three broad ideas that I considered:

Assuming a cosine similarity metric, perform the full multiplication of the normalized matrix by its transpose (implemented as a sum of outer products)
Using locality-sensitive hashing (LSH)
Reducing first the dimensionality of the problem with a PCA

I'd appreciate any thoughts or advices about possible other ways in which I could tackle this problem.

I hope that the following resources might get you additional ideas toward solving the problem:

1) Research paper "Efficient K-Nearest Neighbor Join Algorithms for High Dimensional Sparse Data": http://arxiv.org/abs/1011.2807

2) Class project paper "Recommendation System Based on Collaborative Filtering" (Stanford University): http://cs229.stanford.edu/proj2008/Wen-RecommendationSystemBasedOnCollaborativeFiltering.pdf

3) Project for the Netflix Prize Competition (k-NN-based): http://cs.carleton.edu/cs_comps/0910/netflixprize/final_results/knn/index.html

4) Research paper "Hubs in Space: Popular Nearest Neighbors in High-Dimensional Data" on the curse of dimensionality phenomenon and its relation to machine learning, in general, and k-NN algorithm, in particular: http://jmlr.org/papers/volume11/radovanovic10a/radovanovic10a.pdf

5) Software for sparse k-NN classification (free, but appears not to be open source - might clarify with authors): http://www.autonlab.org/autonweb/10408.html

6) Several discussion threads on StackOverflow:

https://stackoverflow.com/questions/20333092/knn-with-big-sparse-matrices-in-python
https://stackoverflow.com/questions/18164348/efficient-nearest-neighbour-search-for-sparse-matrices
https://stackoverflow.com/questions/21085990/scipy-sparse-distance-matrix-scikit-or-scipy
https://stackoverflow.com/questions/10472681/handling-incomplete-data-data-sparsity-in-knn
https://stackoverflow.com/questions/5560218/computing-sparse-pairwise-distance-matrix-in-r (unlike all previous discussions, which refer to Python, this one refers to R ecosystem)

7) Pay attention to GraphLab, an open source parallel framework for machine learning (http://select.cs.cmu.edu/code/graphlab), which supports parallel clustering via MapReduce model: http://select.cs.cmu.edu/code/graphlab/clustering.html

You might also check my answer here on Data Science StackExchange on sparse regression for links to relevant R packages and CRAN Task View pages: https://datascience.stackexchange.com/a/918/2452.


Autoencoder for anomaly detection from feature vectors I am trying to use an autoencoder (as described here https://blog.keras.io/building-autoencoders-in-keras.html#) for anomaly detection. I am using a ~1700 feature vector (rather than images, which were used in the example) with each vector describing a different protein interaction. I have a "normal" category of interactions on which I train the AE, then I feed it new vectors and use reconstruction error to detect anomalous interactions.

Adjusting my threshold so I get a true positive rate of 0.95, I get a false positive rate of 0.15, which is rather high. When I trained xgboost on the normal and anomalous vectors (using both types of interactions in training and testing) I was able to get precision of 0.98 **.

Does that mean that my model (or indeed my approach of using an AE) is ineffective, or maybe this is the best I could hope for when training an anomaly detector rather than a 2 category classifier (that is, xgboost in my case)?
How should I proceed?

** Of course, this is merely a sanity check, and cannot be used as the solution.  I need the model to detect anomalies that can be very different from those I currently have - thus I need to train it on the normal interaction set, and leave anomalies for testing alone.

Does that mean that my model (or indeed my approach of using an AE) is ineffective

Well, it depends. Auto Encoder are a quite broad field, there are many hyperparameters to tune, width, depth, loss function, optimizer, epochs.

  How should I proceed?

From my gut feeling I would say that you don't have enough data to train the AE properly. Keep in Mind, the MNIST database contains 50,000 image. And you need enough variance in order to not overfit your training data. Tree based approaches are, at least in my experience, easier to train. If you like to stick at the anomaly detection part, which I recommend since you don't know what anomalies you will face, try the Isolation Forest Algorithm. But for a solid recommendation I would need to know how your data looks.

Btw, A good metric to use in such a case is  the ROC score, which basically tells you how likely it is that your model will classify new data points correctly. Check out the link for an visual explanationROC explained

So Baseline is, try less complex approaches until you a certain that they are not sufficient enough.


Unseen classes - 'Other' class or classifying based on the existing classes Let's suppose that I have a classifier which detects whether a script of code is written in Python or C++ or Java.

Therefore, my classifier has 3 outputs which give the probabilities that a certain code script is one of these 3 programming languages above.

However, unfortunately, there is the chance that the test data my contain some code scripts written in other programming languages such as Javascript, Ruby, PHP etc.

If I leave my classifier as it is then it going to classify these code scripts as being in Python or C++ or Java and this will be certainly pretty wrong and misleading.

Does it make sense to add another class called 'Other' which would contain code scripts of various other programming languages (Javascript, Ruby, PHP etc) or even irrelevant text to cope with that?

Is there any better idea?

You could definitely add more samples and tag it as other with your classifier. However, realistically this might not be an option. For this exact purpose, you could use confidence values with the output of your classifier to predict the "other" class. You could bring in confidence thresholding to support this, i.e if your classifier is not confident > 0.8 (as an example) with its prediction, then you tag it "other" class.

What is the best value to threshold with, you can identify by running a number of experiments with different threshold values and plot a graph for correctness i.e classification error rate graph.


Can pinball loss be used to construct a prediction interval? I'm modeling some time series data ($\{y_t\}_t$) and would like to construct a model that is able to return not just a single-value prediction $\hat{y_t}$, but an interval $C_t=(\hat{y}_{t, lower}, \hat{y}_{t, upper})$ such that $y_t \in C_t$ with some probability.

Now, I've learned about the pinball loss:
$$L(q, z)=\cases{qz, & z >= 0 \\ (q-1)z,& z<0}$$
If I understand it correct, $q \in (0,1)$ is the quantile that I want to predict, and $z$ is the difference between the actual value $y$ and what my model predicted $\hat{y}$. If the model is trained to optimize this loss for some $q$, it will return me the estimate $\hat{y}^{(q)}_t$ such that $P(y_t < \hat{y}^{(q)}_t)=q$. Is this interpretation correct?

Then, can I simply train two models, say one for $q=0.05$ and the other for $q=0.95$ in order to get the estimates of the intervals that contain the actual values with the probability $0.95-0.05=0.9$?

Yes, your interpretation regarding the pinball loss function seems right. For a given quantile value t between 0 and 1, it gives you the threshold value v.

  Then, can I simply train two models, say one for q=0.05 and the other for q=0.95 in order to get the estimates of the intervals that contain the actual values with the probability 0.95−0.05=0.9?
  `

And of course if you had trained two models to give threshold values for two quantiles, you can say that  $p(\hat{y}_{t, lower} \le y_t < \hat{y}_{t, upper}) = |\delta(q_1-q_2)|$


Plots with shaded standard deviation What tools can I use to make a visualization similar to this one? I want to have the mean be bolded and the standard deviation be shaded.

The below piece of code will generate the following Image(your's is Subplotting Three of them, so you will get 3 different axe's and per axes you have to use fill-between) (Kindly ignore the Axis Label's..)

plt.style.use('ggplot') #Change/Remove This If you Want

fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(trees_grid, train_acc.mean(axis=1), alpha=0.5, color='blue', label='train', linewidth = 4.0)
ax.plot(trees_grid, test_acc.mean(axis=1), alpha=0.5, color='red', label='cv', linewidth = 1.0)
ax.fill_between(trees_grid, test_acc.mean(axis=1) - test_acc.std(axis=1), test_acc.mean(axis=1) + test_acc.std(axis=1), color='#888888', alpha=0.4)
ax.fill_between(trees_grid, test_acc.mean(axis=1) - 2*test_acc.std(axis=1), test_acc.mean(axis=1) + 2*test_acc.std(axis=1), color='#888888', alpha=0.2)
ax.legend(loc='best')
ax.set_ylim([0.88,1.02])
ax.set_ylabel("Accuracy")
ax.set_xlabel("N_estimators")


Recommender system that matches similar customers with similar highly rated products? I have a dataset of 1,000 customers that bought 20 distinct phones and rated them 1-5. I have several demographic attributes for these customers (gender, age). My website offers 100 distinct devices, each with several attributes (screen size, case material, operating system, price).

For new customers, I want to recommend a ranked list of 5 devices they might enjoy. This might be based on 1) the new customer having a similar demographic profile to the 1,000 customers that gave ratings and 2) devices that were highly rated or had similar attributes to the devices that were highly rated by a similar customer.

All the examples I’ve found show how to make recommendations to similar customers for products that were rated highly by customers of similar profiles. I want to do this without limiting recommendations to the products that were rated. Instead, I want to build a system that might recommend phones I have ratings for, and also phones that haven’t been rated (ex: the phone is new, I need to get rid of inventory, or I want them to try something they might enjoy more) based on their similarity to other highly rated products by similar customers.

What is a good approach to build a recommended system for this scenario? I’ve read about content-based, collaborative filtering, and hybrid recommenders, but I can’t find a good example of this scenario. Is there a name for the type of system I am describing here?

You want to do three things:

Cluster similar customers based on their profiles and their preferences for certain devices
Cluster similar devices based on ratings but also device attributes
Create a recommender system based on clusterings 1 and 2

Here is how I would do it:

Cluster customers via usual means (PCA, K-Means, etc.) based on their demographics
For each cluster develop a model that predicts the "rating" of a device based on the devices attributes (e.g. via ensemble learning, association rules, etc.). Then use the model to predict the rating of a new device for each cluster!
Implement a simple recommender based on the cluster membership and a relevant device set based on ratings, this works because of step 2 each device now has a ranking. If you want to "manipulate the customer" further you can add simple rules to add devices below the relevant rating threshold if they satisfy certain criteria (price, "is on sale", etc.).

Voila!


Does reinforcement learning only work on grid world? Does reinforcement learning always need a grid world problem to be applied to?

Can anyone give me any other example of how reinforcement learning can be applied to something which does not have a grid world scenario?

The short answer is no! Reinforcement Learning is not limited to discrete spaces. But most of the introductory literature does deal with discrete spaces.

As you might know by now that there are three important components in any Reinforcement Learning problem: Rewards, States and Actions. The first is a scalar quantity and theoretically the latter two can either be discrete or continuous. The convergence proofs and analyses of the various algorithms are easier to understand for the discrete case and also the corresponding algorithms are easier to code. That is one of the reasons, most introductory material focuses on them.

Having said that, it should be interesting to note that the early research on Reinforcement Learning actually focussed on continuous state representations. It was only in the the 90s since the literature started representing all the standard algorithms for discrete spaces as we had a lot of proofs for them.

Finally, if you noticed carefully, I said continuous states only. Mapping continuous states and continuous actions is hard. Nevertheless, we do have some solutions for now. But it is an active area of Research in RL.

This paper by Sutton from '98 should be a good start for your exploration!


Relationship between train and test error I have some specific questions for which I could not extract answers from books. Therefore, I ask for help here and shall be extremely grateful for an intuitive explanation if possible.

In general, neural networks have a bias/variance tradeoff and thus we need to have a regularizer. Higher bias --> underfitting; Higher Variance--->overfitting.

To solve overfitting, we use regularization for contraining the weight. This is a hyperparameter and should be learned during training based on my understanding using cross-validation. Thus, the dataset is split into a train, validation and test set. The test set is independent and is unseen by the model during learning, but we have the labels available for it. We usually report the statistics such as false positives, confusion matrix, misclassification based on this test set.

Q1) Is this bias/variance problem encountered in other algorithms such as SVM, LSTM etc as well?

In convolutional neural network (Matlab toolbox) I have not seen any option for specifying the regularization constant. So, does this mean that CNN's don't need a regularizer?

Q2) What is the condition if training error and test error are both zero? Is this the ideal best situation?

Q3) What is the condition if training error > test error?

Q4) What is the condition if training error > validation error?

Please correct me where wrong. Thank you very much.

First of all be very clear with the use of the Training set, Validation set and  Testing set. These play a crucial part in  tuning your DL model. Usually, a validation dataset is used for keeping a check over the model during the training. An intutive observations are noted with the training validation and testing accuracy during data fitting:

If the model is having high validation accuracy and low training accuracy, it is an underfit model.
If the model has higher training accuracy and low validation accuracy, it is overfit.

Bias-variance trade-off problem is a central problem of supervised machine learning algorithms.

The bias–variance decomposition is a way of analyzing a learning algorithm's expected generalization error with respect to a particular problem as a sum of three terms, the bias, variance, and a quantity called the irreducible error, resulting from noise in the problem itself.

Ref


hierarchical clustering doesn't work as expected I have a precomputed distance matrix.

I'm trying to do an hierarchical clustering using scipy:

from scipy.cluster.hierarchy import fcluster, linkage, cut_tree,fcluster

z = linkage(ds, "average")
clust = fcluster(z, 4, criterion='maxclust')
print(clust)

The problem is that, most of the labels ends up in one group - Why?

By the way, I tried to use AgglomerativeClustering as well but I got similar results.

ds is the precomputed distance matrix. I'm using DTW, a distance metric for time series analysis.

I uploaded ds.csv to here.

Also, here's an heatmap which forms interesting lines (I don't really know how to interpret this currently)

Likely your precomputed distance matrix is bad.

Judging from your plot, it's probably a half-filled similarity matrix instead. And it likely is not in the required form for linkage.

  The input y may be either a 1d condensed distance matrix or a 2d array of observation vectors.

Did you make your distance matrix "condensed"? Otherwise it will be treated as data matrix, not distance matrix, because python does not have type safety but uses duck typing - if it quacks like a data matrix, it is a data matrix. Then you end up computing Euclidean distances on half-filled rows of this matrix...


You can define a custom distance metric using the metric parameter from sklearns KNeighborsClassifier where you can specify your callable function that gets called when calculating the distances from the algorithm. There you can weigh var_3 inversely proportional.


Compare scores of models We got several models with predictions. How can we compare scores of different models with each other?

We assume that we got xgboost models and scores distribution can be different for each model, so how can we compare scores?

I'm going to assume your using python and scikit-learn mostly because it has a method for providing model metrics.

from sklearn.metrics import classification_report

# I presume that you've already trained a model and it's saved as xgb
# X_test is your testing X data (NOT THE DATA YOU TRAINED ON!!!!)
# Y_test is the corresponding correct values
print('Accuracy score is: ',accuracy_score(Y_test, xgb.predict(X_test)) * 100)
print(classification_report(Y_test, xgb.predict(X_test)))
>>> Accuracy score is:  61.13989637305699
>>>           precision    recall  f1-score   support

           0       0.38      0.98      0.55        47
           1       0.99      0.49      0.66       146

   micro avg       0.61      0.61      0.61       193
   macro avg       0.68      0.74      0.60       193
weighted avg       0.84      0.61      0.63       193

As you can see there is lots of info available.
The accuracy score is the % of correct predictions overall.
And the classification report goes into more depth about how good the model is predicting each class more info here crossvalidated SE explanation.


Timing sequence in MapReduce I'm running a test on MapReduce algorithm in different environments, like Hadoop and MongoDB, and using different types of data. What are the different methods or techniques to find out the execution time of a query.

If I'm inserting a huge amount of data, consider it to be 2-3GB, what are the methods to find out the time for the process to be completed.

One option is the time command on the command line.


How to access GPT-3, BERT or alike? I am interested in accessing NLP models mentioned in scientific papers, to replicate some results and experiment.
But I only see waiting lists https://openai.com/blog/openai-api/ and licenses granted in large commercial deals https://www.theverge.com/2020/9/22/21451283/microsoft-openai-gpt-3-exclusive-license-ai-language-research .
How can a researcher not affiliated to a university or (large) tech company obtain access so to replicate experiments of scientific papers ?
Which alternatives would you suggest to leverage on pre-trained data sets ?

OpenAI has not released the weights of GPT-3, so you have to access it through their API. However, all other popular models have been released and are easily accessible. This includes GPT-2, BERT, RoBERTa, Electra, etc.
The easiest way to access them all in a unified way is by means of the Transformers Python library by Huggingface. This library supports using the models from either Tensorflow or Pytorch, so it is very flexible.
The library has a repository with all the mentioned models, which are downloaded automatically the first time you use them from the code. This repository is called the "model hub", and you can browse its contents here.


Logistic regression from scratch in Python Here is my logisticRegression class I developed to do gradient descent. There is this one line I marked as problematic

import numpy as np
class logisticRegression():
    """Logistic Regression classifier

    Parameters
    ----------
    alpha : float
        Learning rate(between 0.0 and 1.0).
    iters : int
        Number of iterations.

    Attributes
    ----------
    w_ : 1d-array
        Weights after fitting.
    """
    def __init__(self, alpha = 0.001, iters = 100000):
        self.alpha = alpha
        self.iters = iters

    def fit(self, X, y):
        """Fit training data
        Parameters
        ----------
        X : array-like, shape = [n_samples, n_features]
            Training vectors
        y : array-like, shape = [n_samples]
            Target values

        Returns
        -------
        self : object"""
        # Initialize weight
        self.w_ = np.zeros(1 + X.shape[1])

        self.errors_ = []
        m = X.shape[0]
        x0 = np.ones(X.shape[0])

        for _ in range(self.iters):
            h = self.hyp(X)
            gradient = (X.T)@(h - y)/m
            self.w_[1:] -= self.alpha*gradient
            self.w_[0] -= self.alpha*x0@(h - y)/m # This line is problematic !!!
        return self

    def sigmoid(self, z):
        """Compute sigmoid"""
        return 1/(1+ np.exp(-z))

    def hyp(self, X):
        """Compute hypothesis (probability)"""
        return self.sigmoid(self.w_[0] + X@self.w_[1:] )

I got wrong result. But if I rewrite this line as:

self.w_[0] -= x0@(h - y)/m # Remove the learning rate term

Then I got correct result. But this doesn't seem right. Did I oversee something here?

For those who care, it turns out that removing the learning rate just makes the gradient happen faster. If alpha not removed, things still converge but incredibly slowly (it takes millions loops to converge)
My theory is that my math was right, but plain gradient descent is computationally expensive.


Exploratory Data Analysis with Image Datset In Machine Learning Kernels on Kaggle I often see EDAs with structured data. So, I was wondering, if there are any recommended/standard procedures for EDA with image datasets. What kind of statistical analyses do you conduct, what kind of plots do you draw and what aims do you have in mind?

Have a look at The HASYv2 dataset. I tried to do as much of the exploratory work as possible to make sure that others can directly try more interesting thing with the dataset.

Image format specific stuff

(Minimum / Median / Mean / Maximum) (width / height / area)
Image formats
Timestamps
Exiff meta data

For this kind of stuff, you might want to have a look at edapy.

Image/ML specific stuff

Things you can do with images:

Compute the mean image

Mean image by class

Eigenfaces (or rather "Eigenimages")
Fisher-Faces

You can compute the correlation of pixels, e.g. Figure 3:

Classification-specific stuff

Plot the distribution of classes.
Behaviour of standard classification algorithms (CNNs, VGG-16)
Confusion Matrix Ordering (page 48 - 52, especially Figure 5.12 and 5.13): Find similar classes


Why might several types of models give almost identical results? I've been analyzing a data set of ~400k records and 9 variables The dependent variable is binary. I've fitted a logistic regression, a regression tree, a random forest, and a gradient boosted tree. All of them give virtual identical goodness of fit numbers when I validate them on another data set.

Why is this so? I'm guessing that it's because my observations to variable ratio is so high. If this is correct, at what observation to variable ratio will different models start to give different results?

This results means that whatever method you use, you are able to get reasonably close to the optimal decision rule (aka Bayes rule). The underlying reasons have been explained in Hastie, Tibshirani and Friedman's "Elements of Statistical Learning". They demonstrated how the different methods perform by comparing Figs. 2.1, 2.2, 2.3, 5.11 (in my first edition -- in section on multidimensional splines), 12.2, 12.3 (support vector machines), and probably some others. If you have not read that book, you need to drop everything RIGHT NOW and read it up. (I mean, it isn't worth losing your job, but it is worth missing a homework or two if you are a student.)

I don't think that observations to variable ratio is the explanation. In light of my rationale offered above, it is the relatively simple form of the boundary separating your classes in the multidimensional space that all of the methods you tried have been able to identify.


Transitioning to Data Science from Actuarial Science The title says it all, I want to transition from actuarial science to data science.
My background: I have a BS and MS in pure mathematics, both with high GPA (3.94) and graduation with honors. My areas of study were highly theoretical (Algebraic Geometry), though I took some statistics courses, computer science, and economics as well. I am savvy with R, Python, Sql, etc. Unlike some pure-mathy types I do communicate well and I do well at translating business questions into quantitative problems.
My motivation: I'm not really motivated by money, as most know actuarial science is already fairly high paying. I think I would enjoy a career in data science more than actuarial science. From the research I have done, the skill set and projects in the data science domain seem more intriguing to me. I have always been intrigued by deep learning, machine learning, etc. but since it wasn't directly relevant to my studies in school or my career I have never built a strong background in these areas.
My Attempts: I have sent out some applications for data science positions but haven't had any luck yet. I am located in the Seattle area and being a tech-y city I imagine there are a lot of competitive applicants for any jobs that get posted. I usually get a "thanks but no thanks" response within a week.
The question: How can I make myself more competitive and at least land some interviews. Since I have only worked in actuarial science (3 years experience), my resume and work history are only actuarial (however my last title within the actuarial domain was actually "Actuarial Data Scientist", we were making web applications for insurance clients that let them view models we built for policyholder behaviour and other things of interest.)  Most of the job postings request NLP, deep learning, machine learning experience, to which I have little exposure. I have been self-studying with PyTorch. What types of things can I be self-studying to make my skill set more desirable, and how can I communicate these skills through my resume? It seems uncommon to have a resume section titled "things I have learned in my spare time".
Obviously there are loads of things I could be studying and learning, so I scan job postings to try and narrow down the most commonly requested skills. What would be the best things I could start with, and then how could I incorporate these skills into my resume or cover letter?

Since you have both degrees in pure math, most likely you won't need to do another Masters or similar. For now, focus on making your CV look more like DS/AI/ML/DL. Keep in mind online courses at present do not increase the value of your CV too much. So this is not an easy task, but you have a good start with pytorch. What I'd do if I were you: assuming, you are interested in applying DL in computer vision. Here are some links:

kaggle.com (competitions)
paperswithcode.com
labelled datasets: Pascal VOC, MS COCO,
torchvision library (model zoo) for pytorch (simply import torchvision to get started)

What you should do, is 1) read through some papers on state-of-the-art OS solutions for CV, like Faster R-CNN, Mask R-CNN, 2a) use them in pytorch, they are available in torchvision and/or github, 2b) same with the datasets, 3) hack into them to understand them at a deeper level, luckily they are all opensource, 4) write your own functionality for them, 5) contribute to contests/OS packages, put up your own models on github
You can put all of the above, especially 4) and 5) on your CV. Good luck!


Skills that school doesn't teach you I'll be graduating soon with a master's degree in electrical engineering. I have a lot of experience with the theoretical side of machine learning through courses and research, but all of my experience with ML/data science is through Matlab.

Does anybody have insight as to skills that employers will expect me to add before I get a job? I've been looking at postings and it seems like most of the things that I'm not as sharp with are: SQL, Hadoop, Python, and R.

Are Python and R both necessary, or would that be redundant?
Is SQL and Hadoop something employers will overlook? Because quite frankly I find learning both to be unbearably boring.
Lastly, am I missing anything from this list of skills?

Based on my own experience and in reading what others have written, SQL is one of those skills employers look for, perhaps even assume that you have along with some of the basic skills of communication and teamwork.  The main reason is that lots of data are stored in a relational database with SQL being the primary way to extract that data to get it into your models.


How to compute F1 score? Recently I read about path ranking algorithm in a paper (source: Knowledge Vault: A Web-Scale Approach to Probabilistic Knowledge Fusion).

In this paper was a table (Table 3) with facts and I tried to understand how they were calculated.

F1 (harmonic mean of precision and recall) = 0.04
P (precision) = 0.03
R (recall) = 0.33
W (weight given to this feature by logistic regression)

I found a formula for F1 via Google which is

$F1 = 2 * \frac{precision * recall}{precision + recall}$

The problem is that I get the result of 0.055 with this formula, but not the expected result of 0.04.
Can someone help me to get this part?
Also, does someone know how 'W' can be calculated?
Thanks.

First you need to learn about Logistic Regression, it is an algorithm that will assign weights to different features given some training data. Read the wiki intro, is quite helpful, basically the Betas there are the same as the Ws in the paper.

The formula you have is correct, and those value do seem off. It also depends on the number of significant figures you have, perhaps they are making their calculations with more than the ones they are reporting.

But honestly, you can't understand much of the paper unless you understand LR


SRGAN Generator Architecture: Why is it possible to do this elementwise sum? Consider the first residual block. Its first convolution layer takes in inputs:

THe PRELU's output
64 filters(64 outputs) each one being 3*3 with a stride of (1 ; 1)

So I think that the output of this convolution will have a different shape than the PRELU's output's one.

Then there is a second convolution layer in this same first residual block. So the shape will be even more different!

The first residual blocks ends with an elementwise sum... Which has these problematic inputs:

PRELU's output
The Conv2D, BN, PRELU, Conv2D, BN output

The problem is that, as explained above, the PRELU's output will have a shape quite different than "the Conv2D, BN, PRELU, Conv2D, BN output"'s shape.

So how is it theoretically possible (then technically, using Keras) to do this elementwise sum?

Edit: by "shape", I mean "width, height and eventually depth".

It's possible by adding 0 as padding to the tensor. What is currently refered to "same padding" (in particular in Keras).


Which batch size to use when Batch Normalization? I want to train a CNN in Keras (optimizer Adam) and by using batch normalization after every ConvLayer and before every activation layer.
So far I mostly see examples in which training is carried out with a batch size of 32 or 64 samples.
Should it not be ensured that the last batch in every epoch still contains 32 or 64 samples and not significantly less samples?
What do I mean, if I have 500 training samples for training, would a batch size of 50 not be better than a batch size with 32 oder 64 samples?

The fact that training size is not divisible by batch size does not matter (primarily)
main reasons for batch training is it requires less memory. Since you train the network using fewer samples, the overall training procedure requires less memory, also speed. Typically networks train faster with mini-batches. That's because we update the weights after each propagation.
What you have left in the last iteration will just be propagated even though its not divisible.


Require Guidance - Identifying risk factors I have a dataset of patients who have been inpatients (admitted to hospital) and not admitted (but visited as outpatients). Class proportion is 66:34.

I have collected a list of features for all these patients.

Now my objective is to find/identify the risk factors that leads to hospital admission? Meaning what are the risk factors that can influence a patient to be admitted? How the risk factors are different between two classes? For example patient with High heart rate or some sensitive clinical parameter(just example) could get admitted whereas person with normal clinical paramters may not get admitted but visit only for consulation.

Can you confirm whether my steps below are right?

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

Though my objective is to identify the risk factors that leads to hospital admission, do I still have to predict the outcome class to know the risk factors?

Can you guide me on this?

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

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


How to normalize data without knowing the min and max values? I have a Lending club dataset from Kaggle;
it contains many different columns: there are for example dummy variables, years, amount of the loan...ect
I want to normalize the data in the training and test set but I have to use the Min and Max of the train set to prevent data leakage from the test set.
My question is: if there is, in the test set or even when I try to predict new data point, a value that is greater that the Max value or lower than the Min value and I normalize it using the same values from the train set, is it correct? can I the model process this value normally?

this is the code that I use to normalize

    from  sklearn.preprocessing import MinMaxScaler

    scaler = MinMaxScaler()
    X_train = scaler.fit_transform(X_train)

The minimum and maximum values are just known limits that are parts of the formula that reshapes the distribution of the data, so if a value is bigger than the previously known value the resulting feature scaling (Normalization) will be still appropriate.

An alternative is z-scores if you don't feel like using minimum and maximum values.

x'= (x-x̄) / σ
Where x is the original feature vector, x̄  is the average of the vector x  is the mean of that feature vector and σ is its standard deviation.


Different encoders applied to a dataset I have a dataset which have both categorical features with high cardinality (>8000) and low cardinality (4 or 5).
Would that be ok to encode the high cardinality ones with one encoder (target encoder, for example) and the others with low cardinality with another encoder (one hot encoder) and put everything together to train a model?
Is this wrong and should apply the same encoder to all the features regardless of their cardinality?

Many thanks for your inputs!

It is perfectly fine. When you encode you want to extract the most information possible. You can apply one encoding to each feature, or even two.

Also you can encode numerical variables or bin them and then encoding.

For different encoding techniques, I recommend Category Encoders.

Be aware that some encodings can make your model decrease its performance, so you should select features somehow, not by adding more encodings your model will perform better.


how print f1-score with scikit´s accuracy_score or accuracy of confusion_matrix? I would like to print the f1-score. I got confused about the wording f1-accuracy score and accuracy score. What is the difference of these 2 scikit-learn metrics and how can I print the f1-score out of this code?
from xgboost import XGBClassifier
from sklearn.metrics import accuracy_score, classification_report
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split

df = pd.read...path
X = df.drop('pricing_class', axis=1)
y = df.pricing_class

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)

xgb_classification = XGBClassifier(random_state=42)
xgb_classification.fit(X_train,y_train)

xgb_results=xgb_classification.predict(X_test)
print(classification_report(xgb_results,y_test))
print('accuracy_score',accuracy_score(xgb_results, y_test))

this is a test sample:

Question 1:
There is under the column f1-score the row of accuracy. Is this the f1-score of the scikit-learn classification report? or is this the accuracy score?
I have the feeling, that this value is the rounded value of the accuracy_score the line below (when I use full dataset).
Question 2:
How can I print the f1-score?

Use f1_score instead of the classification report:
from sklearn.metrics import f1_score

...

print('f1_score', f1_score(xgb_results, y_test))


ROC-AUC loss for GRU Model: Cannot use tflearn's loss in keras I am trying to use tflearn.objectives.roc_auc_score as a loss function for a GRU network in Keras but I get the following error:

> ValueError: An operation has `None` for gradient. Please make sure
> that all of your ops have a gradient defined (i.e. are
> differentiable). Common ops without gradient: K.argmax, K.round,
> K.eval.

This is surprising as the implementation is apparently based on an approximation that is supposed to be differentiable.

For your reference, here is the code from the tflearn Github:

def roc_auc_score(y_pred, y_true):
    """ ROC AUC Score.
    Approximates the Area Under Curve score, using approximation based on
    the Wilcoxon-Mann-Whitney U statistic.
    Yan, L., Dodier, R., Mozer, M. C., & Wolniewicz, R. (2003).
    Optimizing Classifier Performance via an Approximation to the Wilcoxon-Mann-Whitney Statistic.
    Measures overall performance for a full range of threshold levels.
    Arguments:
        y_pred: `Tensor`. Predicted values.
        y_true: `Tensor` . Targets (labels), a probability distribution.
    """
    with tf.name_scope("RocAucScore"):

        pos = tf.boolean_mask(y_pred, tf.cast(y_true, tf.bool))
        neg = tf.boolean_mask(y_pred, ~tf.cast(y_true, tf.bool))

        pos = tf.expand_dims(pos, 0)
        neg = tf.expand_dims(neg, 1)

        # original paper suggests performance is robust to exact parameter choice
        gamma = 0.2
        p     = 3

        difference = tf.zeros_like(pos * neg) + pos - neg - gamma

        masked = tf.boolean_mask(difference, difference < 0.0)

return tf.reduce_sum(tf.pow(-masked, p))

This worked for me when I changed the declaration of the function:

def roc_auc_score(y_true, y_pred)

instead:

def roc_auc_score(y_pred, y_true)

I defined it wrong and it worked, when I fixed it I got the same error as you do. I don't really understand your code logic, but you can if this works for you.


Google data studio: How to order a dimension? I'd like to visualize the number of bookings per month, but I can't understand how to order the months (they are a dimension and not a metric, maybe that's the problem?).
When I try to do so it asks me the type of aggregation but I need no aggregation to do so. Am I missing something?

Sort like this:

Hope this works, and I'm adding extra words to fulfill minimum character count.


Books about statistical inference I'm currently taking a course "Introduction to Machine Learning" which covers the following topics:
linear regression, overfitting, classification problems, parametric & non-parametric models, Bayesian & non Bayesian models, generative classification, neural networks, SVM, boosting & bagging, unsupervised learning. I've asked the course stuff for some reading material about those subjects but I would like to hear some more recommendations about books (or any other material) that give more intuition about the listed topics to start with and also some books that go deeper into the theory of those subjects (affter I'll gain some intuition)? (I guess every subject has many books to cover the theory of course, but any recommendations will be great)
Thank you.

For theory Tibshirani: The elements of statistical learning
https://web.stanford.edu/~hastie/Papers/ESLII.pdf
Also Andrew NG and other books from deeplearning.ai:
Machine Learning Yearning
https://d2wvfoqc9gyqzf.cloudfront.net/content/uploads/2018/09/Ng-MLY01-13.pdf
of course the applied machine learning books on computer languages:
An introduction into statistical learning in R
http://faculty.marshall.usc.edu/gareth-james/ISL/
or deep learning with python:
http://faculty.neu.edu.cn/yury/AAI/Textbook/Deep%20Learning%20with%20Python.pdf
Of course there are a lot of free public pdf books in internet. However in my opinion for the beginning Tibshirani and Andrew NG are good. (and of course take your own project and ask questions on stackoverflow. That helps me a lot).


Export dataset with predicted target - Python I've this code (part of predictive model):

training_features, test_features, training_target, test_target, = train_test_split(df.drop(['target'], axis=1),
                                              df['target'],
                                              test_size = .3,
                                              random_state=12)
    coef_gini = DecisionTreeClassifier(criterion = "gini", random_state = 100, max_depth = 3, min_samples_leaf = 5)
    coef_gini.fit(training_features, training_target)

    y_pred = coef_gini.predict(test_features)
    y_pred

How can I export my dataset with the predictive value in order to create a confusion matrix to determine the False Positive value?

Thanks!

If you are just looking for generating Confusion Matrix, then you can try using this command:

#for generating confusion matrix
sklearn.metrics.confusion_matrix(y_true, y_pred, labels=None, sample_weight=None)

If you are just looking for binding predicted and actual values, you can use this command

#For Arrays you can use this
numpy.concatenate()

#for dataframe you can use this
DataFrame.append(other, ignore_index=False, verify_integrity=False)[source]

for better understaning you can go through this Link-1,Link-2,Link-3


Is it a good thing if my model overfits in TensorFlow? Very conceptual question:

I have a TensorFlow model that works well. I have isolated about 70 features worth of data and when training, my validation accuracy stays around 32% while my training accuracy is up to 89%! However, when I use only 24 of those 70 features, I get a validation accuracy of 38% and a training accuracy of 53%. I am using regularization, heavy dropout, and early stopping.

Is this a good problem to have? Should I keep the 70 features while boosting overfitting parameters? What should I do about this? Maybe it's a good idea to keep using only the 24 best features?

Is it generally O.K. to shed some features by just discarding them? Definitely some emotional attachment to my features here, but is it common for an ML process to simply discard these features as opposed to working with them to achieve higher accuracy?

Generally, you should pick the model that has the highest performance on the validation dataset.

The number of features is a hyperparameter and should be tuned during the model fitting process.


Transform test data when using a persistent model I'm quite new to data science and only slowly following the necessary steps to get valid results using scikit-learn. As far as I understand you fit and transform the training data and only transform the test data (using the parameters retrieved by the earlier fitting). For my project a persistent model is necessary, for that I export the trained model using joblib.

When applying the model on test data later, is there a way to retrieve the parameters (for transformation) generated during the training process?

In the same way that you use joblib to persist your saved model, you should persist the transformers that you use in the pipeline too. So for example if you're using StandardScaler() and OneHotEncoder(), those also need to be joblib.dump()ed so you can import them into your prediction script.

The simplest way to achieve this is to add both transformers and estimator into a Scikit Learn pipeline and use joblib to persist that.


How would you interpret the following ROC and PRC curves? How would you interpret the following ROC and PRC curves?
For example, I find it weird to understand that the precision actually increases at some point when recall increases as well. Is that even possible?

Cheers

My interpretation is that the data can be described as the following three groups, by decreasing order of the prediction to be positive:

a large number of positive instances which can "easily" be predicted as positive, with no false positive
then a large number of negative instances
then a smaller number of positive instances, which are predicted as less likely to be positive than the negative instances.

For instance it might look like this:
<predicted probability> <true class>
       1                     P
      0.9                    P
      ...                   ...
      0.4                    P

      0.38                   N
      ...                   ...
      0.14                   N

      0.11                   P
      ...                   ...
      0.05                   P

This kind of configuration would explain the three stages which are clearly visible. There might be other ways this would happen, but I can't think of anything very different than this explanation (I could be wrong about that).
Note that this is why both precision and recall increase with this third group: since the threshold has already passed all the true negative instances (i.e. all the possible FP errors have been made), adding these true positive cases increases recall (more TP cases) without decreasing precision (no more FP). It's indeed very unusual, but not impossible.
What is interesting here is to investigate why this third group of positive instances are totally misclassified: they're not only confused with the negative (the common case), they are predicted as "more negative" than the true negative instances. This is very strange: it's as if there are two very distinct groups of positive instances that the classifier cannot predict on the same side of the positive/negative continuum. But it's encouraging that the classifier can quite well distinguish the three groups from each other, it means that it's probably something which can be fixed.


Word embeddings for Information Retrieval - Document search? What are good ways to find for single sentence (query) the most similiar document (text). I asked myself if word vectors (weighted average of the documents) are suitable to map a single sentence to a whole document?

Doc2Vec is on possible approach. With this, model learns to "cluster" similar sentences together.

Most simplistic approach is to aggregate word vectors but that ignores order of words. Details on few of the approaches :

https://towardsdatascience.com/sentence-embedding-3053db22ea77
https://medium.com/explorations-in-language-and-learning/how-to-obtain-sentence-vectors-2a6d88bd3c8b


How to classify test objects with this ruleset in order of priority? I'm coding a program that tests several classifiers over a database weather.arff, I found rules below, I want classify test objects.

I do not understand how the classification, it is described:
"In classification, let R be the set of generated rules and T the training data. The basic idea of the proposed method is to choose a set of high confidence rules in R to cover T. In classifying a test object, the first rule in the set of rules that matches the test object condition classifies it. This process ensures that only the highest ranked rules classify test objects. "

How to classify test objects?

No. outlook temperature humidity    windy   play
1   sunny       hot     high        FALSE   no
2   sunny       hot     high        TRUE    no
3   overcast    hot     high        FALSE   yes
4   rainy       mild    high        FALSE   yes
5   rainy       cool    normal      FALSE   yes
6   rainy       cool    normal      TRUE    no
7   overcast    cool    normal      TRUE    yes
8   sunny       mild    high        FALSE   no
9   sunny       cool    normal      FALSE   yes
10  rainy       mild    normal      FALSE   yes
11  sunny       mild    normal      TRUE    yes
12  overcast    mild    high        TRUE    yes
13  overcast    hot     normal      FALSE   yes
14  rainy       mild    high        TRUE    no

Rule found:

1: (outlook,overcast) -> (play,yes)
[Support=0.29 , Confidence=1.00 , Correctly Classify= 3, 7, 12, 13]

2: (humidity,normal), (windy,FALSE) -> (play,yes)
[Support=0.29 , Confidence=1.00 , Correctly Classify= 5, 9, 10]

3: (outlook,sunny), (humidity,high) -> (play,no)
[Support=0.21 , Confidence=1.00 , Correctly Classify= 1, 2, 8]

4: (outlook,rainy), (windy,FALSE) -> (play,yes)
[Support=0.21 , Confidence=1.00 , Correctly Classify= 4]

5: (outlook,sunny), (humidity,normal) -> (play,yes)
[Support=0.14 , Confidence=1.00 , Correctly Classify= 11]

6: (outlook,rainy), (windy,TRUE) -> (play,no)
[Support=0.14 , Confidence=1.00 , Correctly Classify= 6, 14]

Thanks,
Dung

Suppose your test object is (sunny, hot, normal, TRUE). Look through the rules top to bottom and see if any of the conditions are matched. The first rule for example tests the outlook feature. The value doesn't match, so the rule isn't matched. Move on to the next rule. And so on. In this case, rule 5 matches the test case and the classification for the p lay variable is "yes".

More generally, for any test case, look at the values its features take and find the first rule that those values satisfy. The implication of that rule will be its classification.


Retrieve user features in real time from UserId for prediction Let's say I'm building an app like Uber and I want to predict the user's most likely destination based on the user's past history, current latitude/longitude, and time/date.

Here is the proposed architecture -

Let's say I have a pre-trained model hosted as a service. The part I'm struggling with is, how do I get the user features from the database in realtime from the RiderID to be used by the prediction service (XGBoost Model)? I'm guessing a lookup in a SQL database will take too long, considering I have 1M+ users and rides.

Thanks in advance!

I think most likely the return of your model wouldn’t be worth it given the amount of effort to generalize it enough.

You may have millions of users, but each users need will probably too unique for generalization. I.e., everyone’s commute is so different that what you have learned from other users are probably not applicable to other users. (Unless during rush hours where most people are heading to the core business areas. You don’t need a model for that. )
The trained model will probably be marginally better than logging the users usage history. It probably isn’t worth the effort to train and process these data for what you can gain.
Recent locations is probably good enough for most users and super easy to implement. Your model will probably have a hard time to predict the odd unusual trips anyway.

You are probably better off storing the users current location and query the most likely destination. Or simply look at all the popular trip destinations from that location. A data base with proper index should be able to handle that


Difference between train, test split before preprocessing and after preprocessing I am new to machine learning. I am bit confused in preprocessing. Generally,

Scenario-1: I am splitting the dataset into train,test and validation and applying the transformations like fit_transform on train and transform on test.

Scenario-2: The other method is applying transformations on the entire dataset first and then split the dataset into train,test and validation. I am bit confused in choosing , dividing the data before preprocessing and feature engineering or after preprocessing and feature engineering. Looking for a nice answer with effects and casues.

You should absolutely adopt the first scenario. That's because the transformers that you use have some parameters (e.g. mean and standard deviation in case of standard scalar) and this parameters are learned from data like the parameters of your machine learning model. As you know, you should not use the validation and test data for learning the model parameters and for the same reason, you should not use them for learning the transformer parameters. As a result, you should just use the training samples for fitting your transformer parameters if you want to try a practical machine learning scenario.


Representing user information I have a task of representing a  users feature matrix , i have features like gender , age etc but  I also have a multivalue feature called as "movies watched" which is essentially another table of movie names watched by that user with a numeric duration, the order of movies does not matter here. Also, movies watched can be from 20 movies to 300 movies. So what is the best way of representing this "movies watched" as a feature vector?

Hot Encoding

For each user, create a vector with the length of your movie catalog and add 1 to the movies the user watched and 0 to the ones the user did not watch.

This is a very naive approach but depending on your task might be enough.

Do keep in mind that your data is suddenly sparse, so choose algorithms that can deal with such data. The good thing is that any kernel above linear is often not necessary for sparse data.

Taking Duration into account

You could also do a Hot Encoding where instead of adding a 1 to the movies watched, you add the duration that the person watched.

However, this can start to become biased for movies that are longer than others. So, you can try two normalization techniques:

Movie length normalization. Take the time the person watched the movie and divide be the actual length of the movie. (e.g. the user watched 75 mins, but the movie was 90 mins, so you get 75/90 = 0.83)
TF-IDF usually used in NLP, but you can apply it here. This method also takes into account the frequency in which a movie is watched by all users. Balancing the weight between movies that are important (i.e. viewed by many users) and less important (i.e. moveis viewed by very few or just one user).

Other

Depending on your use case, you can start to be creative and group movies:

Group movies by genre (e.g. 10 genres) and count the time watched in each genre.
Check the percentage of the movie watched and group them into watched only the beginning, watched more than half and watched the full movie and count each category for each user.


Sequence data vs time series data What is the difference between sequence data and time series data?

My understanding is that sequence data is any data where the order matters and time series is a special type of sequence data ordered by the time stamps. Is this correct?

Is there a paper or book that defines it so I can cite it in a research paper?

Sequential Data is any kind of data where the order matters as you said. So we can assume that time series is a kind of sequential data, because the order matters.
A time series is a sequence taken at successive equally spaced points in time and it is not the only case of sequential data. In the latter the order is defined by the dimension of time. There are other cases of sequential data as data from text documents, where you can take into account the order of the terms or biological data (DNA sequence etc.).
The fact that you have sequential data is important for two reasons. First, you can into account for the representation of the data and also you can take it into account for the data modeling (e.g. Conditional Random Fields, Hidden Markov Models for text or genes and ARIMA Models for time series problems).


NER evaluation metric I'm trying to compare two NER tools on an annotated corpus and I'm not sure which is the best metric to use, as I haven't worked with NER models before. To be more specific, I'm interested in one class only, so I want to evaluate them on that particular class.

A good starting point is to look at the evaluation measures used in the NER shared tasks: https://nlpprogress.com/english/named_entity_recognition.html.
Generally the F1-score can be used for one specific class, but there are different options regarding what is counted as an instance:

every occurrence of the full NE. In this case any difference between the predicted and the gold is counted as false, even if it's only one token difference.
every token in an entity. In this case a partially matched entity counts as "partially correct": if a word is predicted outside instead of inside, it's a false negative and conversely.
Other variants:

count only unique entities, in order to observe the diversity of the entities recognized.
count only entities which didn't appear in the training set, to observe the generalization power.

(writing this from memory, I could miss something)


Will data science develop into a separate academic field? Right now data science is often regarded as an interdisciplinary subfield of statistics and computer science. What would it take for data science to develop into a separate academic field (with its own associations, journals, and conferences...)?

At the risk of showing confirmation bias, yes, data science will become it's own field. The primary argument would be an economic one, data science enables a larger return on investment per resources expended than the many alternatives. It is one of the few profit levers left as business processes become more optimized. So where the money flows, the conferences, journals, et al. will follow.

The second argument is empirical, there are more data science education programs, articles, books, jobs, and salary. I have not modeled it, but this mirrors the indicators in Internet technology and enterprise resource planning waves that the industry has seen. Both have given rise to academic "fields". There appears to be strong correlation.

Unfortunately, large academic institutions and societies have an institutional momentum -- so that recognition may be slow in coming.  One could argue in the business world has already settled this with Chief
Data Scientist Officer
C-level positions.


Should features be correlated or uncorrelated for classification? I have seen researchers using pearson's correlation coefficient to find out the relevant features --  to keep the features that have a high correlation value with the target. The implication is that the correlated features contribute more information in finding out the target in classification problems. Whereas, we remove the features which are redundant and have very negligible correlation value.

Q1) Should highly correlated features with the target variable be included or removed from classification problems ? Is there a better/elegant explanation to this step?

Q2) How do we know that the dataset is linear when there are multiple variables involved? What does it mean by dataset being linear?

Q3) How to check for feature importance for non-linear case?

Q1) Should highly correlated features with the target variable be included or removed from classification and regression problems? Is there a better/elegant explanation to this step?

Actually there's no strong reason either to keep or remove features which have a low correlation with the target response, other than reducing the number of features if necessary:

It is correct that correlation is often used for feature selection. Feature selection is used for dimensionality reduction purposes, i.e. mostly to avoid overfitting due to having too many features / not enough instances (it's a bit more complex than this but that's the main idea). My point is that there's little to no reason to remove features if the number of features is not a problem, but if it is a problem then it makes sense to keep only the most informative features, and high correlation is an indicator of "informativeness" (information gain is another common measure to select features).
In general feature selection methods based on measuring the contribution of individual features are used because they are very simple and don't require complex computations. However they are rarely optimal because they don't take into account the complementarity of groups of features together, something that most supervised algorithms can use very well. There are more advanced methods available which can take this into account: the most simple one is a brute-force method which consists in repeatedly measuring the performance (usually with cross-validation) with any possible subset of features... But that can take a lot of time for a large set of features.

However features which are highly correlated together (i.e. between features, not with the target response), should usually be removed because they are redundant and some algorithms don't deal very well with those. It's rarely done systematically though, because again this involves a lot of calculations.

  Q2) How do we know that the dataset is linear when there are multiple variable involved? What does it mean by dataset being linear?

It's true that correlation measures are based on linearity assumptions, but that's rarely the main issue: as mentioned above it's used as an easy indicator of "amount of information" and it's known to be imperfect anyway, so the linearity assumption is not so crucial here.

A dataset would be linear if the response variable can be expressed as a linear equation of the features (i.e. in theory one would obtain near-perfect performance with a linear regression).

  Q3) How to do feature importance for nonlinear case?

Information gain, KL divergence, and probably a few other measures. But using these to select features individually is also imperfect.


Gradient Descent Python Implementation isnt converging I'm trying to implement gradient descent in Python and following Andrew Ng course in order to follow the math. However, my implementation isn't working as I expected. It would be great if the community can help me to identify my mistake.
When I increase the range from 3 to higher number, it does not converge, rather thetas move from very positive to very negative and finally get nan because they get extremely small.
Code is given below:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_boston
from sklearn.linear_model import LinearRegression

X = pd.DataFrame(load_boston().data, columns = load_boston().feature_names)
X['theta0'] = 1
y = load_boston().target
y = pd.DataFrame(y, columns = ['target'])
theta = pd.DataFrame(np.random.randn(X.shape[1]),columns = ['target'], index = X.columns.values)

print('theta shape',theta.shape)
print('X shape',X.shape)
print('y shape',y.shape)
print(theta)

def predict(X,theta, ycol = 'target'):
    return X.dot(theta)

mse_values =[]
alpha = 0.01
for i in range(10000):
   error = predict(X,theta) - y
   theta = theta - ((alpha)* (1/len(X)) * X.T.dot(error))
   mse= np.sum(error**2)/len(X)
   print('mse: ', mse.values)
   mse_values.append(mse)
   print('+'*5)

plt.plot(mse_values)
plt.show()

I was doubting my implementation all the way but it was the learning rate.
After a lot of experimentation, I found the right one, but I'm very much surprised to see how small the learning rate had to be in order for it to work, i.e alpha = 0.000001


Why are Chunking and IOB tags necessary? I've just come across chunking and I can't get my head around why is it necessary? I know that it is used for 'named entity recognition'. I have few questions:

Why and how is Chunking helpful?
Plus aren't POS tags enough?
Why are three tags necessary for the representation? Why not just use 'inside' tag and 'outside' tag?

BIO(L) tagging is important (but as you correctly noted, not necessary) part of a NER pipeline. Main idea behind such split is to facilitate learning in following manner.

Take English as an example, some words will (most likely) never end a Named Entity, like adjectives, so the model will never tag them as the L(ast) part of a named entity. The same applies to the L-tag.

What is crucial, is that many models, like Conditional Random Fields, learn not only tags themselves, but also the transition probability, so, if you will get some chunk of text that is tagged as B_ O_ L_, that sequence is incorrect, but when you learn the transitions as well, model will figure out, that if you get a strong Beginning and End, the inside part should also be a entity part.


Should I scale high ranging ordinal fields? In the left column, I have an ordinal integer field.
In the right column, I have a scaled float feature.
Should I scale the ordinal field since it is getting so much bigger than the other feature?

We scale data because certain algorithm will not work optimally esp. Gradient descent.
You may check the internet for further detail.
Coming to the exact question -
I am assuming, you have done the analysis that the Oridinal feature will be used as a Continuous(Not Categorical) feature with its respective values. So, I will ignore this point
Models don't see the feature scale, it looks for the respective variance, interaction with other features, Correlation with the target etc.(in a very simple language) and scaling will not hamper these parameters.
So, you must scale if that is your only concern.
 You may ignore it for some Models e.g. Decision Tree/RF will work fine even without scaling.


How to decide what threshold to use for removing low-variance features? How to decide what threshold to use for removing low-variance features?

Particularly, I have 100000 features and the variances look like:

Could I e.g. take the average and use it to split this to ~half?

Or some other method of grouping?

You can do this a few ways, which I can list in ascending order of effort:

Pick a value that seems ok for you and your dataset by eye-balling it then simply cut variables below the theshold from the dataset
Create a function, which given a threshold, tells you how many variables would be removed, if you used that threshold. Then create a simple plot and see if there is a certain level that seems appealing (this depends on your target model once data is ready).
Use some smarter functions that d a little more for you, e.g. the NearZeroVar function in the Caret package in R

There are, however, some arguments as to whether these approaches in general are optimal. Have a look at some of the discussion on this thread over at Cross-Validated. The quote from the OP in that thread if from the book of the guy who wrote the above mentioned Caret package - Max Kuhn.

The arguments against this approach say that you may be moving variables that, although they have low variance, might actually be extremely powerful in explaining your target (dependent) variable.

A final approach I can suggest goes into the realm of covariance, that is to look at the collinearity between pairs of variables. I have done this in the past and it worked out well for me. The basic algorithm would look something like this:

Compute the covariance matrix across all your variables
Find the pair with the highest covariance

correlation if you prefer that measure
the plan is to remove one of these two variables

using your covariance matrix from step 1, compute which of these two variables in step 2 has the highest sum of covariances with the rest of the variables
remove the variable with the highest sum of covariances
Repeat steps 1-4 until you arrive at your desired number of variables, or a threshold is reached in terms of covariances or individual variable variances.

EDIT:

Here is the Scikit-Learn class which can do basic variance thresholding for you - there is also a short tutorial. They also present some ways to do recursive feature selection, similar in nature to my final approach outlined above.


Classifying Email in R I'm working on a project in R where I have roughly 1200 emails from a company, most of which are labeled class$_{1}$ or class$_{2}$, which are the types of requests. Roughly 1000 emails are labeled class$_{1}$, and 200 are labeled class$_{2}$.My goal is to used supervised learning to build a model that will classify new emails.

But, after a lot of pre-processing (parsing, removing stopwords, etc.), and trying typical algorithms (SVM, decision trees, etc.) on a document term matrix, my confusion matrix contained many false positives and false negatives, but only a few false negatives with SVM.

I'm wondering how could I improve my results? Do I need to use oversampling,  or bi-gram feature representation? I guess the problem is that the topics of the two categories are really close.

( All emails are or in french or in english )

Pre-processing methods :

Merge " Summary " and " Content " which are the head of the email and the content
Remove all emails adress
Remove all " From : Someone To : someone ... subject : something "
Remove all images included in the email
Order the email according to their class
Replace all french accent by no accent like é -> e ; ê -> e ...
Put text to lower
remove punctuation
remove numbers
strip white space
remove some first name from a list and some specific words
remove stop words in french and english
stem document in french and english
Remove term

--> Then Document term matrix, with TF-IDF

The two classes are from a technical support, two categories "complex" and "easy", "complex" are topics around finance ( in theory ) , "simple" problem with the software ( in theory ) but in practice they have a lot words in common.
And the other classes I don't take them into account I just focus on the two for now

Actually the kind of classification algorithm I used is not so relevant because I tried with 5 algo and none gave good results

Example ( confusion matrix )
Decision tree:

  Decision tree:

pred:

335 | 10
59  | 12

SVM:

331  | 1
83   | 1

Knn (n=10):

330  | 2

83   | 1

Naive Bayes:

1   |  83

12   |  320


How to preprocess data for Word2Vec? I have text data which is crawled from websites. I am preprocessing data to train Word2Vec model. Should I remove stopwords and do lemmatization? How to preprocess data for Word2Vec?

Welcome to the community,

I do not know about other libraries, but gensim has a very good API to create word2vec models. In order to preprocess data, you have to decide first what things you are gonna keep in your vocab and whatnot. for ex:- Punctuations, numbers, alphanumeric words(ex - 42nd) etc.

In my knowledge, the most generic preprocessing pipeline is the following:-

1) Convert to lower
2) Remove punctuations/symbols/numbers (but it is your choice)
3) Normalize the words (lemmatize and stem the words)

Once this is done, now you can tokenize the sentence into uni/bi/tri-grams.

Have a look at this

The generic format to put data in gensim.models.word2vec()'s sentence parameter is : [[tokeneized sentence 1], [tokenized sentence 2].....and so on]

Hope it helps, thanks!!


What is the function of the hidden layer in a neural network mapping to? The hidden layers of the neural network which are in between the input layer and the output layer take in input data and apply a function to churn out data from each node which is then weighed by the next layer.

The way I've seen it explained is for example to predict whether a image is a bus , the nodes learn whether there is a wheel , a tire etc or to predict if a person likes a document, the hidden layer nodes map to whether the topic is sports, history etc.

However the "function" that the hidden layer nodes apply, what exactly are they mapping to i.e what is the dependent variable? Is it the output variable that the model is fed ? For example if I'm trying to predict if the image given is that of a dog or cat , then does the hidden layer map  the input data to the output variable(dog or cat) ? How exactly does the hidden layer learn useful features? How do the nodes learn different features rather than the same one?

Dependent variable: Yes, the output variable is dependent value but by being fed what do you mean? (We have a training set and a test set. We feed our model via training set (both independent and dependent values) and then predict the values for the dependent variable in the test set)

There are some features for each sample that are independent like temperature, heart rate, etc. Based upon these independent values, a feature (outcome) is predicted, for instance, whether someone is prone to health issues or not (classification problem). So this output (health issues) that depends on independent features ( temperature, heart rate, etc. is dependent)

Note: each pair of independent variables might be correlated.

If you are trying to predict if an image is a cat or dog, then the outcome might be different based on what activation function we have chosen. for instance, if we have chosen sigmoid activation function, the output would be two probabilities, determining the probability of cat and dog. But if we use the threshold function, it gives 0 or 1.

Actually, the way in which the hidden layers are acting in a neural network varies for different sort of layers like Dense, convolutional, recurrent, etc.

For instance, Dense layers try to figure out what the weights of the features (independent variables) should be, meaning, how important each feature is in determining the output (dependent variable), and then based upon the function we utilize (sigmoid, rectifier, etc) would return probability of each outcome, binary outcome for dependent variables with two outcomes, etc.

What do you mean by "How do the nodes learn different features rather than the same one?"


Statistical test using Gmean to compare multiple algorithms on multiple datasets I am new in this area. I am facing some issues while comparing the algorithms using statistical test. I have following result of Gmean of some classification algorithm. Abalone, Balance-scale, Car, Chess are the datasets here and ROS, RUS, RFS, NoS are the algorithms.

If I want to compare which dataset is better than others using some statistical test like, t-test, Friedmen test, Wilcoxon test etc then is it possible that I can compare the algorithm using the following table?

                  ROS       RUS     RFS     NoS
Abalone           0.003     0.0036  0.0039  0
Balance-scale     0.8858    0.8065  0.8966  0.9417
Car               0.9191    0.7216  0.9056  0.9094
Chess             0.4912    0.1973  0.5084  0.1438

If anyone has any idea about it please help me. Or you can share any references from where I can find the solutions. I studied these statistical test, null hypothesis, p-value etc but couldn't understand whether it is possible or not to compare these algorithms using Gmean.

***G-mean = Geometric Mean, used to evaluate the performance of multiclass classifiers

Thanks in advance.

The performance of machine learning algorithms is not commonly evaluated with null hypothesis significance testing (NHST).
Machine learning performance is evaluated with performance on a hold-out data (e.g., validation or test), regardless of the evaluation metric.


IterativeImputer - Returning -0 and other wierd results I am using IterativeImputer to impute my dataset.
from sklearn.experimental import enable_iterative_imputer
from sklearn.impute import IterativeImputer

imp = IterativeImputer(random_state=0, max_iter=100, verbose=10)
imp.fit(hosp)

hosp_imputed = pd.DataFrame(imp.transform(hosp), columns=cols)

I have a boolean column "ICU" that had 8 missing values. But after imputation, it outputs very weird results. Please see the attached screenshot. Can you please let me know what am I doing wrong?

Despite the fact that I'm not sure why it's that, it's seems that's normal. Please see the example from sklearn documentation: https://scikit-learn.org/stable/modules/impute.html#multivariate-feature-imputation
import numpy as np
from sklearn.experimental import enable_iterative_imputer
from sklearn.impute import IterativeImputer
imp = IterativeImputer(max_iter=10, random_state=0)
imp.fit([[1, 2], [3, 6], [4, 8], [np.nan, 3], [7, np.nan]])

X_test = [[np.nan, 2], [6, np.nan], [np.nan, 6]]
# the model learns that the second feature is double the first
print(np.round(imp.transform(X_test)))

They use np.round at the end to get results:
array([[ 1.,  2.],
       [ 6., 12.],
       [ 3.,  6.]])

Running this code without rounding gives results similar to yours:
array([[ 1.00007297,  2.        ],
       [ 6.        , 12.00002754],
       [ 2.99996145,  6.        ]])

Try to add np.round before casting to pd.DataFrame to see if it helps.


Case when Out of Bag Error and Test error differs a lot in Random Forest I'm using random forest and the out of bag error for the level of one class is very different to its test error. I'm working with a cutt-of equal to c(0.2,0.8). Here's the case:

fmla <- as.formula(paste("ex ~ ", paste(names(muestra.fullarbol[,-c(1,2,3,9,10,11,12,17,19,20,21,22,23,24,29,31,32,33,34,35,36,47)]), collapse= "+")))
> bosque <- randomForest(fmla , data=muestra.fullarbol ,mtry=12, ntree=1000  , cutoff=c(0.2,0.8),importance=TRUE)
> bosque

Call:
 randomForest(formula = fmla, data = muestra.fullarbol, mtry = 12,      ntree = 1000, cutoff = c(0.2, 0.8), importance = TRUE)
               Type of random forest: classification
                     Number of trees: 1000
No. of variables tried at each split: 12

        OOB estimate of  error rate: 15.81%
Confusion matrix:
     No Si class.error
No 3999  1     0.00025
Si  758 42     0.94750

As we see, the out of bag error for the level "SI" is 0.94750. However If I use the test set to get a sense of the error, the result is very different:

res.arbol <- predict(bosque,test.fullarbol,type="class")
> summary(res.arbol)
  No   Si
7761   43
> table(res.arbol,test.fullarbol$ex)

res.arbol   No   Si
       No 6937  824
       Si    4   39
> prop.table(table(res.arbol,test.fullarbol$ex),1)

res.arbol         No         Si
       No 0.89382811 0.10617189
       Si 0.09302326 0.90697674

Now we see thae error rate for the test set in the class "Si" is very low ,  it's equal to 0.093 and It doesn´t make sense to me.

I guess that the cut off is working just to predict out of the sample(muestra.fullarbol), but I'm not sure. What can be the reason of that huge difference?

What type of sampling method did you use to split the data? I'm guessing, by looking at the ratio of classes in your OOB confusion matrix and your test set confusion matrix that it wasn't stratified, is this correct? For instance, the class ratio in the OOB data is 4000:800 whereas in the test set it is 7761:43. As a starting point, you may want to split your data using stratified sampling so that the classes are fairly represented (in a statistical sense) in both your training data and test data. The ratio of classes in the test set should be identical or almost the same as the ratio used in the training data.

I think this would be a good starting point to figuring out the problem.


Can some one explain how PCA is relevant in extracting parameters of Gaussian Mixture Models I am having some difficulty in seeing connection between PCA on second order moment matrix in estimating parameters of Gaussian Mixture Models. Can anyone connect the above??

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

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


Is it possible to patent a new general method of optimizing some industrial processes? I have finished a new method (implemented as an algorithm/software) which exploring data inputs obtains a sequence of steps, appliable for different industrial processes, that reduces drastically material and human resources as well as energy and time.

For example. This method gives the optimal commands for managing an arm-robot to arrange 7 tones of different size stones in 10 pallets of 1 cubic metre in 60 minutes instead of the current process that needs 3 arm-robots (and others) for performing the same task in 30 pallets and in more than 300 minutes.

Note that for different processes and inputs (a different set of stones) it will produce a different sequence of commands, so it is generating new industrial processes for each new task.

I know that software that implements industrial processes are patentable in US and EU but as I´ve exposed it is not an industrial process but an algorithm to generate some industrial processes.

Is this case of software patentable as a unique-global software for industrial processes or each case must be patented apart?

Disclaimer: you need to ask a legal expert: software patents is a very complex and specialized domain, so don't rely on strangers on the internet ;)

As far as I know some algorithmic methods are patentable, but there are conditions to satisfy, in particular about the novelty of the method. You would probably have to prove the novelty by doing a thorough literature review, it's probably not enough to show that the software leads to efficiency improvements.


Should I rescale losses before combining them for multitask learning? I have a multitask network taking one input and trying to achieve two tasks (with several shared layers, and then separate layers).

One task is multiclass classification using the CrossEntropy loss, the other is sequence recognition using the CTC loss.

I want to use a combination of the two losses as criterion, something like Loss = λCE + (1-λ)CTC. The thing is that my CE loss starts around 2 while the CTC loss is in the 400s.

Should I rescale the losses at each epoch with a Max(L₁)/L₁ factor, where Max(L₁) is the maximal loss at epoch 1 and L₁ is each “sub-loss” at epoch 1. That is we scale the loss so that at the first epoch they have the same magnitude and then we keep scaling using those factors.

Is there a better approach? How do I ensure that my two losses have the same influence on the backpropagation with respect to λ?

Check this.

Under the heading Multi-tasks losses they have mentioned how they average losses from two different tasks. They do a weighted average depending on their use case.


how does gradient descent update weigths in neural network Im currently trying to learn about back propagation, and it's going forward, but theres one thing that keeps me scratching my head, and doesnt really seems to be answered in any of the videos or articles im looking at.
I understand now, that based on my loss, the weigths of my network is updated. But what i dont understand is how this happens. lets say i have this exercise network with the following weigths:

W_1 = 1.2 - w_2 = 0.4 - W_3 = 1.0

Now i do some training, and lets say i have the loss o.8.
Now when i use my loss to update my weights, what happens specifically to the weights? are something being added, subtracted maybe multiplied?

Thanks a lot

In short it is "Added" to previous value of the weight.

Here is the algo from tom mitchell's, in your case it shall be W_1 = w_1+delta,W_2 = w_2+delta, W_3 = w_3+delta.


What kind of Visualization is this? Can anyone help identify what kind of Visualization this is?
(google image search was not informative, unfortunately...)

Welcome to the site!

I think it is called as Flow Visualization. I remember seeing something similar when I was running a Campaign using Google Analytics. That graph is used for showing the Click-Path Analysis, Visit Flow, Navigation Flow etc. You can go through this link-1, link-2 for better understanding.

The outcome of this graph was to see which path was mostly used and where can we find some room to improve it the ones which are not used mostly, finding the root cause and provide best experience to the users.


review: gradient descent, epochs, validation in neural network training These days, training data aren't put in gradient descent all at once. Rather, they are put in batch after batch. Gradient descent is run once for each batch of training data. When all batches are traversed, 1 epoch is done. However, gradient descent hasn't minimized the loss function yet, the loss function still being on a slope. The loss function now and weights serve as initial values for the next epoch. Weights are initialized only at the beginning of the 1st batch of the 1st epoch.

During each epoch, the validation set is used to calculate the error (evaluated using trained weights) on the validation set. If the error is dropping, finish this epoch and go to the next epoch. Chances are, when the validation error is minimized, the current epoch isn't traversed yet, the remaining batches of training data are left unused.

If the above is all right, seems that the hyper parameters: number of ConvNet filters, size of ConvNet filters, number of layers won't be trained or tuned?

Chances are, when the validation error is minimized, the current epoch isn't traversed yet, the remaining batches of training data are left unused.

Typically, validation is done only at the end of the epoch. So no batch should remain unused. For example, this is the behavior of Keras https://keras.io/models/model/#fit

validation_freq: Only relevant if validation data is provided. Integer or list/tuple/set. If an integer, specifies how many training epochs to run before a new validation run is performed, e.g.  validation_freq=2 runs validation every 2 epochs. If a list, tuple, or set, specifies the epochs on which to run validation, e.g. validation_freq=[1, 2, 10] runs validation at the end of the 1st, 2nd, and 10th epochs.

  hyper parameters: number of ConvNet filters, size of ConvNet filters,
  number of layers won't be trained or tuned?

Yes, such hyper parameters are set when model is defined.  These are not modified during training.

However : Systems like Google AutoML are trying to change this. These systems try to learn model hyper parameters during training.