第一次使用預測流程,執行 Part3 腳本,出現下列問題? 圖的下方,有貼上完整訊息。
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) ~\anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj) 343 method = get_real_method(obj, self.print_method) 344 if method is not None: --> 345 return method() 346 return None 347 else: ~\anaconda3\lib\site-packages\pandas\io\formats\style.py in _repr_html_(self) 180 Hooks into Jupyter notebook rich display system. 181 """ --> 182 return self.render() 183 184 @Appender( ~\anaconda3\lib\site-packages\pandas\io\formats\style.py in render(self, **kwargs) 535 * table_attributes 536 """ --> 537 self._compute() 538 # TODO: namespace all the pandas keys 539 d = self._translate() ~\anaconda3\lib\site-packages\pandas\io\formats\style.py in _compute(self) 610 r = self 611 for func, args, kwargs in self._todo: --> 612 r = func(self)(*args, **kwargs) 613 return r 614 ~\anaconda3\lib\site-packages\pandas\io\formats\style.py in _applymap(self, func, subset, **kwargs) 702 subset = pd.IndexSlice[:] 703 subset = _non_reducing_slice(subset) --> 704 result = self.data.loc[subset].applymap(func) 705 self._update_ctx(result) 706 return self ~\anaconda3\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key) 1759 except (KeyError, IndexError, AttributeError): 1760 pass -> 1761 return self._getitem_tuple(key) 1762 else: 1763 # we by definition only have the 0th axis ~\anaconda3\lib\site-packages\pandas\core\indexing.py in _getitem_tuple(self, tup) 1286 continue 1287 -> 1288 retval = getattr(retval, self.name)._getitem_axis(key, axis=i) 1289 1290 return retval ~\anaconda3\lib\site-packages\pandas\core\indexing.py in _getitem_axis(self, key, axis) 1951 raise ValueError("Cannot index with multidimensional key") 1952 -> 1953 return self._getitem_iterable(key, axis=axis) 1954 1955 # nested tuple slicing ~\anaconda3\lib\site-packages\pandas\core\indexing.py in _getitem_iterable(self, key, axis) 1592 else: 1593 # A collection of keys -> 1594 keyarr, indexer = self._get_listlike_indexer(key, axis, raise_missing=False) 1595 return self.obj._reindex_with_indexers( 1596 {axis: [keyarr, indexer]}, copy=True, allow_dups=True ~\anaconda3\lib\site-packages\pandas\core\indexing.py in _get_listlike_indexer(self, key, axis, raise_missing) 1550 1551 self._validate_read_indexer( -> 1552 keyarr, indexer, o._get_axis_number(axis), raise_missing=raise_missing 1553 ) 1554 return keyarr, indexer ~\anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_read_indexer(self, key, indexer, axis, raise_missing) 1652 if not (ax.is_categorical() or ax.is_interval()): 1653 raise KeyError( -> 1654 "Passing list-likes to .loc or [] with any missing labels " 1655 "is no longer supported, see " 1656 "https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike" # noqa:E501 KeyError: 'Passing list-likes to .loc or [] with any missing labels is no longer supported, see https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike'
<pandas.io.formats.style.Styler at 0x21907df5948>
資產總計 : 1,150,432
6224 歸因分析圖
--------------------------------------------------------------------------- UnicodeDecodeError Traceback (most recent call last) <ipython-input-6-e48eedced9e4> in <module> 7 model_2d60 = cs.load_model(data_2d, model_file='2d_60D_model') 8 model_60 = cs.blending_model([model_1d60, model_2d60], [0.7]) ----> 9 cs.predict_result(trading_params=TRADING_PARAMS, model_d1=model_1, model_d60=model_60) C:\porson\AI_EX\CH4\cstock.py in predict_result(trading_params, model_d1, model_d60) 1436 max_index = model_60[1].index(max(model_60[1])) 1437 plot_model_60 = model_60[0][max_index] -> 1438 shap_plot(plot_model_60, shap_item) 1439 else: # 單一模型 1440 shap_plot(model_60, shap_item) C:\porson\AI_EX\CH4\cstock.py in shap_plot(model, shap_item) 1208 submodel = model[2] 1209 if model[1]==0: -> 1210 explainer = shap.TreeExplainer(submodel) 1211 shap_values = explainer.shap_values(data) 1212 shap.initjs() ~\anaconda3\lib\site-packages\shap\explainers\tree.py in __init__(self, model, data, model_output, feature_perturbation, **deprecated_options) 119 self.feature_perturbation = feature_perturbation 120 self.expected_value = None --> 121 self.model = TreeEnsemble(model, self.data, self.data_missing, model_output) 122 self.model_output = model_output 123 #self.model_output = self.model.model_output # this allows the TreeEnsemble to translate model outputs types by how it loads the model ~\anaconda3\lib\site-packages\shap\explainers\tree.py in __init__(self, model, data, data_missing, model_output) 755 self.original_model = model.get_booster() 756 self.model_type = "xgboost" --> 757 xgb_loader = XGBTreeModelLoader(self.original_model) 758 self.trees = xgb_loader.get_trees(data=data, data_missing=data_missing) 759 self.base_offset = xgb_loader.base_score ~\anaconda3\lib\site-packages\shap\explainers\tree.py in __init__(self, xgb_model) 1324 self.read_arr('i', 29) # reserved 1325 self.name_obj_len = self.read('Q') -> 1326 self.name_obj = self.read_str(self.name_obj_len) 1327 self.name_gbm_len = self.read('Q') 1328 self.name_gbm = self.read_str(self.name_gbm_len) ~\anaconda3\lib\site-packages\shap\explainers\tree.py in read_str(self, size) 1454 1455 def read_str(self, size): -> 1456 val = self.buf[self.pos:self.pos+size].decode('utf-8') 1457 self.pos += size 1458 return val UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 198: invalid continuation byte
回答列表
-
2020/07/24 上午 10:59陳明佑 (Ming You Chen)贊同數:2不贊同數:0留言數:1
同學您好
這個狀況分為兩個問題
前半部的問題, 是無法顯示彩色表格格式,
可以先使用昨天的更新版程式, 替換掉其中的 cstock.py, 就能先看到正常的無上色版
後半部的問題, 同樣是因為新版XGB無法使用舊版資訊不相容的問題
昨天的更新版程式也有修正這點, 請您再試試看
-
2020/07/25 上午 09:57徐偉峻贊同數:3不贊同數:0留言數:0
我下載了7/24 v1.03 版執行還是有遇到一樣的問題
KeyError: 'Passing list-likes to .loc or [] with any missing labels is no longer supported
AttributeError: 'list' object has no attribute 'save_raw'