I am working on a classification project in which I am required to detect a component of a railway switch using time-series data collected from an inductive sensor.

After some signal processing, I have implemented Short Time Fourier Transform (STFT), which yields a feature matrix (51 features in total) and time values corresponding to each STFT window. I labelled the windows by comparing it to the excel file containing my manual labelling.

The points where the components are present have been marked as label 1 and the points where there are no components have been marked as label 0. There are 39263 0s in total, whereas only 71 1s. To cater this problem of unbalanced labels, I used oversampling approach after splitting my data into train and test datasets which making sure that each of them contains at least one 1 label using stratify.

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=101, stratify=y, shuffle=True)

oversample = RandomOverSampler(sampling_strategy='minority')
X_train_over, y_train_over = oversample.fit_resample(X_train, y_train)
X_test_over, y_test_over = oversample.fit_resample(X_test, y_test)

So, this is a hard labelling approach (binary labels 0 or 1) that I am using, and it is not yielding good results as the model is over-fitting or becoming over-confident.

The following is a snapshot of the results (Confusion Matrix) obtained from logistic regression:

enter image description here

Now, I am thinking of using a soft labelling approach to enhance the robustness of my model. However, the classification models do not accept float values. What should I do?

I am trying to do something like this:

However, how can I use soft labels for classification? Do I need to clarify more?

enter image description here

  • $\begingroup$ It would be great if you shared the data. $\endgroup$
    – Royi
    Nov 23 at 9:30
  • $\begingroup$ Due to confidentiality policies, I cannot share the data. Could you please elaborate what information do you need from the data so that I can explain my case better? $\endgroup$ Nov 23 at 9:35

1 Answer 1


You may take one of the following 2 approaches (Which are pretty equivalent):

  1. Use a Classifier with Cross Entropy Loss
    The cross entropy loss basically minimizes the differences between 2 distributions. For binary classification we usually have one class with value of 1 and the other as 0. But you may use any values you want for each class. So in case of soft you may use 0.95 for the 1 class and 0.05 for the 0 class.

  2. Use a Regressor for the Probability
    This is very similar to the way the logistic regression works. But you may try other regressors as well.

This an answer to your direct question about moving to soft labelling.

Beyond that, your data looks like imbalanced data, it might be the problem more than the classification type. If you shared the features you have in a different question we might have a better idea what to do.

  • $\begingroup$ Can we actually use a regressor model for classification? Secondly, I am working on a time-series data which has been collected from the inductive sensor. The data contains time values, sensor data and position values for the train. And because the project is position dependent, I have moved from Time domain to Position domain using interpolation. To extract features from the data, I have implemented STFT $\endgroup$ Nov 23 at 10:42
  • $\begingroup$ Maybe more data about the train? Weight, number of railroad cars? $\endgroup$
    – Royi
    Nov 23 at 11:17
  • $\begingroup$ Oh I am afraid that kind of information is not available to me $\endgroup$ Nov 23 at 14:17
  • $\begingroup$ However, it is hard for me to understand that how can we use a regressor for classification problem $\endgroup$ Nov 23 at 14:17
  • $\begingroup$ You try to regress over the probability of the class of interest. This is basically what logistic regression is doing. $\endgroup$
    – Royi
    Nov 23 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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