willengler-uc commited on
Commit
4239845
·
verified ·
1 Parent(s): 18b59c3

Add metallicglass_Dmax

Browse files
.gitattributes CHANGED
@@ -60,3 +60,4 @@ model_perovskite_formationE/model.dill filter=lfs diff=lfs merge=lfs -text
60
  model_perovskite_conductivity/model.dill filter=lfs diff=lfs merge=lfs -text
61
  model_metallicglass_Rc_LLM/model.dill filter=lfs diff=lfs merge=lfs -text
62
  model_metallicglass_Rc/model.dill filter=lfs diff=lfs merge=lfs -text
 
 
60
  model_perovskite_conductivity/model.dill filter=lfs diff=lfs merge=lfs -text
61
  model_metallicglass_Rc_LLM/model.dill filter=lfs diff=lfs merge=lfs -text
62
  model_metallicglass_Rc/model.dill filter=lfs diff=lfs merge=lfs -text
63
+ model_metallicglass_Dmax/model.dill filter=lfs diff=lfs merge=lfs -text
model_metallicglass_Dmax/.gitattributes ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
model_metallicglass_Dmax/README.md ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # model_metallicglass_Dmax
2
+ Random forest model to predict the maximum casting diameter of metallic glasses
model_metallicglass_Dmax/RandomForestRegressor.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1186ef8804d518404508f736869163bd7f972646089a846ab9692b4473f31e13
3
+ size 13408723
model_metallicglass_Dmax/StandardScaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:88ed7071d46efef04a7f8399342b9c54ea5d1f0ae279312f9921d916e5592120
3
+ size 2541
model_metallicglass_Dmax/X_train.csv ADDED
The diff for this file is too large to render. See raw diff
 
model_metallicglass_Dmax/model.dill ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5505a5c7e21195b711cf54194a92d557736ed74d7c331bca0261859cdd081c23
3
+ size 33303638
model_metallicglass_Dmax/predict_metallicglass_Dmax.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pandas as pd
3
+ import numpy as np
4
+ import joblib
5
+ import dill
6
+ from mastml.feature_generators import ElementalFeatureGenerator, OneHotGroupGenerator
7
+
8
+ def get_preds_ebars_domains(df_test):
9
+ d = 'model_metallicglass_Dmax'
10
+ scaler = joblib.load(os.path.join(d, 'StandardScaler.pkl'))
11
+ model = joblib.load(os.path.join(d, 'RandomForestRegressor.pkl'))
12
+ df_features = pd.read_csv(os.path.join(d, 'X_train.csv'))
13
+ recal_params = pd.read_csv(os.path.join(d, 'recal_dict.csv'))
14
+
15
+ features = df_features.columns.tolist()
16
+ df_test = df_test[features]
17
+
18
+ X = scaler.transform(df_test)
19
+
20
+ # Make predictions
21
+ preds = model.predict(X)
22
+
23
+ # Get ebars and recalibrate them
24
+ errs_list = list()
25
+ a = recal_params['a'][0]
26
+ b = recal_params['b'][0]
27
+ c = recal_params['c'][0]
28
+ for i, x in X.iterrows():
29
+ preds_list = list()
30
+ for pred in model.model.estimators_:
31
+ preds_list.append(pred.predict(np.array(x).reshape(1, -1))[0])
32
+ errs_list.append(np.std(preds_list))
33
+ ebars = a * np.array(errs_list)**2 + b * np.array(errs_list) + c
34
+
35
+ # Get domains
36
+ with open(os.path.join(d, 'model.dill'), 'rb') as f:
37
+ model_domain = dill.load(f)
38
+
39
+ domains = model_domain.predict(X)
40
+
41
+ return preds, ebars, domains
42
+
43
+ def process_data(comp_list):
44
+ X = pd.DataFrame(np.empty((len(comp_list),)))
45
+ y = pd.DataFrame(np.empty((len(comp_list),)))
46
+
47
+ df_test = pd.DataFrame({'Material composition': comp_list})
48
+
49
+ # Try this both ways depending on mastml version used.
50
+ try:
51
+ X, y = ElementalFeatureGenerator(composition_df=df_test['Material composition'],
52
+ feature_types=['composition_avg', 'arithmetic_avg', 'max', 'min','difference'],
53
+ remove_constant_columns=False).evaluate(X=X, y=y, savepath=os.getcwd(), make_new_dir=False)
54
+ except:
55
+ X, y = ElementalFeatureGenerator(featurize_df=df_test['Material composition'],
56
+ feature_types=['composition_avg', 'arithmetic_avg', 'max', 'min',
57
+ 'difference'], remove_constant_columns=False).evaluate(X=X, y=y, savepath=os.getcwd(), make_new_dir=False)
58
+
59
+ df_test = pd.concat([df_test, X], axis=1)
60
+
61
+ return df_test
62
+
63
+ def make_predictions(comp_list):
64
+
65
+ # Process data
66
+ df_test = process_data(comp_list)
67
+
68
+ # Get the ML predicted values
69
+ preds, ebars, domains = get_preds_ebars_domains(df_test)
70
+
71
+ pred_dict = {'Compositions': comp_list,
72
+ 'Predicted Dmax (mm)': preds,
73
+ 'Ebar Dmax (mm)': ebars}
74
+
75
+ for d in domains.columns.tolist():
76
+ pred_dict[d] = domains[d]
77
+
78
+ del pred_dict['y_pred']
79
+ #del pred_dict['d_pred']
80
+ del pred_dict['y_stdu_pred']
81
+ del pred_dict['y_stdc_pred']
82
+
83
+ return pd.DataFrame(pred_dict)
model_metallicglass_Dmax/recal_dict.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ a,b,c
2
+ -0.00924471242524412,1.3186856766547437,1.0739939482671579
model_metallicglass_Dmax/requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ scikit-learn
2
+ numpy
3
+ pandas
4
+ mastml
5
+ pymatgen