8. confidence intervals

import os
import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "Times New Roman"
from keras.engine.training import *
from utils import get_dataset, get_fitted_model, \
    confidenc_interval, plot_ci, evaluate_model
dataset, adsorbent_enc, dye_enc = get_dataset(encoding="ohe")


X_train, y_train = dataset.training_data()
***** Training *****
input_x shape:  (1059, 74)
target shape:  (1059, 1)
X_test, y_test = dataset.test_data()
***** Test *****
input_x shape:  (455, 74)
target shape:  (455, 1)
feature_names = dataset.input_features[0:10] + ['Adsorbent'] + ['Dye']
model, path, _ = get_fitted_model(model_type="functional", return_path=True)
***** Training *****
input_x shape:  (1059, 74)
target shape:  (1059, 1)
dot plot of model could not be plotted due to ('You must install pydot (`pip install pydot`) and install graphviz (see instructions at https://graphviz.gitlab.io/download/) ', 'for plot_model/model_to_dot to work.')
test_p = model.predict(x=X_test)
            argument test is deprecated and will be removed in future. Please
            use 'predict_on_test_data' method instead.
`Model.state_updates` will be removed in a future version. This property should not be used in TensorFlow 2.0, as `updates` are applied automatically.
evaluate_model(y_test, test_p)
mse 1982.9941791309736
rmse 44.53082279871969
r2 0.9862583591464813
r2_score 0.9862559257978472
mape inf
mae 19.717024301749014
alpha = 0.05
df = confidenc_interval(model, X_train[0:685], y_train[0:685],
                        X_test, y_test,
                        alpha=alpha)
argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.
plot_ci(df, alpha)
percent = int((1 - alpha) * 100)
fpath = os.path.join(path, f"{percent}_interval_")
plt.savefig(fpath, dpi=300, bbox_inches="tight")
plt.tight_layout()
plt.show()
confidence intervals
plot_ci(df.iloc[0:50], alpha)
percent = int((1 - alpha) * 100)
fpath = os.path.join(path, f"{percent}_interval_")
plt.savefig(fpath, dpi=300, bbox_inches="tight")
plt.tight_layout()
plt.show()
confidence intervals
alpha = 0.1
df = confidenc_interval(model, X_train[0:685], y_train[0:685],
                        X_test, y_test,
                        alpha=alpha)

plot_ci(df, alpha)
percent = int((1 - alpha) * 100)
fpath = os.path.join(path, f"{percent}_interval_")
plt.savefig(fpath, dpi=300, bbox_inches="tight")
plt.tight_layout()
plt.show()
confidence intervals
argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.
plot_ci(df.iloc[0:50], alpha)
percent = int((1 - alpha) * 100)
fpath = os.path.join(path, f"{percent}_interval_")
plt.savefig(fpath, dpi=300, bbox_inches="tight")
plt.tight_layout()
plt.show()
confidence intervals
alpha = 0.15
df = confidenc_interval(model, X_train[0:685], y_train[0:685],
                        X_test, y_test,
                        alpha=alpha)

plot_ci(df, alpha)
percent = int((1 - alpha) * 100)
fpath = os.path.join(path, f"{percent}_interval_")
plt.savefig(fpath, dpi=300, bbox_inches="tight")
plt.tight_layout()
plt.show()
confidence intervals
argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.
plot_ci(df.iloc[0:50], alpha)
percent = int((1 - alpha) * 100)
fpath = os.path.join(path, f"{percent}_interval_")
plt.savefig(fpath, dpi=300, bbox_inches="tight")
plt.tight_layout()
plt.show()
confidence intervals
alpha = 0.2
df = confidenc_interval(model, X_train[0:685], y_train[0:685],
                        X_test, y_test,
                        alpha=alpha)

plot_ci(df, alpha)
percent = int((1 - alpha) * 100)
fpath = os.path.join(path, f"{percent}_interval_")
plt.savefig(fpath, dpi=300, bbox_inches="tight")
plt.tight_layout()
plt.show()
confidence intervals
argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.
plot_ci(df.iloc[0:50], alpha)
percent = int((1 - alpha) * 100)
fpath = os.path.join(path, f"{percent}_interval_")
plt.savefig(fpath, dpi=300, bbox_inches="tight")
plt.tight_layout()
plt.show()
confidence intervals
alpha = 0.25
df = confidenc_interval(model, X_train[0:685], y_train[0:685],
                        X_test, y_test,
                        alpha=alpha)

plot_ci(df, alpha)
percent = int((1 - alpha) * 100)
fpath = os.path.join(path, f"{percent}_interval_")
plt.savefig(fpath, dpi=300, bbox_inches="tight")
plt.tight_layout()
plt.show()
confidence intervals
argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.

argument test is deprecated and will be removed in future. Please
use 'predict_on_test_data' method instead.
plot_ci(df.iloc[0:50], alpha)
percent = int((1 - alpha) * 100)
fpath = os.path.join(path, f"{percent}_interval_")
plt.savefig(fpath, dpi=300, bbox_inches="tight")
plt.tight_layout()
plt.show()
confidence intervals

Total running time of the script: (1 minutes 33.184 seconds)

Gallery generated by Sphinx-Gallery