hossam 0.3.12__py3-none-any.whl → 0.3.15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hossam-0.3.12.dist-info → hossam-0.3.15.dist-info}/METADATA +1 -1
- {hossam-0.3.12.dist-info → hossam-0.3.15.dist-info}/RECORD +5 -6
- hossam/hs_interaction.py +0 -119
- {hossam-0.3.12.dist-info → hossam-0.3.15.dist-info}/WHEEL +0 -0
- {hossam-0.3.12.dist-info → hossam-0.3.15.dist-info}/licenses/LICENSE +0 -0
- {hossam-0.3.12.dist-info → hossam-0.3.15.dist-info}/top_level.txt +0 -0
|
@@ -3,15 +3,14 @@ hossam/__init__.py,sha256=_JKBoe04oOsil2xB2Ab4FD9Mat1hm7zngpx2ClJE51g,2609
|
|
|
3
3
|
hossam/data_loader.py,sha256=UpC_gn-xUWij0s-MO51qrzJNz3b5-RCz1N6esQMZUJM,6320
|
|
4
4
|
hossam/hs_classroom.py,sha256=b2vzxHapxibnJwcRwWvOfLfczjF-G3ZdT9hIUt4z4oU,27407
|
|
5
5
|
hossam/hs_gis.py,sha256=9ER8gXG2Or0DZ1fpbJR84WsNVPcxu788FsNtR6LsEgo,11379
|
|
6
|
-
hossam/hs_interaction.py,sha256=0E5yf7jc1u6nFIldmcnd27700IrWWJDOxFYH-WYGGCI,5095
|
|
7
6
|
hossam/hs_plot.py,sha256=U_rBU6PueGZboe0DzhSWUu3FGWrTdghI2XU9lVRuNg8,73966
|
|
8
7
|
hossam/hs_prep.py,sha256=sHoirbIXfv594SayqReuaVj_KbfjQD3upQ-VLaX27_w,22580
|
|
9
8
|
hossam/hs_stats.py,sha256=a50n8fWOVjsOgKQIzmlkOrAdtDOEzAbNoHvSiIGXc6c,107062
|
|
10
9
|
hossam/hs_timeserise.py,sha256=loRofR-m2NMxHaDEWDhZjo6DwayEf4c7qkSoCErfBWY,42165
|
|
11
10
|
hossam/hs_util.py,sha256=E4LnzPlRdWeqICv7TtTL9DT5PogqBhOuTgYiaav565U,7461
|
|
12
11
|
hossam/leekh.png,sha256=1PB5NQ24SDoHA5KMiBBsWpSa3iniFcwFTuGwuOsTHfI,6395
|
|
13
|
-
hossam-0.3.
|
|
14
|
-
hossam-0.3.
|
|
15
|
-
hossam-0.3.
|
|
16
|
-
hossam-0.3.
|
|
17
|
-
hossam-0.3.
|
|
12
|
+
hossam-0.3.15.dist-info/licenses/LICENSE,sha256=nIqzhlcFY_2D6QtFsYjwU7BWkafo-rUJOQpDZ-DsauI,941
|
|
13
|
+
hossam-0.3.15.dist-info/METADATA,sha256=ZgRxyHFZzqx76keXMxieyd8NV6pIVaBuWLTTy_GqeFs,13116
|
|
14
|
+
hossam-0.3.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
15
|
+
hossam-0.3.15.dist-info/top_level.txt,sha256=_-7bwjhthHplWhywEaHIJX2yL11CQCaLjCNSBlk6wiQ,7
|
|
16
|
+
hossam-0.3.15.dist-info/RECORD,,
|
hossam/hs_interaction.py
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# ===================================================================
|
|
3
|
-
# 상호작용(Interaction) 항 생성 함수
|
|
4
|
-
# ===================================================================
|
|
5
|
-
import numpy as np
|
|
6
|
-
from pandas import DataFrame
|
|
7
|
-
from itertools import combinations
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
# ===================================================================
|
|
11
|
-
# 변수 간의 상호작용 항을 추가한 데이터프레임을 반환한다
|
|
12
|
-
# ===================================================================
|
|
13
|
-
def interaction(*fields: str):
|
|
14
|
-
"""변수 간의 상호작용(interaction) 항을 생성하는 데코레이터 함수.
|
|
15
|
-
|
|
16
|
-
사용 방법: 원본 데이터프레임에 대해 호출하면 상호작용 컬럼이 추가된 새 데이터프레임을 반환한다.
|
|
17
|
-
|
|
18
|
-
Args:
|
|
19
|
-
*fields (str): 상호작용할 변수들의 컬럼명. 2개 이상의 컬럼을 지정하면 모든 조합의 상호작용을 생성.
|
|
20
|
-
지정하지 않으면 모든 수치형 컬럼의 모든 2-way 상호작용을 생성.
|
|
21
|
-
|
|
22
|
-
Returns:
|
|
23
|
-
function: 데이터프레임을 입력받아 상호작용 항이 추가된 데이터프레임을 반환하는 함수.
|
|
24
|
-
|
|
25
|
-
Examples:
|
|
26
|
-
>>> from hossam.hs_prep import interaction
|
|
27
|
-
>>> import pandas as pd
|
|
28
|
-
>>> df = pd.DataFrame({'x1': [1, 2, 3], 'x2': [4, 5, 6], 'x3': [7, 8, 9]})
|
|
29
|
-
|
|
30
|
-
# 특정 변수들의 상호작용만 생성
|
|
31
|
-
>>> result = interaction('x1', 'x2')(df)
|
|
32
|
-
>>> print(result.columns) # x1, x2, x3, x1*x2
|
|
33
|
-
|
|
34
|
-
# 모든 2-way 상호작용 생성
|
|
35
|
-
>>> result = interaction()(df)
|
|
36
|
-
>>> print(result.columns) # x1, x2, x3, x1*x2, x1*x3, x2*x3
|
|
37
|
-
"""
|
|
38
|
-
def wrapper(data: DataFrame) -> DataFrame:
|
|
39
|
-
df = data.copy()
|
|
40
|
-
|
|
41
|
-
# fields가 비어있으면 모든 수치형 컬럼의 2-way 상호작용 생성
|
|
42
|
-
if not fields:
|
|
43
|
-
numeric_cols = df.select_dtypes(include=[np.number]).columns.tolist()
|
|
44
|
-
cols_to_interact = list(combinations(numeric_cols, 2))
|
|
45
|
-
else:
|
|
46
|
-
# fields가 지정된 경우 모든 가능한 조합 생성
|
|
47
|
-
field_list = [f for f in fields if f in df.columns]
|
|
48
|
-
if len(field_list) < 2:
|
|
49
|
-
return df
|
|
50
|
-
cols_to_interact = list(combinations(field_list, 2))
|
|
51
|
-
|
|
52
|
-
# 상호작용 항 생성
|
|
53
|
-
for col1, col2 in cols_to_interact:
|
|
54
|
-
# 두 컬럼이 모두 수치형인지 확인
|
|
55
|
-
if not (pd.api.types.is_numeric_dtype(df[col1]) and pd.api.types.is_numeric_dtype(df[col2])):
|
|
56
|
-
continue
|
|
57
|
-
|
|
58
|
-
interaction_col_name = f"{col1}*{col2}"
|
|
59
|
-
df[interaction_col_name] = df[col1] * df[col2]
|
|
60
|
-
|
|
61
|
-
return df
|
|
62
|
-
|
|
63
|
-
return wrapper
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
# ===================================================================
|
|
67
|
-
# 직접 상호작용 항을 추가하는 함수 (데코레이터 없이 직접 사용)
|
|
68
|
-
# ===================================================================
|
|
69
|
-
def add_interaction(data: DataFrame, *fields: str) -> DataFrame:
|
|
70
|
-
"""데이터프레임에 상호작용 항을 추가한다.
|
|
71
|
-
|
|
72
|
-
특정 변수 쌍 또는 모든 수치형 변수 간의 상호작용 항을 생성하여 데이터프레임에 추가한다.
|
|
73
|
-
|
|
74
|
-
Args:
|
|
75
|
-
data (DataFrame): 원본 데이터프레임.
|
|
76
|
-
*fields (str): 상호작용할 변수들의 컬럼명 목록.
|
|
77
|
-
지정하지 않으면 모든 수치형 컬럼의 모든 2-way 상호작용을 생성.
|
|
78
|
-
지정된 경우, 지정된 컬럼들의 모든 조합에 대해 상호작용을 생성.
|
|
79
|
-
|
|
80
|
-
Returns:
|
|
81
|
-
DataFrame: 상호작용 항이 추가된 새 데이터프레임.
|
|
82
|
-
|
|
83
|
-
Examples:
|
|
84
|
-
>>> from hossam.hs_prep import add_interaction
|
|
85
|
-
>>> import pandas as pd
|
|
86
|
-
>>> df = pd.DataFrame({'x1': [1, 2, 3], 'x2': [4, 5, 6], 'x3': [7, 8, 9]})
|
|
87
|
-
|
|
88
|
-
# 특정 변수들의 상호작용만 추가
|
|
89
|
-
>>> result = add_interaction(df, 'x1', 'x2')
|
|
90
|
-
>>> print(result.columns) # x1, x2, x3, x1*x2
|
|
91
|
-
>>> print(result['x1*x2'].tolist()) # [4, 10, 18]
|
|
92
|
-
|
|
93
|
-
# 모든 2-way 상호작용 추가
|
|
94
|
-
>>> result = add_interaction(df)
|
|
95
|
-
>>> print(result.columns) # x1, x2, x3, x1*x2, x1*x3, x2*x3
|
|
96
|
-
"""
|
|
97
|
-
df = data.copy()
|
|
98
|
-
|
|
99
|
-
# fields가 비어있으면 모든 수치형 컬럼의 2-way 상호작용 생성
|
|
100
|
-
if not fields:
|
|
101
|
-
numeric_cols = df.select_dtypes(include=[np.number]).columns.tolist()
|
|
102
|
-
cols_to_interact = list(combinations(numeric_cols, 2))
|
|
103
|
-
else:
|
|
104
|
-
# fields가 지정된 경우 모든 가능한 조합 생성
|
|
105
|
-
field_list = [f for f in fields if f in df.columns]
|
|
106
|
-
if len(field_list) < 2:
|
|
107
|
-
return df
|
|
108
|
-
cols_to_interact = list(combinations(field_list, 2))
|
|
109
|
-
|
|
110
|
-
# 상호작용 항 생성
|
|
111
|
-
for col1, col2 in cols_to_interact:
|
|
112
|
-
# 두 컬럼이 모두 수치형인지 확인
|
|
113
|
-
if not (pd.api.types.is_numeric_dtype(df[col1]) and pd.api.types.is_numeric_dtype(df[col2])):
|
|
114
|
-
continue
|
|
115
|
-
|
|
116
|
-
interaction_col_name = f"{col1}*{col2}"
|
|
117
|
-
df[interaction_col_name] = df[col1] * df[col2]
|
|
118
|
-
|
|
119
|
-
return df
|
|
File without changes
|
|
File without changes
|
|
File without changes
|