# A Novel Intelligent Method for Fault Diagnosis of Steam Turbines Based on T-SNE and XGBoost
## Appendix A  
The following source code for reference is the t-SNE algorithm.  
```
#!/usr/bin/env python #coding:utf-8 import os import sys os.chdir (os.path.split (os.path.realpath (sys.argv [0]))[0]) import numpy from numpy import * import numpy as np from sklearn.manifold import TSNE from sklearn.datasets import load_iris from sklearn.decomposition import PCA import matplotlib.pyplot as plt import pandas as pd df1 = pd.read_excel ('D./data/gz5.xlsx') df1.label.value_counts 0 def get_data (data): X = data_drop (columns = [\"time', 'label']).values y = data_label.values n_samples, n_features = X.shape return X, y, n_samples, n_features X1, y1, n_samples1, n_features1 = get_data (df1) X_tsne = TSNE (n_components = 2,init = 'pca', random_state = 0).fit_transform (X1) def plot_embedding (X, y, title = None): X_min, x_max = np.min(X, 0), np.max(X, 0) X = (X - x_min) / (x_max - x_min)
```
plt.figure() ax=plt.subplot(111) for i in range (X.shape[0]): plt.text(X[i,0],X[i,1],'.', color=plt.cm.Set1(y[i]*3/10.), fontidict={'weight':'bold','size':9]} plt.xticks([]), plt.yticks([]) if title is not None: plt.title(title) plot_embedding(X_tsne,y1) from sklearn.cluster import KMeans from sklearn.externals import joblib from sklearn import cluster estimator = KMeans (n_clusters=2) res=estimator.fit_predict(X_tsne) lable_pred=estimator.labels_ centroids=estimator.cluster_centers_ inertia=estimator.inertia_ from pandas import DataFrame XA=DataFrame (res) XA_to_csv('D./data/gz5 out.csv')
```
**Algorithm A1** T-SNE algorithm.

The following source code for reference is the XGBoost algorithm.
``` #!/usr/bin/env python #coding:utf-8 fromxgboost import plot_importance from matplotlib import pyplot as plt import xgboost as xgb from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score import numpy as np import pandas as pd from xgboost.sklearn import XGBClassifier # load data data = pd.read_csv('D./data/suanfa/kyq.csv' x,y=data.loc[.data.columns.difference(['label']).values, data['label'].values x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3) data.label.value_counts() params={'learning_rate':0.1,'max_depth':2, 'n_estimators':50, 'num_boost_round':10,```
``` 'objective':'multisoftprob', 'random_state':0,'silent':0, 'num_class':6, 'eta':0.9 } model=xgb.train (params, xgb.DMatrix (x_train, y_train)) y_pred =model.predict (xgb.DMatrix (x_test)) yprob =np.argmax (y_pred, axis = 1) # return the index of the biggest pro model.save_model ('testXGBoostClass.model') yprob =np.argmax (y_pred, axis = 1) # return the index of the biggest pro predictions =[round (value) for value in yprob]
evaluate predictions accuracy =accuracy_score(y_test, predictions) print (\"Accuracy: %2.2%%%% % (accuracy * 100.0)) plot_importance (model) plt.show () xgb1 = XGBClassifier ( learning_rate = 0.1,  n_estimators = 20,  max_depth = 2,  num_boost_round = 10,  random_state = 0,  silent = 0,  objective ='multi:softprob',  num_class = 6,  eta = 0.9 ) xgb1.fit (x_train, y_train) y_pred1 = xgb1.predict_proba (x_test) yprob1 = np.argmax (y_pred1, axis = 1) # return the index of the biggest pro from sklearn.metrics import confusion_matrix confusion_matrix (y_test.astype ('int'), yprob1.astype ('int')) from sklearn.metrics import classification_report print ('Accuracy of Classifier':\(\chi\)xgb1.score (x_test, y_test.astype ('int'))) print (classification_report (y_test.astype ('int'), yprob1.astype ('int')))
```  
**Algorithm A2** XGBoost algorithm.