Last active
August 24, 2022 17:32
-
-
Save prabhant/ebc0f4f9eb17fec4a80047f2aeb4b184 to your computer and use it in GitHub Desktop.
Pipeline to Gama compatible string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p = Pipeline(steps=[('imputation', SimpleImputer(strategy='median')),('1', SMOTE(k_neighbors=21)),('0', EasyEnsembleClassifier(n_estimators=100))]) | |
try: | |
if p['imputation']: | |
p = p[1:] | |
except: | |
pass | |
print(p) | |
l = [] | |
for i in range(len(p)): | |
l.append(str(p[i].__class__()).replace('()','')) | |
#making string from pipeline | |
s = [] | |
#For making list | |
for i in reversed(l): | |
s.append(f"{i}(") | |
#for making data | |
data_string ="data" | |
s.append(data_string) | |
#for making hyperparameters | |
for i in range(len(p)): | |
keys = p[i].__dict__.keys() & clf_config[p[i].__class__].keys() | |
for j in keys: | |
# if j in clf_config[p[i].__class__].keys(): | |
if j == list(keys)[-1]: | |
if type(p[i].__dict__[j])==str: | |
s.append(f"{str(p[i].__class__()).replace('()','')}.{j}='{p[i].__dict__[j]}'") | |
else: | |
s.append(f"{str(p[i].__class__()).replace('()','')}.{j}={p[i].__dict__[j]}") | |
else: | |
if type(p[i].__dict__[j])==str: | |
s.append(f"{str(p[i].__class__()).replace('()','')}.{j}='{p[i].__dict__[j]}', ") | |
else: | |
s.append(f"{str(p[i].__class__()).replace('()','')}.{j}={p[i].__dict__[j]}, ") | |
s.append('), ') | |
s[-1] = ')' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment