Neural Sync Active
Machine Learning with Scikit-Learn
Registry Synced
Machine Learning with Scikit-Learn
103 words
1 min read
Machine Learning with Scikit-Learn
pythonfrom sklearn.datasets import load_iris from sklearn.model_selection import train_test_split, GridSearchCV from sklearn.preprocessing import StandardScaler from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import classification_report # Load data 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.2, random_state=42 ) # Preprocess scaler = StandardScaler() X_train = scaler.fit_transform(X_train) X_test = scaler.transform(X_test) # Model model = RandomForestClassifier(n_estimators=100) model.fit(X_train, y_train) # Evaluate y_pred = model.predict(X_test) print(classification_report(y_test, y_pred)) # Hyperparameter tuning param_grid = {'n_estimators': [50, 100, 200], 'max_depth': [3, 5, None]} grid = GridSearchCV(RandomForestClassifier(), param_grid, cv=5) grid.fit(X_train, y_train) print(f"Best params: {grid.best_params_}")