-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
30 lines (23 loc) · 1.17 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from sklearn.preprocessing import QuantileTransformer
import pandas as pd
def string_list_to_list(strlist):
return [c.strip("'").strip('"') for c in strlist.strip("[]").split(", ")]
def quantile_transformation(s):
# Initialize the QuantileTransformer
# Set 'output_distribution' to 'uniform' or 'normal', depending on your needs
qt = QuantileTransformer(output_distribution='uniform', n_quantiles=s.nunique(), random_state=323)
# Fit and transform the data
# Note: QuantileTransformer expects a 2D array, so we use s.values.reshape(-1, 1) to reshape the Series
s_transformed = qt.fit_transform(s.values.reshape(-1, 1))
# The output is a numpy array, convert it back to a pandas Series if needed
s_transformed = pd.Series(s_transformed.flatten(), index=s.index)
return s_transformed
def prepare_concept_for_request(c):
repl_with_space = ["-","_", "\\", "/"]
repl_with_empty = ["%",":",'"',"+","*","(",")","[","]","{","}","|","'",'.']
for char in repl_with_space:
c = c.replace(char, " ")
for char in repl_with_empty:
c = c.replace(char, "")
c = c.replace(" ", " ")
return c.strip().strip("/").strip()