前提・実現したいこと
TypeErrorを直したい!
また,解決法を教えてほしい.
発生している問題・エラーメッセージ
TypeError Traceback (most recent call last) <ipython-input-61-312f5a8ebc80> in <module> 55 } 56 # 上記のパラメータでモデルを学習する ---> 57 model = lgb.train(lgbm_params, lgb_train, valid_sets=lgb_eval) 58 59 # テストデータを予測する C:\ProgramData\Anaconda3\lib\site-packages\lightgbm\engine.py in train(params, train_set, num_boost_round, valid_sets, valid_names, fobj, feval, init_model, feature_name, categorical_feature, early_stopping_rounds, evals_result, verbose_eval, learning_rates, keep_training_booster, callbacks) 160 if not isinstance(valid_data, Dataset): 161 raise TypeError("Traninig only accepts Dataset object") --> 162 reduced_valid_sets.append(valid_data._update_params(params).set_reference(train_set)) 163 if valid_names is not None and len(valid_names) > i: 164 name_valid_sets.append(valid_names[i]) C:\ProgramData\Anaconda3\lib\site-packages\lightgbm\basic.py in set_reference(self, reference) 1246 ._set_predictor(reference._predictor) 1247 # we're done if self and reference share a common upstrem reference -> 1248 if self.get_ref_chain().intersection(reference.get_ref_chain()): 1249 return self 1250 if self.data is not None: C:\ProgramData\Anaconda3\lib\site-packages\lightgbm\basic.py in get_ref_chain(self, ref_limit) 1487 if isinstance(head, Dataset): 1488 ref_chain.add(head) -> 1489 if (head.reference is not None) and (head.reference not in ref_chain): 1490 head = head.reference 1491 else: TypeError: unhashable type: 'numpy.ndarray'
該当のソースコード
%matplotlib inline import matplotlib.pyplot as plt import pandas as pd import numpy as np import lightgbm as lgb from pandas import DataFrame, Series from sklearn.datasets import make_blobs from matplotlib.font_manager import FontProperties fp = FontProperties(fname=r'c:\windows\Fonts\meiryo.ttc', size=14) from sklearn.svm import SVC from sklearn.metrics import r2_score from sklearn.metrics import mean_squared_error from sklearn.ensemble import RandomForestRegressor import mglearn data_1 = pd.read_csv("seiri.csv", header = None, encoding="UTF8") pre_ent = np.array(data_1.iloc[0:6415,0]) pre_exi = np.array(data_1.iloc[0:6415,1]) flow_rate = np.array(data_1.iloc[0:6415,2]) pre_diff = pre_ent - pre_exi Pre_Diff = pre_diff.reshape(1,-1) Flow_Rate = flow_rate.reshape(1,-1) Pre_Diff = pre_diff.reshape(1,-1) Flow_Rate = flow_rate.reshape(1,-1) X_train, X_test, Y_train, Y_test = train_test_split(Pre_Diff, Flow_Rate,train_size = 0.7) x_train = np.linspace(0, 450, 100) X_train = x_train.reshape(1,-1) y_train = np.linspace(0, 4500, 50) Y_train = x_train.reshape(1,-1) z_train = np.cos(X_train)+(10**(-1))*(np.sin(-1)*(Y_train))-(X_train)/1.5--(Y_train)/15+550 lgb_train = lgb.Dataset(X_train, Y_train, z_train) Z_test= np.linspace(550,0,100) z_test = Z_test.reshape(1,-1) lgb_eval = lgb.Dataset(X_test, Y_test, z_test) # LightGBM のハイパーパラメータ lgbm_params = { # 回帰問題 'objective': 'regression', 'metric': 'r2_score', } # 上記のパラメータでモデルを学習する model = lgb.train(lgbm_params, lgb_train, valid_sets=lgb_eval) # テストデータを予測する z_pred = model.predict(X_test, Y_test, num_iteration=model.best_iteration)
試したこと
list配列に変えるなどした.
補足情報(FW/ツールのバージョンなど)
jupyter notebookで書いてます.
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。