1
$\begingroup$

I am working on a project where a physical test over time is conducted to decide whether an object is diagnosed as class $A$ or class $B$. Typically these tests can take around 2.5-3 hours and so each timestep $t$ is recorded. $t$ is usually around one second long and so each row has a set of features at a particular second during the test. Once the test is completed, you decide whether the object is of type $A$ or $B$. Humans usually look at the time-series plot of the test to determine this classification - but I am tasked with automating it.

The issue is each CSV file for a test is approx 9000 to 11000 (2.5 to 3 multiplied by 3600 seconds in an hour) rows since the test can vary in time. The amount of features/columns are fixed. I have $N$ CSV files, which represent the time series data for one test done on one sample object (note, one sample object always gets tested once). So, my question: Is there a way to aggregate each sample so that I can have single dataframe to train my classifier on? Or is there another approach?

To add more clarity, I will have to make predictions on CSV files that come with inconsistent row dimensions due to the variance in testing time.

E.g.;

  • csv1.shape = (8751, 1257) --> Prediction: Class $A$
  • csv2.shape = (10321, 1257) --> Prediction: Class $A$
  • csv3.shape = (9978, 1257) --> Prediction: Class $B$
$\endgroup$
6
  • $\begingroup$ So, in your training set, let's say there are $M$ objects. Does this mean you have $MN$ files? $\endgroup$
    – gunes
    Commented Feb 26, 2022 at 23:47
  • $\begingroup$ @gunes one test done for one object, and so I have $N$ files for $N$ objects (made an edit in the original post). $\endgroup$
    – User_13
    Commented Feb 27, 2022 at 0:20
  • $\begingroup$ In my opinion it is not a good idea to cast this as a classification (forced choice, premature decision) problem (see this). Consider instead using a probability model (e.g., logistic regression) or a probability machine. What is of most interest is estimating the tendency for diagnosis class B, not to make arbitrary classifications (which are especially meaningless when the probability of class membership is around 0.5). $\endgroup$ Commented Feb 27, 2022 at 0:33
  • $\begingroup$ @FrankHarrell , sure that is a fair assessment but what would you suggest I do about the data itself so that it can actually be used as an input to, say, a logistic regression? $\endgroup$
    – User_13
    Commented Feb 27, 2022 at 2:52
  • $\begingroup$ WIthout knowing more about your design and goals, I'd start with a simple Markov process to handle dependence between certain observations, e.g., $\Pr(Y(t) = 1 | Y(t-1), X) = \mathrm{expit}(X\beta + \gamma Y(t-1))$. $\endgroup$ Commented Feb 27, 2022 at 12:58

2 Answers 2

3
$\begingroup$

You could try treating each object's time series as a function, and use tools from functional time series analysis (or functional data analysis) to analyze it.

Here is one paper Clustering and Forecasting Multiple Functional Time Series which attempts to do this.

Also there is an R package for functional time series analysis here. Possibly you could look at running principal component analysis and then classify time series based on the coefficients.

$\endgroup$
1
$\begingroup$

One option would be calculating summary statistics (e.g. mean, min, max, autocorrelation of varying degrees etc.) from each time series for each feature and representing an object with a long set of features.

Another option is to feed the multivariate time series into an LSTM-like architecture and train with the raw series. Although note that making LSTMs work with time series of different length is possible but may need special attention.

$\endgroup$
4
  • $\begingroup$ I have the summary stats idea noted for things I should try, however I am a bit skeptical about it as I feel that I may lose important information such as anomalous spikes in a feature at a particular time step. Could you further expand on how I can use an LSTM model to train on each time series CSV file (again, each file describes what should be a training example)? From what I understand about LSTMs using an ML framework like TensorFlow, you can only use 1 dataframe/csv as an input. $\endgroup$
    – User_13
    Commented Feb 27, 2022 at 22:12
  • $\begingroup$ You need to prepare your data, not the same, but this link may help: machinelearningmastery.com/… $\endgroup$
    – gunes
    Commented Feb 27, 2022 at 22:21
  • $\begingroup$ I am thinking of going with the approach seen in Saad's comment here: stackoverflow.com/questions/54794867/… Would like to get your thoughts. $\endgroup$
    – User_13
    Commented Mar 4, 2022 at 16:32
  • $\begingroup$ Yes, it makes sense to use batch size = 1 when the frameworks you use do not support variable lengths. I don't know if things have changed in tensorflow since then. In NLP applications, I've seen a max sentence length has been set, and remaining words are padded. So it's not a bad idea all together. It might worth trying out both approaches. $\endgroup$
    – gunes
    Commented Mar 4, 2022 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.