0
$\begingroup$

I have a similar dataset like the one below. Each row represents a person and there are 3 different variables m1,m2,m3 with 3 measurements each. I am trying to frame this time series problem as a supervised learning problem so i can train an SVM and/or random forest.

id Age gender m1_1 m2_1 m3_1 m1_2 m2_2 m3_2 m1_3 m2_3 m3_3 label
1 20 M 12.4 34 12 13 324 34 34 232 12 0
2 30 M 123.4 324 2 32 32 4 3 2 2 1

My idea would be to reshape the data like this: Note that I only did for the first row on the dataset above

id Age gender m1 m2 m3 Label
1 20 M 12.4 34 12 0
1 20 M 13 324 34 0
1 20 M 34 232 12 0

Basically, if there are 3 measurements per variable, I'd have 3 rows to reflect this information.

Am I going in the right direction with this approach? If not, could you point me to the right direction?

Thank you for taking your time in advance.

$\endgroup$
11
  • $\begingroup$ So m1, m2 and m3 are variables taken over time? If so, how you have arranged your data is the standard way to transform a time series problem that can be handled by typical supervised learning problems. However, this is assuming that you know what m1, m2, and m3 will be in the forecast period before observing the target variable. $\endgroup$
    – aranglol
    Commented Feb 20, 2021 at 20:25
  • $\begingroup$ Yes, m1,m2,m3 are measurements taken over time. I am not sure I understand what you mean by "this is assuming that you know what m1, m2, and m3 will be in the forecast period before observing the target variable". Do you mean that when I observe the second instance of m1, I should have a value for the first instance of m1? I used the full data shaped like the one above in a simple SVM model using GridSearchCV and the score for each iteration of GridSearch remains the same. I am not sure it is correct. A side note is that my data is unbalanced. About 87% are label 0 and 12% label 1. $\endgroup$
    – bws
    Commented Feb 20, 2021 at 20:30
  • $\begingroup$ Well, I am assuming you wish to predict the next periods value right? Like the target variable for the 4th time period, or even further? Then if you are using m1, m2 and m3 as predictors it is necessary that you know these values m1, m2 and m3 beforehand. If you know these values beforehand then there is no problem as far as I can tell data arrangement wise. $\endgroup$
    – aranglol
    Commented Feb 20, 2021 at 20:34
  • $\begingroup$ Also, how are you validating the model? Are you respecting the time aspect of your data, say, splitting the dataset by time? $\endgroup$
    – aranglol
    Commented Feb 20, 2021 at 20:37
  • $\begingroup$ No, I am not trying to predict the next value in the series. I'm trying to predict if the output is 1 or 0 by looking at the measurements. No, I just did the regular test_train_split as below: X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, test_size=0.4). and did the following for the GridSearchCV : svm = SVC(gamma=1) # Instantiate the GridSearchCV object and run the search parameters = {'C':[0.1, 1, 10], 'gamma':[0.00001, 0.0001, 0.001, 0.01, 0.1]} searcher = GridSearchCV(svm, parameters, scoring='accuracy', verbose=10) searcher.fit(X_train, y_train) $\endgroup$
    – bws
    Commented Feb 20, 2021 at 20:55

0

Your Answer

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