snajmark commited on
Commit
97c782e
·
1 Parent(s): 4f4cd8d

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +10 -44
utils.py CHANGED
@@ -8,14 +8,14 @@ import joblib
8
  import matplotlib.pyplot as plt
9
 
10
  # Explainer path
11
- explainer_filename = "explainer.bz2"
12
 
13
  feature_names = ['PROPERTY: BCC/FCC/other', 'PROPERTY: Calculated Density (g/cm$^3$)',
14
  'PROPERTY: Calculated Young modulus (GPa)',
15
- #'PROPERTY: Processing method', 'PROPERTY: Microstructure',
16
- #'PROPERTY: Single/Multiphase', 'Microstructure One Hot',
17
- #'Processing Method One Hot', 'BCC/FCC/other One Hot',
18
- #'Single/Multiphase One Hot',
19
  'Microstructure B2',
20
  'Microstructure B2+BCC', 'Microstructure B2+L12',
21
  'Microstructure B2+Laves+Sec.', 'Microstructure B2+Sec.',
@@ -43,8 +43,8 @@ feature_names = ['PROPERTY: BCC/FCC/other', 'PROPERTY: Calculated Density (g/cm$
43
  'Preprocessing method CAST', 'Preprocessing method OTHER',
44
  'Preprocessing method POWDER', 'Preprocessing method WROUGHT',
45
  'BCC/FCC/other BCC', 'BCC/FCC/other FCC', 'BCC/FCC/other OTHER',
46
- #'Single/Multiphase ',
47
- 'Single/Multiphase M', 'Single/Multiphase S']
48
 
49
  def return_feature_names():
50
  return feature_names
@@ -140,44 +140,9 @@ def return_num_classes_one_hot(df):
140
  "Num classes single/multiphase": num_classes_single_multiphase,
141
  "Num classes bcc/fcc/other": num_classes_bcc_fcc_other}
142
 
143
- # def turn_into_one_hot(X, mapping_dict):
144
- # one_hot = X
145
- # num_classes_one_hot = {'Num classes microstructure': 45, 'Num classes preprocessing': 5,
146
- # 'Num classes single/multiphase': 3, 'Num classes bcc/fcc/other': 3}
147
- # one_hot["Microstructure One Hot"] = X["PROPERTY: Microstructure"].apply(to_categorical_num_classes_microstructure, num_classes_one_hot=num_classes_one_hot)
148
- # one_hot["Processing Method One Hot"] = X["PROPERTY: Processing method"].apply(to_categorical_num_classes_processing,
149
- # num_classes_one_hot=num_classes_one_hot)
150
- # one_hot["BCC/FCC/other One Hot"] = X["PROPERTY: BCC/FCC/other"].apply(to_categorical_bcc_fcc_other,
151
- # num_classes_one_hot=num_classes_one_hot)
152
- # one_hot["Single/Multiphase One Hot"] = X["PROPERTY: Single/Multiphase"].apply(to_categorical_single_multiphase,
153
- # num_classes_one_hot=num_classes_one_hot)
154
-
155
- # flatten_microstructure = one_hot["Microstructure One Hot"].apply(pd.Series)
156
- # flatten_processing = one_hot["Processing Method One Hot"].apply(pd.Series)
157
- # flatten_bcc_fcc_other = one_hot["BCC/FCC/other One Hot"].apply(pd.Series)
158
- # flatten_single_multiphase = one_hot["Single/Multiphase One Hot"].apply(pd.Series)
159
-
160
- # one_hot.drop(columns=["Microstructure One Hot", "Processing Method One Hot", "BCC/FCC/other One Hot",
161
- # "Single/Multiphase One Hot"])
162
-
163
- # for column in flatten_microstructure.columns:
164
- # one_hot["Microstructure " + str(
165
- # list(mapping_dict["PROPERTY: Microstructure"].keys())[int(column)])] = flatten_microstructure[int(column)]
166
- # for column in flatten_processing.columns:
167
- # one_hot["Preprocessing method " + str(list(mapping_dict["PROPERTY: Processing method"].keys())[int(column)])] = flatten_processing[column]
168
- # for column in flatten_bcc_fcc_other.columns:
169
- # one_hot["BCC/FCC/other " + str(list(mapping_dict["PROPERTY: BCC/FCC/other"].keys())[int(column)])] = flatten_bcc_fcc_other[column]
170
- # for column in flatten_single_multiphase.columns:
171
- # one_hot["Single/Multiphase " + str(list(mapping_dict["PROPERTY: Single/Multiphase"].keys())[int(column)])] = flatten_single_multiphase[column]
172
-
173
- # one_hot = one_hot.drop(columns=["PROPERTY: Microstructure", "Microstructure One Hot", "BCC/FCC/other One Hot", "Single/Multiphase One Hot",
174
- # "Processing Method One Hot", "PROPERTY: Processing method", "PROPERTY: BCC/FCC/other", "PROPERTY: Single/Multiphase"])
175
- # return one_hot
176
-
177
-
178
  def turn_into_one_hot(X, mapping_dict):
