reliability = clf.predict(X_test) # outliers = -1

data = []
output = 'test2.csv'
for i in range(len(X_test)):
    satom1 = periodic_table.get_el_sp(int(X_test[i][0])) 
    satom2 = periodic_table.get_el_sp(int(X_test[i][1])) 
    natom1 = int(X_test[i][2])
    natom2 = int(X_test[i][3])
    str_mat = str(satom1) + str(natom1) + str(satom2) + str(natom2)
    formula = Composition(str_mat).reduced_formula
    temp = (formula, int(X_test[i][4]), int(y_pred[i]), reliability[i])
    data.append(temp)

properties=['formula','P', 'Tc', 'AD']
df = pd.DataFrame(data, columns=properties)
df.sort_values('Tc', ascending=False, inplace=True)
df.to_csv(output, index=False)
#df_in_ = df[df.AD ==  1]
#df_in_.to_csv(output, index=False)
print('Predicted Tc is written in file {}'.format(output))

#%%
param_grid = [
{'kernel': ['rbf'], 'gamma': range_g, 'C': range_c,'epsilon': range_e},
]
for i in range(10):
    dcv(X_train, y_train, model, param_grid)

print('{:.2f} seconds '.format(time() - start))
y_pred = gscv.predict(X_train)
print('train data: ', end="")
print_score(y_train, y_pred)
y_pred = gscv.predict(X_test)
print('test  data: ', end="")
print_score(y_test, y_pred)

y_pred = gscv.predict(X_train)
fig = yyplot(y_train, y_pred)
y_pred = gscv.predict(X_test)
fig = yyplot(y_test, y_pred)

#%%
# Novelty detection by One Class SVM with optimized hyperparameter
clf = OneClassSVM(nu=0.003,
                  kernel=gscv.best_params_['kernel'],
                  gamma=gscv.best_params_['gamma'])
clf.fit(X_train)

y_pred = gscv.predict(X_test)  # prediction
reliability = clf.predict(X_test)  # outliers = -1
results = np.c_[y_pred, y_test, reliability]
columns = ['predicted y', 'observed y', 'reliability']
df = pd.DataFrame(results, columns=columns)
print(df)

#%%
for i in range(10):
    dcv(X, y, mod, param_grid)

print('{:.2f} seconds '.format(time() - start))