Supple Maximizing Performance in Cs CuBiCl
Supple Maximizing Performance in Cs CuBiCl
VLSI Centre of Excellence, Chitkara University Institute of Engineering and Technology, Chitkara University,
Punjab, India
*Corresponding authors
Random Forest-
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import keras_tuner as kt
import shap
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error, mean_absolute_error,
r2_score
from sklearn.preprocessing import StandardScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout
from tensorflow.keras.callbacks import EarlyStopping
# Import the RandomSearch tuner from keras_tuner
from keras_tuner.tuners import RandomSearch
df = pd.read_csv('/content/drive/MyDrive/ML/Nikhil_ML3.csv')
# Split data into features and target variables
X = df[['Thickness', 'doping', 'Defect']]
y = df['PCE (%)']
Output
Mean Squared Error: 0.05262326227246941
R-squared: 0.9897033432799267
Cross-Validation Score: -5256.733933041297
Best Parameters: {'max_depth': 7, 'min_samples_leaf': 1, 'n_estimators':
100}
Best Score: 0.9914386927829856
# Plotting actual PCE vs predicted FF for the training set and test set
plt.scatter(y_train, y_train_pred, c='blue', label='Training set')
plt.scatter(y_test, y_test_pred, c='red', label='Test set')
plt.plot(np.linspace(xmin, xmax, 100), np.linspace(xmin, xmax, 100), '-
-', label='Perfect fit')
plt.xlabel('Actual PCE')
plt.ylabel('Predicted PCE')
plt.title(' RF Actual vs Predicted | PCE')
plt.legend()
plt.savefig('10082023RF_PCE_Actual vs predicted.png', dpi=600)
plt.show()
XGBoost-
import pandas as pd
import numpy as np
import xgboost as xgb
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.metrics import mean_squared_error, r2_score
from xgboost import XGBRegressor
from sklearn.model_selection import cross_val_score
best_params = grid_search.best_params_
print("Best Hyperparameters:", best_params)
# Creating the final XGBRegressor model with the best hyperparameters
final_xgb_model = xgb.XGBRegressor(**best_params)
# Training the model
final_xgb_model.fit(X_train, y_train)
# Predicting the target variable on the test set
y_test_pred = final_xgb_model.predict(X_test)
# Predict on training and test sets
y_train_pred = final_xgb_model.predict(X_train)
# Calculating the mean squared error
mse = mean_squared_error(y_test, y_test_pred)
r2 = r2_score(y_test, y_test_pred)
cv_score = cross_val_score(grid_search.best_estimator_, X, y, cv=50)
print('Mean Squared Error:', mse)
print('R-squared:', r2)
print('Cross-Validation Score:', cv_score.mean())
print('Best Parameters:', grid_search.best_params_)
print('Best Score:', grid_search.best_score_)
Output
Best Hyperparameters: {'learning_rate': 0.1, 'max_depth': 7,
'min_child_weight': 1, 'n_estimators': 200}
Mean Squared Error: 0.0014407104963233793
R-squared: 0.9997180999281869
Cross-Validation Score: -4718.083636367358
Best Parameters: {'learning_rate': 0.1, 'max_depth': 7, 'min_child_weight':
1, 'n_estimators': 200}
Best Score: 0.9998299680327589
import shap
explainer = shap.TreeExplainer(final_xgb_model)
shap_values = explainer.shap_values(X)
# Creating a SHAP plot to show the impact of all features
plt.savefig('20052023XGB_AgBiSCl2NK_PCE_SHAP values.png', dpi=600)
shap.summary_plot(shap_values, X)
# Calculate the x-axis range for the plot
xmin = min(min(y_train_pred), min(y_test_pred))
xmax = max(max(y_train_pred), max(y_test_pred))
# Plotting actual PCE vs predicted PCE for the training set and test
set
plt.scatter(y_train, y_train_pred, c='blue', label='Training set')
plt.scatter(y_test, y_test_pred, c='red', label='Test set')
plt.plot(np.linspace(xmin, xmax, 100), np.linspace(xmin, xmax, 100), '-
-', label='Perfect fit')
plt.xlabel('Actual PCE')
plt.ylabel('Predicted PCE')
plt.title('Actual vs Predicted | PCE | AgBiSCl2NK')
plt.legend()
plt.savefig('20052023XGB_AgBiSCl2NK_PCE_Actual vs predicted.png',
dpi=600)
plt.show()