Upload thermalcond_aflow models
Browse files- .gitattributes +1 -0
- model_thermalcond_aflow/.gitattributes +4 -0
- model_thermalcond_aflow/README.md +2 -0
- model_thermalcond_aflow/RandomForestRegressor.pkl +3 -0
- model_thermalcond_aflow/StandardScaler.pkl +3 -0
- model_thermalcond_aflow/X_train.csv +0 -0
- model_thermalcond_aflow/model.dill +3 -0
- model_thermalcond_aflow/predict_thermalcond_aflow.py +82 -0
- model_thermalcond_aflow/recal_dict.csv +2 -0
- model_thermalcond_aflow/requirements.txt +5 -0
.gitattributes
CHANGED
|
@@ -37,3 +37,4 @@ model_bandgap-main/model.dill filter=lfs diff=lfs merge=lfs -text
|
|
| 37 |
model_piezoelectric-main/model.dill filter=lfs diff=lfs merge=lfs -text
|
| 38 |
model_perovskite_Habs-main/model.dill filter=lfs diff=lfs merge=lfs -text
|
| 39 |
model_Mg_alloy-main/model.dill filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 37 |
model_piezoelectric-main/model.dill filter=lfs diff=lfs merge=lfs -text
|
| 38 |
model_perovskite_Habs-main/model.dill filter=lfs diff=lfs merge=lfs -text
|
| 39 |
model_Mg_alloy-main/model.dill filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
model_thermalcond_aflow/model.dill filter=lfs diff=lfs merge=lfs -text
|
model_thermalcond_aflow/.gitattributes
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Auto detect text files and perform LF normalization
|
| 2 |
+
* text=auto
|
| 3 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.dill filter=lfs diff=lfs merge=lfs -text
|
model_thermalcond_aflow/README.md
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# model_thermalcond_aflow
|
| 2 |
+
Random forest model to predict the thermal conductivity of materials, trained from AFLOW database
|
model_thermalcond_aflow/RandomForestRegressor.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d4aaf522d442f9ec47485f3a8bbf756e7482c1b78ac1085a9ab8f525f821859c
|
| 3 |
+
size 99013264
|
model_thermalcond_aflow/StandardScaler.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fbf7d44096a2605e57fd064ca80a9099a1e0a9111f7ce231dcf6825335631ad8
|
| 3 |
+
size 1364
|
model_thermalcond_aflow/X_train.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model_thermalcond_aflow/model.dill
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f25862e70cb2f88322d84c555660fe2bfbcb846e01bbc537bf2c96e16c62836f
|
| 3 |
+
size 132167605
|
model_thermalcond_aflow/predict_thermalcond_aflow.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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_thermalcond_aflow'
|
| 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 |
+
for i, x in X.iterrows():
|
| 28 |
+
preds_list = list()
|
| 29 |
+
for pred in model.model.estimators_:
|
| 30 |
+
preds_list.append(pred.predict(np.array(x).reshape(1, -1))[0])
|
| 31 |
+
errs_list.append(np.std(preds_list))
|
| 32 |
+
ebars = a * np.array(errs_list) + b
|
| 33 |
+
|
| 34 |
+
# Get domains
|
| 35 |
+
with open(os.path.join(d, 'model.dill'), 'rb') as f:
|
| 36 |
+
model_domain = dill.load(f)
|
| 37 |
+
|
| 38 |
+
domains = model_domain.predict(X)
|
| 39 |
+
|
| 40 |
+
return preds, ebars, domains
|
| 41 |
+
|
| 42 |
+
def process_data(comp_list):
|
| 43 |
+
X = pd.DataFrame(np.empty((len(comp_list),)))
|
| 44 |
+
y = pd.DataFrame(np.empty((len(comp_list),)))
|
| 45 |
+
|
| 46 |
+
df_test = pd.DataFrame({'Material composition': comp_list})
|
| 47 |
+
|
| 48 |
+
# Try this both ways depending on mastml version used.
|
| 49 |
+
try:
|
| 50 |
+
X, y = ElementalFeatureGenerator(composition_df=df_test['Material composition'],
|
| 51 |
+
feature_types=['composition_avg', 'arithmetic_avg', 'max', 'min','difference'],
|
| 52 |
+
remove_constant_columns=False).evaluate(X=X, y=y, savepath=os.getcwd(), make_new_dir=False)
|
| 53 |
+
except:
|
| 54 |
+
X, y = ElementalFeatureGenerator(featurize_df=df_test['Material composition'],
|
| 55 |
+
feature_types=['composition_avg', 'arithmetic_avg', 'max', 'min',
|
| 56 |
+
'difference'], remove_constant_columns=False).evaluate(X=X, y=y, savepath=os.getcwd(), make_new_dir=False)
|
| 57 |
+
|
| 58 |
+
df_test = pd.concat([df_test, X], axis=1)
|
| 59 |
+
|
| 60 |
+
return df_test
|
| 61 |
+
|
| 62 |
+
def make_predictions(comp_list):
|
| 63 |
+
|
| 64 |
+
# Process data
|
| 65 |
+
df_test = process_data(comp_list)
|
| 66 |
+
|
| 67 |
+
# Get the ML predicted values
|
| 68 |
+
preds, ebars, domains = get_preds_ebars_domains(df_test)
|
| 69 |
+
|
| 70 |
+
pred_dict = {'Compositions': comp_list,
|
| 71 |
+
'Predicted thermal conductivity (W/m-K)': preds,
|
| 72 |
+
'Ebar thermal conductivity (W/m-K)': ebars}
|
| 73 |
+
|
| 74 |
+
for d in domains.columns.tolist():
|
| 75 |
+
pred_dict[d] = domains[d]
|
| 76 |
+
|
| 77 |
+
del pred_dict['y_pred']
|
| 78 |
+
#del pred_dict['d_pred']
|
| 79 |
+
del pred_dict['y_stdu_pred']
|
| 80 |
+
del pred_dict['y_stdc_pred']
|
| 81 |
+
|
| 82 |
+
return pd.DataFrame(pred_dict)
|
model_thermalcond_aflow/recal_dict.csv
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
a,b
|
| 2 |
+
0.9548670317937368,-0.038849973163035206
|
model_thermalcond_aflow/requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
scikit-learn
|
| 2 |
+
numpy
|
| 3 |
+
pandas
|
| 4 |
+
mastml
|
| 5 |
+
pymatgen
|