自作データセットを用いて機械学習モデルを使いとりあえず動かしてみようと思いLightGBM手法を使い実行してみたところ下記のエラーが出てきました。
Traceback (most recent call last): File "face3.py", line 87, in <module> reg.fit(X_train, y_train) File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\sklearn\multioutput.py", line 182, in fit for i in range(y.shape[1])) File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\joblib\parallel.py", line 1041, in __call__ if self.dispatch_one_batch(iterator): File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\joblib\parallel.py", line 859, in dispatch_one_batch self._dispatch(tasks) File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\joblib\parallel.py", line 777, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\joblib\_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\joblib\_parallel_backends.py", line 572, in __init__ self.results = batch() File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\joblib\parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\joblib\parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\sklearn\utils\fixes.py", line 222, in __call__ return self.function(*args, **kwargs) File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\sklearn\multioutput.py", line 41, in _fit_estimator estimator.fit(X, y, **fit_params) File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\lightgbm\sklearn.py", line 822, in fit categorical_feature=categorical_feature, callbacks=callbacks, init_model=init_model) File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\lightgbm\sklearn.py", line 688, in fit callbacks=callbacks, init_model=init_model) File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\lightgbm\engine.py", line 228, in train booster = Booster(params=params, train_set=train_set) File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\lightgbm\basic.py", line 2229, in __init__ train_set.construct() File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\lightgbm\basic.py", line 1472, in construct categorical_feature=self.categorical_feature, params=self.params) File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\lightgbm\basic.py", line 1270, in _lazy_init self.__init_from_np2d(data, params_str, ref_dataset) File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\lightgbm\basic.py", line 1320, in __init_from_np2d ctypes.byref(self.handle))) File "C:\Users\shota\anaconda3\envs\env2\lib\site-packages\lightgbm\basic.py", line 110, in _safe_call raise LightGBMError(_LIB.LGBM_GetLastError().decode('utf-8')) lightgbm.basic.LightGBMError: Unknown boosting type {'gender':
途中までの出力
[LightGBM] [Warning] Unknown parameter: 2.864}},{'gender': [LightGBM] [Warning] Unknown parameter: 99.415, [LightGBM] [Warning] Unknown parameter: 0.354}},{'gender': [LightGBM] [Warning] Unknown parameter: 90.221, [LightGBM] [Warning] Unknown parameter: 97.022,
実行したコード
import pandas as pd import json import codecs import numpy as np from sklearn import svm, metrics, model_selection from sklearn.model_selection import train_test_split from sklearn.neighbors import KNeighborsClassifier knn = KNeighborsClassifier(n_neighbors=1) df = pd.read_csv('emotion.csv') with open("Emotion.json") as f: data = json.load(f) res1 = [] for d in data: res1.append(d['gender']) res2 = [] for e in data: res2.append(d['age']) res3 = [] for f in data: res3.append(d['emotion']) #print(res1) #print(res2) #print(res3) #df = data[0] #DF = df["emotion"].keys() #print(DF) #print(df) #print(type(df)) print("データセットのキー(特徴量名)の確認==>:\n", df.keys()) print('dataframeの行数・列数の確認==>\n', df.shape) # dataframe各列の欠損値でないデータ数、データ型を確認 df.info() # 数値ではない型の要素の抽出 #objectlist = df[['特徴量名を入れる']][df['特徴量名を入れる'].apply(lambda s:pd.to_numeric(s, errors='coerce')).isnull()] #objectlist import sklearn facemotion = sklearn.utils.Bunch() # 'Score'(幸福スコア)を目的変数'target'とする facemotion['target'] = df[['anger', 'disgust', 'fear', 'happiness', 'neutral', 'sadness', 'surprise']] # 説明変数を'data'に入れる facemotion['data'] = df.loc[:, ['anger', 'disgust', 'fear', 'happiness', 'neutral', 'sadness', 'surprise']] # 特徴量の名前も入れておくと、グラフの凡例等に使えます(無くても可) #facemotion['feature_names'] = ['anger', 'disgust', 'fear', 'happiness', 'neutral', 'sadness', 'surprise'] # 訓練セットとテストセットに分割 from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split( facemotion['data'], facemotion['target'], random_state=0) #X_train, X_test, y_train, y_test = \ #model_selection.train_test_split(facemotion['data'], facemotion['target'], random_state=0) print("X_train shape:", X_train.shape) print("X_test shape:", X_test.shape) from sklearn.multioutput import MultiOutputRegressor import lightgbm as lgb reg = MultiOutputRegressor(lgb.LGBMRegressor(data, n_estimators=500)) reg.fit(X_train, y_train) """ # データを学習し、予測 clf = svm.SVC() clf.fit(X_train, y_train) pre = clf.predict(X_test) # 正解率を求める ac_score = metrics.accuracy_score(y_test, pre) print("正解率 =", ac_score) # 未知のデータを予測 newdata = np.array([[5.8,2.6,4.0,1.2]]) print("newdata.shape: {}".format(newdata.shape)) knn.fit(X_train, y_train) prediction = knn.predict(newdata) print("Predicted target name: {}".format(prediction)) """
エラー内容を検索してみても回答が得られず、ここに投稿させていただきました。
何か解決方法があれば教えていただきたいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。