scikit-learn
ML機器學習
概述 scikit-learn
Scikit-learn 是 Python 最受歡迎的機器學習函式庫。它為分類、迴歸、聚類、降維、模型選擇和預處理提供簡單且一致的 API。 Scikit-learn 幾乎是每個 Python 機器學習專案的起點。
PyRun支援scikit-learn作為Pyodide發行版的一部分,這表示您可以完全在瀏覽器中訓練分類器、計算準確性分數並探索 ML 演算法。它是一個強大的教育工具 - 運行 Iris 分類器,試驗超參數,並在沒有雲端筆記本的情況下查看結果。
程式碼和執行輸出
在 Iris 資料集上訓練隨機森林。
Scikit-learn Classifier在編輯器中執行
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, classification_report
iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.25, random_state=42
)
clf = RandomForestClassifier(n_estimators=50, random_state=42)
clf.fit(X_train, y_train)
preds = clf.predict(X_test)
print(f"Accuracy: {accuracy_score(y_test, preds):.2%}\n")
print("Classification Report:")
print(classification_report(y_test, preds, target_names=iris.target_names))相關套餐
推薦的 Python 資源
透過相關的互動式教學、備忘單和程式碼比較來擴展您的知識。
Python教學
Python 迴圈:For 與 While 迴圈解釋
了解如何使用 Python 循環來迭代資料。透過互動式範例掌握 for 迴圈、while 迴圈、break、continue 和迴圈最佳實務。
查看資源
操作指南
如何在 Python 中對列表進行排序(升序和降序)
了解如何在 Python 中使用 sort() 方法和sorted() 函數對清單進行排序。發現自訂鍵排序和逆序範例。
查看資源
備忘錄
Python 字串方法備忘單
Python 字串操作的完整參考指南。掌握格式化、搜尋、拆分、取代和檢查字串屬性。
查看資源
語言比較
Python 與 JavaScript:哪種程式語言最好?
Python 和 JavaScript 的全面比較。探索語法差異、效能、用例(後端與前端)和編碼範例。
查看資源