Python 中jupyternotebook中%%time使用报错


  • 错误提示
UsageError: Line magic function `%%time` not found.
  • 解决方法
    • %%time放在代码块的顶行顶格。
  • 出错代码
#n_jobs =3,表示只使用3个内核进行计算
%%time 
bagging_clf1 = BaggingClassifier(DecisionTreeClassifier(random_state=666),
                                n_estimators=500,
                                max_samples = 100, 
                                random_state=42,
                                bootstrap = True,
                                oob_score=True,
                                n_jobs = 1)

#在训练的时候传入所有数据
bagging_clf1.fit(X, y)
  • 解决方法
    • %%time需要放在代码块的顶行顶格
  • 修改后的代码==>执行没问题
%%time 
#n_jobs =3,表示只使用3个内核进行计算
bagging_clf1 = BaggingClassifier(DecisionTreeClassifier(random_state=666),
                                n_estimators=500,
                                max_samples = 100, 
                                random_state=42,
                                bootstrap = True,
                                oob_score=True,
                                n_jobs = 1)

#在训练的时候传入所有数据
bagging_clf1.fit(X, y)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM