良辰2635 2024-04-18 14:14 采纳率: 100%
浏览 19
已结题

使用Jupyter book学习出现控件无法显示的问题

学习吴恩达机器学习实验课程 C1_W1_Lab04_Cost_function_Soln中,执行到
plt_intuition(x_train,y_train)语句时,正常应该有滑块控件,但是执行后没有滑块,只有提示如下

img


点击后有以下提示:

[Open Browser Console for more detailed log - Double click to close this message]
https://img-mid.csdnimg.cn/release/static/image/mid/ask/2e1ed310e0054479b77fe25090a26a58.png "#left")
Failed to load model class 'VBoxModel' from module '@jupyter-widgets/controls'
Error: Module @jupyter-widgets/controls, version ^1.5.0 is not registered, however,         2.0.0 is
    at f.loadClass (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.a63a8d293fb35a52dc25.js?v=a63a8d293fb35a52dc25:1:75057)
    at f.loadModelClass (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/336.ebc7a55ea1768712771f.js?v=ebc7a55ea1768712771f:1:10729)
    at f._make_model (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/336.ebc7a55ea1768712771f.js?v=ebc7a55ea1768712771f:1:7517)
    at f.new_model (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/336.ebc7a55ea1768712771f.js?v=ebc7a55ea1768712771f:1:5137)
    at f.handle_comm_open (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/336.ebc7a55ea1768712771f.js?v=ebc7a55ea1768712771f:1:3894)
    at _handleCommOpen (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.a63a8d293fb35a52dc25.js?v=a63a8d293fb35a52dc25:1:73473)
    at v._handleCommOpen (http://localhost:8888/static/notebook/3676.bundle.js:1:30808)
    at async v._handleMessage (http://localhost:8888/static/notebook/3676.bundle.js:1:32702)

该语句之前的代码使用的是课件内容,具体如下:
该语句之前的代码使用的是课件内容,具体如下:

import numpy as np
%matplotlib widget
import matplotlib.pyplot as plt
from lab_utils_uni import plt_intuition, plt_stationary, plt_update_onclick, soup_bowl
plt.style.use('./deeplearning.mplstyle')

x_train = np.array([1.0, 2.0])           #(size in 1000 square feet)
y_train = np.array([300.0, 500.0])           #(price in 1000s of dollars)

def compute_cost(x, y, w, b): 
    """
    Computes the cost function for linear regression.
    
    Args:
      x (ndarray (m,)): Data, m examples 
      y (ndarray (m,)): target values
      w,b (scalar)    : model parameters  
    
    Returns
        total_cost (float): The cost of using w,b as the parameters for linear regression
               to fit the data points in x and y
    """
    # number of training examples
    m = x.shape[0] 
    
    cost_sum = 0 
    for i in range(m): 
        f_wb = w * x[i] + b   
        cost = (f_wb - y[i]) ** 2  
        cost_sum = cost_sum + cost  
    total_cost = (1 / (2 * m)) * cost_sum  

    return total_cost
  • 写回答

3条回答 默认 最新

  • 专家-赤兔[在线] 全栈领域优质创作者 2024-04-18 14:14
    关注

    引自免费微信小程序:皆我百晓生

    看起来你在尝试运行一个基于 Jupyter Notebook 的机器学习教程中的代码,但遇到了一些与 JupyterLab 控件加载相关的问题。根据错误信息,似乎有一个版本不匹配的问题:模块 @jupyter-widgets/controls 的预期版本是 ^1.5.0,但实际安装的版本是 2.0.0

    要解决这个问题,你需要确保你的 JupyterLab 环境中的所有依赖项版本都正确且兼容。这里是一个可能的步骤列表来修复这个问题:

    1. 首先,你需要确认你的 JupyterLab 和其扩展是否是最新的。在命令行中运行以下命令更新它们(如果你使用 conda):

      conda update jupyterlab jupyterlab_widgets
      
    2. 如果你使用的是 pip,则可以尝试:

      pip install --upgrade jupyterlab jupyterlab-widgets
      
    3. 如果上述步骤无法解决问题,那么你可能需要检查特定的 @jupyter-widgets/controls 版本。可以使用以下命令卸载当前版本并安装预期版本(这里是 1.5.0):

      pip uninstall jupyterlab_widgets
      pip install jupyterlab_widgets==1.5.0
      
    4. 卸载和重新安装后,重启 JupyterLab 服务,确保更改生效。

      jupyter labextension rebuild
      jupyter lab
      
    5. 如果问题仍然存在,可能是由于其他库或依赖项之间的冲突。在这种情况下,你可能需要创建一个新的 Python 环境,并在这个新环境中按照教程安装所需的库。这样可以避免已安装软件包的干扰。以下是创建新环境并安装所需库的示例(使用 conda):

      conda create -n my_ml_env python=3.8
      conda activate my_ml_env
      conda install numpy matplotlib ipywidgets jupyterlab jupyterlab_widgets
      
    6. 在新环境下运行你的代码。首先激活新环境(对于 conda,使用 conda activate my_ml_env),然后打开 JupyterLab 并导入相应的库以及运行你的代码。

    完成这些步骤后,你应该能成功加载控件并看到预期的图表。如果你仍然遇到问题,或者需要进一步的帮助,你可以提供更详细的日志或者反馈,我会尽力协助你。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 4月26日
  • 已采纳回答 4月18日
  • 创建了问题 4月18日

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题