解决以下报错:--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[40], line 387 380 save_intoCSV(Results, './Results_MSE.csv') 386 if __name__ == '__main__': --> 387 main() Cell In[40], line 334, in main() 331 test_MSE = test_total_MSE / (test_count * 1.0) 333 print("Evaluating...") --> 334 evaluate_forecast(y_true,y_pred) 336 # Update results or break? 337 if (test_MSE < test_best_MSE): Cell In[40], line 35, in evaluate_forecast(y_true, y_pred) 31 def evaluate_forecast(y_true, y_pred): 32 #rmse = mean_squared_error(y_true, y_pred, squared=False) 33 #mae = mean_absolute_error(y_true, y_pred) 34 #mape = np.mean(np.abs((y_true - y_pred) / y_true)) * 100 ---> 35 rse=np.sqrt(np.sum(np.square(y_true - y_pred))) / np.sqrt(np.sum(np.square(y_true - np.mean(y_true)))) 36 rae=np.sum(np.abs(y_true - y_pred)) / np.sum(np.abs(y_true - np.mean(y_true))) 37 # 将输入数据转换为numpy数组 TypeError: unsupported operand type(s) for -: 'list' and 'list'
这个报错是因为在 evaluate_forecast 函数中,y_true 和 y_pred 是列表类型,而 np.square 和 np.sum 函数只能作用于 numpy 数组。因此,需要将 y_true 和 y_pred 转换为 numpy 数组。
可以使用以下代码将列表转换为 numpy 数组:
import numpy as np
y_true = np.array(y_true)
y_pred = np.array(y_pred)
将此代码添加到 evaluate_forecast 函数的开始部分,即可解决该报错。
npm run dev报错node: --openssl-legacy-provider is not allowed in NODE_OPTIONS
当你在运行npm run dev
命令时,出现了node: --openssl-legacy-provider is not allowed in NODE_OPTIONS
的报错信息。这个错误是由于在你的环境变量中设置了NODE_OPTIONS
,并且其中包含了--openssl-legacy-provider
选项,但是该选项在当前的Node.js版本中已经被禁用了。
解决这个问题的方法是更新你的Node.js版本或者修改NODE_OPTIONS
环境变量中的选项。你可以尝试以下几种方法来解决这个问题:
更新Node.js版本:升级到最新的稳定版本可以解决该问题。你可以访问Node.js官方网站(https://nodejs.org/)下载最新版本的Node.js,并安装它。
修改
NODE_OPTIONS
环境变量:如果你不想升级Node.js版本,你可以尝试修改NODE_OPTIONS
环境变量中的选项。你可以通过以下步骤来修改:- 在命令行中运行
echo %NODE_OPTIONS%
(Windows)或者echo $NODE_OPTIONS
(Mac/Linux)来查看当前的NODE_OPTIONS
值。 - 如果其中包含了
--openssl-legacy-provider
选项,你可以尝试删除它或者将其替换为其他合适的选项。 - 保存修改后的环境变量,并重新运行
npm run dev
命令。
- 在命令行中运行
希望以上方法能够帮助你解决问题!如果你还有其他问题,请继续提问。
安装hanlp报错: subprocess-exited-with-error
安装HanLP时出现subprocess-exited-with-error错误通常是由于缺少setuptools或setuptools_rust模块导致的。您可以尝试以下解决方案:
- 确保您已经安装了Microsoft Visual C++ 14.0或更高版本,如果没有,请前往https://visualstudio.microsoft.com/visual-cpp-build-tools/下载并安装。
- 运行命令pip install setuptools和pip install setuptools_rust,安装缺少的模块。
- 如果以上方法无效,您可以尝试使用conda安装HanLP,命令为conda install -c conda-forge pyhanlp。 如果您仍然遇到问题,请提供更详细的错误信息以便我们更好地帮助您解决问题。
相关推荐
















