TimeDistributed(Dense) vs Dense in Keras – Same number of parameters

TimeDistributedDense applies a same dense to every time step during GRU/LSTM Cell unrolling. So the error function will be between predicted label sequence and the actual label sequence. (Which is normally the requirement for sequence to sequence labeling problems). However, with return_sequences=False, Dense layer is applied only once at the last cell. This is normally … Read more

Can Keras deal with input images with different size?

Yes. Just change your input shape to shape=(n_channels, None, None). Where n_channels is the number of channels in your input image. I’m using Theano backend though, so if you are using tensorflow you might have to change it to (None,None,n_channels) You should use: input_shape=(1, None, None) None in a shape denotes a variable dimension. Note … Read more

Reset weights in Keras layer

Save the initial weights right after compiling the model but before training it: model.save_weights(‘model.h5’) and then after training, “reset” the model by reloading the initial weights: model.load_weights(‘model.h5’) This gives you an apples to apples model to compare different data sets and should be quicker than recompiling the entire model.

TfidfVectorizer in scikit-learn : ValueError: np.nan is an invalid document

You need to convert the dtype object to unicode string as is clearly mentioned in the traceback. x = v.fit_transform(df[‘Review’].values.astype(‘U’)) ## Even astype(str) would work From the Doc page of TFIDF Vectorizer: fit_transform(raw_documents, y=None) Parameters: raw_documents : iterable an iterable which yields either str, unicode or file objects

Pattern recognition in time series [closed]

Here is a sample result from a small project I did to partition ecg data. My approach was a “switching autoregressive HMM” (google this if you haven’t heard of it) where each datapoint is predicted from the previous datapoint using a Bayesian regression model. I created 81 hidden states: a junk state to capture data … Read more

How to find the importance of the features for a logistic regression model?

One of the simplest options to get a feeling for the “influence” of a given parameter in a linear classification model (logistic being one of those), is to consider the magnitude of its coefficient times the standard deviation of the corresponding parameter in the data. Consider this example: import numpy as np from sklearn.linear_model import … Read more