context
894e4fae 39aa 43e2 8e08 00a71ba66883
ctx:claims/beam/894e4fae-39aa-43e2-8e08-00a71ba66883Source document
full textbeam-chunk
text/plain1 KB
doc:beam/894e4fae-39aa-43e2-8e08-00a71ba66883X = np.random.rand(11000, 10) y = np.random.randint(0, 2, size=11000) # Split data X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Define pipeline pipeline = Pipeline([ ('scaler', StandardScaler()), ('classifier', RandomForestClassifier(n_estimators=100, n_jobs=-1)) ]) # Cross-validation cv_scores = cross_val_score(pipeline, X_train, y_train, cv=5, scoring='accuracy') print(f"Cross-validation accuracy: {np.mean(cv_scores):.4f}") # Fit the pipeline pipeline.fit(X_train, y_train) # Predict and evaluate y_pred = pipeline.predict(X_test) accuracy = accuracy_score(y_test, y_pred) f1 = f1_score(y_test, y_pred) print(f"Test accuracy: {accuracy:.4f}") print(f"F1 score: {f1:.4f}") # Further optimization # Grid search for hyperparameter tuning from sklearn.model_selection import GridSearchCV param_grid = { 'classifier__n_estimators': [50, 100, 200], 'classifier__max_depth': [None, 10, 20, 30], 'classifier__min_samples_split': [2, 5, 10] } grid_search = GridSearchCV(pipeline, param_grid, cv=5, scoring='accuracy') grid_search.fit(X_train, y_train) best_params = grid_search.best_params_
Facts in this context
Grouped by subject. Each subject links to its full article.
Workflow23 factsex:workflow
| codeCompleteness | incomplete - missing imports |
| demonstratesCompleteMLPipeline | true |
| ensuresReproducibility | true |
| evaluationPhase | after hyperparameter optimization |
| evaluationStrategy | train-test split with cross-validation |
| followsMLBestPractices | true |
| includesCrossValidation | true |
| includesDataPreprocessing | true |
| includesHyperparameterOptimization | true |
| includesHyperparameterTuning | true |
| includesModelEvaluation | true |
| includesModelTraining | true |
| includesTrainTestSplit | true |
| modelSelectionMethod | cross-validation scoring |