“Sklearn Random Florest Feature Importocor” Respostas de código

Sklearn Random Florest Feature Importocor

import time
import numpy as np

start_time = time.time()
importances = forest.feature_importances_
std = np.std([
    tree.feature_importances_ for tree in forest.estimators_], axis=0)
elapsed_time = time.time() - start_time

print(f"Elapsed time to compute the importances: "
      f"{elapsed_time:.3f} seconds")
Gentle Gaur

Sklearn Random Florest Feature Importocor

import pandas as pd
forest_importances = pd.Series(importances, index=feature_names)

fig, ax = plt.subplots()
forest_importances.plot.bar(yerr=std, ax=ax)
ax.set_title("Feature importances using MDI")
ax.set_ylabel("Mean decrease in impurity")
fig.tight_layout()
Gentle Gaur

Sklearn Random Florest Feature Importocor

from sklearn.ensemble import RandomForestClassifier

feature_names = [f'feature {i}' for i in range(X.shape[1])]
forest = RandomForestClassifier(random_state=0)
forest.fit(X_train, y_train)
Gentle Gaur

Sklearn Random Florest Feature Importocor

RandomForestClassifier(random_state=0)
Gentle Gaur

Sklearn Random Florest Feature Importocor

from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split

X, y = make_classification(
    n_samples=1000, n_features=10, n_informative=3, n_redundant=0,
    n_repeated=0, n_classes=2, random_state=0, shuffle=False)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, stratify=y, random_state=42)
Gentle Gaur

Sklearn Random Florest Feature Importocor

print(__doc__)
import matplotlib.pyplot as plt
Gentle Gaur

Respostas semelhantes a “Sklearn Random Florest Feature Importocor”

Perguntas semelhantes a “Sklearn Random Florest Feature Importocor”

Mais respostas relacionadas para “Sklearn Random Florest Feature Importocor” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código