# Classification when variables are in ranges

I want to classify my data and some of my variables are ranges.

I classify location so for example, school, the hours that people are at school are from 7:00 to 14:00, some of my variables are categorical (working day) and some of them numerics(frequency of visiting in a month).

I thought using LDA but how can I declare a range as one variable?

btw, I use Python

Example:

place         visiting time    frequency    workday
school         8:00-14:00        18-20           1
restaurant    13:00-21:00        0-3            both
bank          8:00-17:00         0-4             1
night club     21:00-2:00        0-4            both


The algorithm should be supervised because I insert the ground truth (the place) by myself.

TIA

• Hi and welcome to the site! Can you share a couple of examples what your data exactly looks like? And what exactly are you trying to classify (supervised)? Or is it rather about clustering (unsupervised)? Jan 6 '20 at 19:55
• Edited and add some examples Jan 6 '20 at 20:06

This is actually much more about feature engineering than just finding any representation. Therefore, I'd think through which variables might help your algorithm.

Here are some more ideas for features based on your time ranges which might be helpful:

• duration
• start time
• end time
• morning, day time, evening or night activity (categorical, i.e. not for LDA)

For the start and end time you might want to have a look at cyclic feature design.

• Thank you, I will check it out as well Jan 6 '20 at 20:38
• I tried your idea (right now without the categorical variable) and split my data set to x = [duration, start_time, end_time, work_day,week_end] and y = ['place] and I got an error says ValueError: The number of samples must be more than the number of classes.. Any idea what is wrong with it?  Jan 6 '20 at 20:44
• The problem is that I have only one sample for each class. Is there a way to pass this without generating a whole new database? Jan 6 '20 at 20:55

# Option 1

Convert range to numerical features. You can create 2 features from it.

     range
-------------
7:00 to 14:00

becomes

percentage of day in school | hours in school
----------------------------|----------------
0.29            |      7


# Option 2

Convert range to a hot-encoding. You can create 24 features from it.

     range
-------------
7:00 to 14:00

becomes

at 0:00|at 1:00|at 2:00|at 3:00|at 4:00|at 5:00|at 6:00|at 7:00|at 8:00|at 9:00|at 10:00|at 11:00|at 12:00|at 13:00|at 14:00|at 15:00|at 16:00|at 17:00|at 18:00|at 19:00|at 20:00|at 21:00|at 22:00|at 23:00
-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------
0   |   0   |   0   |   0   |   0   |   0   |   0   |   1   |   1   |   1   |    1   |    1   |    1   |    1   |    0   |    0   |    0   |    0   |    0   |    0   |    0   |    0   |    0   |    0


# Option 3

Combine both options for a total of 26 features.

• One Hot encoding sound like a good idea but classifier like LDA could work with that? Jan 6 '20 at 20:06