前回の質問のかいもあってコードを実行することができ、実際に実行したのですがaccuracyやf1等のscoreがすべて同じ値になりました。これはどういう状況でしょうか。それとも現在組んでいるコードでは足りない箇所があるのでしょうか。
分かる方がいらしたら教えてください。
実際のコードが以下です
# -*- coding: utf-8 -*- import scipy as sp import pandas as pd from pandas import Series, DataFrame import matplotlib.pyplot as plt from sklearn.preprocessing import StandardScaler from sklearn.ensemble import RandomForestClassifier #RandomForest from sklearn.svm import SVC # SVM用 import lightgbm as lgb from sklearn.metrics import confusion_matrix #混同行列 from sklearn.metrics import accuracy_score, precision_score #適合率 from sklearn.metrics import recall_score, f1_score #再現率,F1スコア from sklearn.metrics import make_scorer def SVM(X_train_std, X_test_std, Y_train, Y_test): model_SVM = SVC(kernel = "rbf", C = 763.8 , gamma = 0.0197 ) #学習モデル構築。引数に訓練データの特徴量と、それに対応したラベル model_SVM.fit(X_train_std,Y_train) #予測したクラスラベル Y_pred = model_SVM.predict(X_test_std) #print(Y_pred.shape) #print(Y_pred) #print(Y_test.shape) #print(Y_test) # .scoreで正解率を算出。 print("\nSVM") print("train score:",model_SVM.score(X_train_std,Y_train)) print("test score:",model_SVM.score(X_test_std,Y_test)) Y_test=Y_test.values print("accuracy score:",accuracy_score(Y_test, Y_pred)) print("precision score:",precision_score(Y_test, Y_pred,average='micro')) print("recall score:",recall_score(Y_test, Y_pred,average='micro')) print("f1 score:",f1_score(Y_test, Y_pred,average='micro')) def GBM(X_train, X_test, Y_train, Y_test): model_GBM = lgb.LGBMClassifier(boosting_type='gbdt', num_leaves=58, max_depth=14, learning_rate=0.1, n_estimators=940, min_child_samples=40, importance_type="split", random_state=0) #学習モデル構築。引数に訓練データの特徴量と、それに対応したラベル model_GBM.fit(X_train, Y_train) #予測したクラスラベル Y_pred = model_GBM.predict(X_test) # .scoreで正解率を算出。 print("\nGBM") print("train score:",model_GBM.score(X_train,Y_train)) print("test score:",model_GBM.score(X_test,Y_test)) Y_test=Y_test.values print("accuracy score:",accuracy_score(Y_test, Y_pred)) print("precision score:",precision_score(Y_test, Y_pred,average='micro')) print("recall score:",recall_score(Y_test, Y_pred,average='micro')) print("f1 score:",f1_score(Y_test, Y_pred,average='micro')) def main(): """ TODO case_nameに任意の名前を指定 フォルダを統一するために以降のscriptも名前を統一する """ case_name = "case3" # --------------------------------------- case_dir = "./casestudy/{}/".format(case_name) input_csv_name = "2_extracted_features_original.csv" input_csv_path = case_dir + input_csv_name input_df = pd.read_csv(input_csv_path, encoding="utf-8-sig") #すべてのデータを対象に分類を行う場合 #----------------------------------------------------------------------- task = "all" train_df = input_df[input_df["train_test_flag"] == 0] test_df = input_df[input_df["train_test_flag"] == 1] # print(train_df) # print(test_df) X_train = train_df.loc[:, "contrast":"inverse_difference_m_norm"] X_test = test_df.loc[:, "contrast":"inverse_difference_m_norm"] # print(X_train) # print(X_test) Y_train = train_df["category"] Y_test = test_df["category"] # print(Y_train) sc = StandardScaler() sc.fit(X_train) X_train_std = sc.transform(X_train) X_test_std = sc.transform(X_test) # print(X_train_std) # print(X_test_std) # #------------------------------------------------------------------------ SVM(X_train_std, X_test_std, Y_train, Y_test) GBM(X_train, X_test, Y_train, Y_test) if __name__ == "__main__": main()
実際に出た結果がこちらです。
SVM train score: 0.8728841145833334 test score: 0.771484375 accuracy score: 0.771484375 precision score: 0.771484375 recall score: 0.771484375 f1 score: 0.771484375 GBM train score: 1.0 test score: 0.7096354166666666 accuracy score: 0.7096354166666666 precision score: 0.7096354166666666 recall score: 0.7096354166666666 f1 score: 0.7096354166666666
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。