scikit-learn

ML

Học máy

Tổng quan scikit-learn

Scikit-learn là thư viện máy học phổ biến nhất của Python. Nó cung cấp các API đơn giản và nhất quán để phân loại, hồi quy, phân cụm, giảm kích thước, lựa chọn mô hình và tiền xử lý. Scikit-learn là điểm khởi đầu cho hầu hết mọi dự án học máy bằng Python.

PyRunhỗ trợscikit-learnnhư một phần của phân phốiPyodide, nghĩa là bạn có thể huấn luyện các trình phân loại, tính toán điểm chính xác và khám phá các thuật toán ML hoàn toàn trong trình duyệt của mình. Đó là một công cụ giáo dục mạnh mẽ — chạy trình phân loại Iris, thử nghiệm các siêu tham số và xem kết quả mà không cần sổ ghi chép trên đám mây.

Đầu ra mã & thực thi

Huấn luyện một khu rừng ngẫu nhiên trên tập dữ liệu Iris.

Scikit-learn ClassifierChạy trong Trình chỉnh sửa
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))

Gói liên quan

Tài nguyên Python được đề xuất

Mở rộng kiến thức của bạn với các hướng dẫn tương tác, bảng ghi chú và so sánh mã có liên quan.