179
  one_hot = X
180
- num_classes_one_hot = {'Num classes microstructure': 30, 'Num classes preprocessing': 5,
181
  'Num classes single/multiphase': 3, 'Num classes bcc/fcc/other': 3}
182
  one_hot["Microstructure One Hot"] = X["PROPERTY: Microstructure"].apply(to_categorical_num_classes_microstructure, num_classes_one_hot=num_classes_one_hot)
183
  one_hot["Processing Method One Hot"] = X["PROPERTY: Processing method"].apply(to_categorical_num_classes_processing,
@@ -205,5 +170,6 @@ def turn_into_one_hot(X, mapping_dict):
205
  for column in flatten_single_multiphase.columns:
206
  one_hot["Single/Multiphase " + str(list(mapping_dict["PROPERTY: Single/Multiphase"].keys())[int(column)])] = flatten_single_multiphase[column]
207
 
208
- one_hot = one_hot.drop(columns=["PROPERTY: Microstructure", "Microstructure One Hot", "BCC/FCC/other One Hot", "Single/Multiphase One Hot", "Processing Method One Hot", "PROPERTY: Processing method", "PROPERTY: BCC/FCC/other", "PROPERTY: Single/Multiphase"])
 
209
  return one_hot
 
8
  import matplotlib.pyplot as plt
9
 
10
  # Explainer path
11
+ explainer_filename = "models/explainer_old.bz2"
12
 
13
  feature_names = ['PROPERTY: BCC/FCC/other', 'PROPERTY: Calculated Density (g/cm$^3$)',
14
  'PROPERTY: Calculated Young modulus (GPa)',
15
+ 'PROPERTY: Processing method', 'PROPERTY: Microstructure',
16
+ 'PROPERTY: Single/Multiphase', 'Microstructure One Hot',
17
+ 'Processing Method One Hot', 'BCC/FCC/other One Hot',
18
+ 'Single/Multiphase One Hot',
19
  'Microstructure B2',
20
  'Microstructure B2+BCC', 'Microstructure B2+L12',
21
  'Microstructure B2+Laves+Sec.', 'Microstructure B2+Sec.',
 
43
  'Preprocessing method CAST', 'Preprocessing method OTHER',
44
  'Preprocessing method POWDER', 'Preprocessing method WROUGHT',
45
  'BCC/FCC/other BCC', 'BCC/FCC/other FCC', 'BCC/FCC/other OTHER',
46
+ 'Single/Multiphase ',
47
+ 'Single/Multiphase M', 'Single/Multiphase S']
48
 
49
  def return_feature_names():
50
  return feature_names
 
140
  "Num classes single/multiphase": num_classes_single_multiphase,
141
  "Num classes bcc/fcc/other": num_classes_bcc_fcc_other}
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  def turn_into_one_hot(X, mapping_dict):
144
  one_hot = X
145
+ num_classes_one_hot = {'Num classes microstructure': 45, 'Num classes preprocessing': 5,
146
  'Num classes single/multiphase': 3, 'Num classes bcc/fcc/other': 3}
147
  one_hot["Microstructure One Hot"] = X["PROPERTY: Microstructure"].apply(to_categorical_num_classes_microstructure, num_classes_one_hot=num_classes_one_hot)
148
  one_hot["Processing Method One Hot"] = X["PROPERTY: Processing method"].apply(to_categorical_num_classes_processing,
 
170
  for column in flatten_single_multiphase.columns:
171
  one_hot["Single/Multiphase " + str(list(mapping_dict["PROPERTY: Single/Multiphase"].keys())[int(column)])] = flatten_single_multiphase[column]
172
 
173
+ one_hot = one_hot.drop(columns=["PROPERTY: Microstructure", "Microstructure One Hot", "BCC/FCC/other One Hot", "Single/Multiphase One Hot",
174
+ "Processing Method One Hot", "PROPERTY: Processing method", "PROPERTY: BCC/FCC/other", "PROPERTY: Single/Multiphase"])
175
  return one_hot