Loading…
DS · Classification · Program 19 · In the record
Random Forest classification.
1from sklearn.datasets import load_wine2from sklearn.model_selection import train_test_split3from sklearn.ensemble import RandomForestClassifier4from sklearn.metrics import accuracy_score5 6X, y = load_wine(return_X_y=True)7X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)8 9rf = RandomForestClassifier(n_estimators=100, random_state=42).fit(X_train, y_train)10print("Random Forest Accuracy:", accuracy_score(y_test, rf.predict(X_test)))Random Forest Accuracy: 1.0

Run program 19 in your browser
Python 3.14 · Pyodide. Change the code or the input, run it, break it, and see what happens.