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