gitlabds 1.1.0__tar.gz → 1.1.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gitlabds
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: Gitlab Data Science and Modeling Tools
5
5
  Home-page: https://gitlab.com/gitlab-data/gitlabds
6
6
  Author: Kevin Dietz
@@ -43,6 +43,10 @@ def dummy_code(
43
43
  DataFrame with dummy-coded columns. Categorical columns that were dummy coded will be dropped from the dataframe.
44
44
  """
45
45
 
46
+
47
+
48
+
49
+
46
50
  if columns == "all":
47
51
  var_list = df.columns.tolist()
48
52
  print("Will examine all variables as candidate for dummy coding")
@@ -205,9 +209,11 @@ def dummy_top(
205
209
 
206
210
  levels = levels.loc[levels > min_threshold].index.tolist()
207
211
 
212
+ dummy_dfs = []
208
213
  for l in levels:
209
- dummy_name = str(d) + "_dummy_" + str(l)
210
- new_df[dummy_name] = np.where(new_df[d] == str(l), 1, 0)
214
+ dummy_name = f"{d}_dummy_{l}"
215
+ dummy_series = pd.Series(np.where(new_df[d] == str(1), 1,0), name=dummy_name, index=new_df.index)
216
+ dummy_dfs.append(dummy_series)
211
217
 
212
218
  if output_file != None:
213
219
 
@@ -217,6 +223,8 @@ def dummy_top(
217
223
  else:
218
224
  f.write(f"\n df['{dummy_name}'] = np.where(df['{d}'] == '{l}', 1, 0)")
219
225
 
226
+ new_df = pd.concat([new_df] + dummy_dfs, axis=1)
227
+
220
228
  # drop categorical fields after they have been dummy coded
221
229
  if drop_categorial == True:
222
230
  new_df.drop(columns=[d], inplace=True)
@@ -225,4 +233,4 @@ def dummy_top(
225
233
  f.write('\n\n return df')
226
234
  f.close()
227
235
 
228
- return new_df
236
+ return new_df
@@ -112,7 +112,7 @@ def mad_outliers(
112
112
  # Windsor values if they fall below the windsor_threshold
113
113
  if ((min_aff / len(df) < windsor_threshold) and (min_aff > 0) and (new_min != old_min)):
114
114
 
115
- df[v].clip(lower=new_min, inplace=True)
115
+ df[v] = df[v].clip(lower=new_min)
116
116
 
117
117
  if verbose == True:
118
118
  print(f"{v} - MAD: {mad}; Lower Windsor Value: {new_min}, Rows affected {min_aff} ({min_aff/len(df)*100})")
@@ -122,7 +122,7 @@ def mad_outliers(
122
122
 
123
123
  if ((max_aff / len(df) < windsor_threshold) and (max_aff > 0) and (new_max != old_max)):
124
124
 
125
- df[v].clip(upper=new_max, inplace=True)
125
+ df[v] = df[v].clip(upper=new_max)
126
126
 
127
127
  if verbose == True:
128
128
  print(f"{v} - MAD: {mad}; Upper Windsor Value: {new_max}, Rows affected {max_aff} ({max_aff/len(df)*100}%)")
@@ -179,7 +179,7 @@ def mad_outliers(
179
179
  # Windsor values if they fall below the windsor_threshold
180
180
  if ((min_aff / len(df) < windsor_threshold) and (min_aff > 0) and (new_min != old_min)):
181
181
 
182
- new_df[v].clip(lower=new_min, inplace=True)
182
+ new_df[v] = new_df[v].clip(lower=new_min)
183
183
 
184
184
  if verbose == True:
185
185
  print(f"{v} - MAD: {mad}; Lower Windsor Value: {new_min}, Rows affected {min_aff} ({min_aff/len(df)*100})")
@@ -189,7 +189,7 @@ def mad_outliers(
189
189
 
190
190
  if ((max_aff / len(df) < windsor_threshold) and (max_aff > 0) and (new_max != old_max)):
191
191
 
192
- new_df[v].clip(upper=new_max, inplace=True)
192
+ new_df[v] = new_df[v].clip(upper=new_max)
193
193
 
194
194
  if verbose == True:
195
195
  print(f"{v} - MAD: {mad}; Upper Windsor Value: {new_max}, Rows affected {max_aff} ({max_aff/len(df)*100}%)")
@@ -51,9 +51,12 @@ def split_data(df:pd.DataFrame, train_pct:float=0.7, dv:str=None, dv_threshold:f
51
51
 
52
52
  print(f'Outcome variable "{dv}" pct: {dv_pct}. Below the dv_threshold value of {dv_threshold}. Will up-sample with SMOTE-NC...')
53
53
 
54
- # Get list of binary variables (mostly categorical dummy codes)
55
- cats = pd.DataFrame(x_train.select_dtypes(include=["number"]).nunique(dropna=False, axis=0))
56
- cats = np.where(cats[0] == 2, True, False)
54
+ # Get numeric columns
55
+ numeric_cols = x_train.select_dtypes(include=["number"]).columns
56
+
57
+ # Create categorical feature indices list. Should just be dummy features that have 2 values
58
+ cats = [i for i, col in enumerate(numeric_cols)
59
+ if x_train[col].nunique(dropna=False) == 2]
57
60
 
58
61
  # SMOTENC
59
62
  sm = SMOTENC(random_state=random_state,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gitlabds
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: Gitlab Data Science and Modeling Tools
5
5
  Home-page: https://gitlab.com/gitlab-data/gitlabds
6
6
  Author: Kevin Dietz
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes