# - * -コーディング:UTF-8 - * - ""」 月3月9日午前13時24分〇七秒2020で作成されました @author:管理者 「」」 から scipy.io インポートloadmat から sklearn.ensemble インポートRandomForestRegressor から sklearn.neural_networkのインポートMLPRegressor から sklearn.svm インポートSVRの インポートのNPとしてnumpyの インポートPLTのようmatplotlib.pyplot インポートMPLとしてmatplotlibの から sklearn.metricsのインポートr2_score から sklearnのインポートメトリック mpl.rcParams [ ' font.sans-セリフ' ] = [ ' カイティ' ] mpl.rcParams [ ' font.serif ' ] = [ ' カイティ' ] #は中国のmatplotlibのを表示できない問題解決 plt.rcParamsを[ ' axes.unicode_minus ' ] = Falseの #は、問題の負の表示座標解決 位[2]元29、請求ランダム森+ データ= loadmat(' original_data.mat ' ) train_data =データ[ ' train_data ' ] train_label = DATA [ ' train_label ' ] .reshape(-1,1) #のデータセットとなる(-1、n)は、n番目のカラムとなる TEST_DATA = DATA [ ' TEST_DATA ' ] test_label =データ[ ' test_label ' ] .reshape(-1,1 ) #(1、-1)RESHAPEデータセットは、行になり(N、-1):n行目となる RFL = RandomForestRegressor(MAX_DEPTH = 2、random_state = 0 ) rf1.fit(train_data、train_label.ravel()) test_pred1 = rf1.predict(TEST_DATA).reshape(-1,1 ) plt.figure() plt.plot(test_label、' - * '、ラベル= ' 真' ) plt.plot(test_pred1、' -p '、ラベル= ' preict ' ) plt.title(' ランダムフォレストにより、29 + ' ) plt.xlabel(" 試験試料" ) plt.ylabel(' 残りの人生/ H ' ) plt.legend() plt.show() #計算指標が 印刷(' ランダムフォレストを特徴オリジナル+ 29 ' ) #MAPE test_mape = np.mean(np.abs((test_pred1-test_label)/ test_label))を #RMSE test_rmse = np.sqrt(np.mean(NP .square(test_pred1- test_label))) #メイ test_mae = np.mean(np.abs(test_pred1- test_label)) #R2 test_r2 = r2_score(test_label、test_pred1) プリント(「オリジナル+ 29ランダムフォレストテストセットMAPE特徴: 'test_mape、 ' RMSE: 'test_rmse、 ' メイ: 'test_mae、 'R2:" 、test_r2) #で[3] KPCA回帰に+ランダムフォレスト データ = loadmat(' kpca_data.mat ' ) train_data =データ[ ' train_data ' ] train_label =データ[ ' train_label ' ] .reshape(-1,1 ) TEST_DATA =データ[ ' TEST_DATA ' ] test_label =データ[ ' test_label ' ] .reshape(-1,1 ) RF2 = RandomForestRegressor(MAX_DEPTH = 10、random_state = 0) rf2.fit(train_data、train_label.ravel()) #ラヴェルは、一次元の多次元なる test_pred2 = rf2.predict(TEST_DATA).reshape(-1,1 ) plt.figure() plt.plot(test_label、' - * '、ラベル= ' 真' ) plt.plot(test_pred2、' -p '、ラベル= ' preict ' ) (plt.title ' KPCA +ランダム森林に対する' ) plt.xlabel(" 試験試料" ) plt.ylabel(' 残りの人生/ H ' ) plt.legend() plt.show() 印刷(' KPCA +ランダム森林' ) #MAPE test_mape = np.mean(np.abs((test_pred2-test_label)/ test_label)) #RMSE #test_rmse = np.sqrt(np.mean(np.square(test_pred2-test_label))) test_rmse = np.sqrt( metrics.mean_squared_error(test_label、test_pred2)) #メイ test_mae = np.mean(np.abs(test_pred2- test_label)) #R2 test_r2 = r2_score(test_label、test_pred2) プリント(' KPCA +随机森林测试集的MAPE:'、test_mape 、' RMSE:'、test_rmse、' メイ:'、test_mae、' R2:'、test_r2) #で[4] + KPCA SVR回帰 RF3 SVR =(C = 100、ガンマ= 1 ) rf3.fit(train_data、train_label.ravel()) test_pred3 = rf3.predict(TEST_DATA).reshape(-1,1 ) plt.figure() plt.plot(test_label、' - * '、ラベル= ' 真' ) plt.plot(test_pred3、' -p '、ラベル= ' preict ' ) plt.title(' KPCA + SVR ' ) plt.xlabel(" 試験試料" ) plt.ylabel(' 残りの人生/ H ' ) plt.legend() plt.show() 印刷(' KPCA + SVR ' ) #MAPE test_mape = np.mean(np.abs((test_pred3-test_label)/ test_label)) #RMSE test_rmse = np.sqrt(np.mean(np.square(test_pred3- test_label)) ) #メイ test_mae = np.mean(np.abs(test_pred3- test_label)) #R2 test_r2 = r2_score(test_label、test_pred3) プリント(' KPCA + SVR测试集的MAPE:'、test_mape、' RMSE:'、test_rmse、' メイ:'、test_mae、' R2:'、test_r2) #で[]ビデオ一緒に plt.figure() plt.plot(test_label、' - * '、ラベル= ' 真' ) plt.plot(test_pred1、' -p '、ラベル= ' ランダム森' ) plt.plot(test_pred2、' -s '、ラベル= ' KPCA +ランダム森林に対する' ) plt.plot(test_pred3、' -o '、ラベル= ' KPCA + SVR ' ) plt.title(' 様々な比較' ) plt.xlabel(" 試験試料" ) plt.ylabel(' 残りの人生/ H ' ) plt.legend() plt.show()