<jupyter_start><jupyter_text>Trajectory Library usageIn this cell, we load data.we need to pass the column names for latitude, longitude, time and date, target (our class labels), file name and the seperator character.<jupyter_code>ts_obj=ts.TrajectorySegmentation()
ts_obj.load_data(lat='lat',lon='lon',time_date='time',
                 labels=['target'],src='animal.csv',seperator=',')
print(ts_obj.return_row_data().shape)<jupyter_output>loading...
lat
lon
None
time
['target']
animal.csv
,
Data loaded.
(287095, 6)<jupyter_text>Check class labels<jupyter_code>set(ts_obj.return_row_data().target)<jupyter_output><empty_output><jupyter_text>SegmentationIn this cell, we segment our raw trajectory. We can use segmentation methods avaiable such as segmentByLabel, Multi_Label_Segmentation and ...Using segmentByLabel, we need to pass label as a column that has trajectory IDs.Using multi_label_segmentation, we pass an array of columns that is going to segment our data.<jupyter_code>segments, trajectorySegments=ts_obj.segmentByLabel(label='tid')
#segments, trajectorySegments = ts_obj.segmentByStopMove()
#segments, trajectorySegments=ts_obj.multi_label_segmentation(labels=['t_user_id','day','transportation_mode'])
print('Number of trajectories in dataset:',len(trajectorySegments))
print('Classes in dataset:',set(ts_obj.return_row_data().target))<jupyter_output>Number of trajectories in dataset: 253
Classes in dataset: {'cattle', 'deer', 'elk'}<jupyter_text>Feature ExtractionFor each segment generated using the previous step, we generate point features and trajectory features and collect them in an array.<jupyter_code>i=1
features=[]
for seg in range(len(trajectorySegments)):
    # only use segments longer than 10
    if(trajectorySegments[seg].shape[0]>10):
        tr_obj=tr.Trajectory(mood='df',trajectory=trajectorySegments[seg],labels=['target'])
        
        tr_obj.point_features() # generate point_features
        f=tr_obj.segment_features()# generate segment_features
        userid=1

        f.append(userid)
        features.append(np.array(f))
        i=i+1
        if (i%300)==1:
            print(i)<jupyter_output><empty_output><jupyter_text>save the feature extraction results<jupyter_code>bearingSet=[ 'bearing_min', 'bearing_max', 'bearing_mean', 'bearing_median', 'bearing_std','bearing_p10','bearing_p25','bearing_p50','bearing_p75','bearing_p90']
speedSet=[ 'speed_min', 'speed_max', 'speed_mean', 'speed_median', 'speed_std','speed_p10','speed_p25','speed_p50','speed_p75','speed_p90']
distanceSet=[ 'distance_min', 'distance_max', 'distance_mean', 'distance_median', 'distance_std','distance_p10','distance_p25','distance_p50','distance_p75','distance_p90']
accelerationSet=['acceleration_min', 'acceleration_max', 'acceleration_mean', 'acceleration_median','acceleration_std','acceleration_p10','acceleration_p25','acceleration_p50','acceleration_p75','acceleration_p90']
jerkSet=[ 'jerk_min', 'jerk_max', 'jerk_mean', 'jerk_median', 'jerk_std','jerk_p10','jerk_p25','jerk_p50','jerk_p75','jerk_p90']
brateSet=[ 'bearing_rate_min', 'bearing_rate_max', 'bearing_rate_mean', 'bearing_rate_median', 'bearing_rate_std','bearing_rate_p10','bearing_rate_p25','bearing_rate_p50','bearing_rate_p75','bearing_rate_p90']
brate_rateSet=[ 'brate_rate_min', 'brate_rate_max', 'brate_rate_mean', 'brate_rate_median', 'brate_rate_std','brate_rate_p10','brate_rate_p25','brate_rate_p50','brate_rate_p75','brate_rate_p90']
stop_timeSet=[ 'stop_time_min', 'stop_time_max', 'stop_time_mean', 'stop_time_median', 'stop_time_std','stop_time_p10','stop_time_p25','stop_time_p50','stop_time_p75','stop_time_p90']

targetset=['cattle', 'deer', 'elk']
col=distanceSet+speedSet+accelerationSet+bearingSet+jerkSet+brateSet+brate_rateSet+stop_timeSet+['isInValid', 'isPure', 'target','stopRate','starTime', 'endTime',  'isWeekDay', 'dayOfWeek', 'durationInSeconds', 'distanceTravelled', 'startToEndDistance','startLat', 'starLon', 'endLat', 'endLon', 'selfIntersect', 'modayDistance', 'tuesdayDistance', 'wednesdayDay', 'thursdayDistance', 'fridayDistance', 'saturdayDistance', 'sundayDistance', 'stopTotal','stopTotalOverDuration', 'userId']

features_set = pd.DataFrame(features,columns=col)
features_set.to_csv('features_animal.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14305717619603267, 'fraction_numerical': 0.023803967327887983, 'mean_word_length': 9.850632911392404, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '208112', 'license': 'Apache-2.0', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1420, 'n_words': 240, 'path': 'TrajLib_Usage_Example.ipynb', 'repo_name': 'JRose6/TrajLib', 'size': '4285'}