Skip to content

Commit

Permalink
Update feature_engineering.py
Browse files Browse the repository at this point in the history
pjh feature engineering 주석 작성
  • Loading branch information
PJHgh authored Jun 7, 2021
1 parent 9a965bb commit 6c2fe04
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions feature_engineering.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ def userID_testid_experience(df):
# userID별 시간 순으로 정렬
df = df.sort_values(by=['userID', 'Timestamp']).reset_index(drop=True)

# userID, testID별로
# userID 별로 testid를 풀어본 적 있는지
df["userID_testid_experience"] = df.groupby(["userID", "testId"])['testId'].cumcount()
df['userID_testid_experience'] = df['userID_testid_experience'].apply(lambda x : 1 if x > 0 else 0)
return df

def userID_assessmentItemID_experience(df):
# userID별 시간 순으로 정렬
df = df.sort_values(by=['userID', 'Timestamp']).reset_index(drop=True)
# userID별 시간 순으로 정렬

# userID 별로 assessmentItemID를 풀어본 적 있는지
df["userID_assessmentItemID_experience"] = df.groupby(["userID", "assessmentItemID"])['assessmentItemID'].cumcount()
df['userID_assessmentItemID_experience'] = df['userID_assessmentItemID_experience'].apply(lambda x : 1 if x > 0 else 0)
return df
Expand All @@ -28,11 +29,14 @@ def userID_time_diff_from_last(df):
def convert_time(s):
timestamp = time.mktime(datetime.strptime(s, '%Y-%m-%d %H:%M:%S').timetuple())
return int(timestamp)


# 초 단위 시간
df['sec'] = df['Timestamp'].apply(convert_time)

# userID별 시간 순으로 정렬 + index column 생성
df = df.sort_values(by=['userID', 'sec']).reset_index(drop=False)


# userID별 마지막 index 값
last_idx_group = df.groupby(['userID'])['index'].agg(["max"])
last_idx_group = last_idx_group.reset_index()
last_idx_group.columns = ['userID', 'last_index']
Expand All @@ -43,6 +47,7 @@ def changed_time(x):
period = last_time-x['sec']
return period

# userID별 마지막 index의 시간과의 차이 계산
df["userID_time_diff_from_last"] = df.apply(changed_time, axis=1)

df.drop('sec', axis=1, inplace=True)
Expand Down

0 comments on commit 6c2fe04

Please sign in to comment.