You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Scikit-learn 1.2.0在VS Code中代码分析及运行极慢问题求助

关于scikit-learn metrics模块导致Pylance语言服务器卡顿的问题

已排查排除以下因素:

  • 扩展干扰(仅保留Pylance和Python官方扩展)
  • Python版本差异(测试了3.10.7与3.10.9)
  • VS Code及相关扩展版本问题
  • 运行环境差异(Linux及其他设备)

最终发现仅在使用scikit-learn时出现异常:输入metrics.触发代码补全时,Pylance语言服务器需要约6秒才能完成检查分析,metrics模块加载耗时过长,严重影响开发体验。

测试代码如下:

from sklearn import metrics
import matplotlib.pyplot as plt

y_true = ["cat", "ant", "cat", "cat", "ant", "bird"]
y_pred = ["ant", "ant", "cat", "cat", "ant", "cat"]


conf_matrix = metrics.confusion_matrix(y_true, y_pred, labels=["ant", "bird", "cat"])

conf_display = metrics.ConfusionMatrixDisplay(conf_matrix, display_labels=["ant", "bird", "cat"])

accuracy = metrics.accuracy_score(y_true, y_pred, normalize=True)

print(accuracy)

conf_display.plot()

plt.show()

想咨询:是否因为scikit-learn模块结构复杂,导致语言服务器读取源码耗时过久?

内容的提问来源于stack exchange,提问作者HeuristicPointer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 09:40:29