Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

sklearn random forest feature importance

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")
Comment

sklearn random forest feature importance

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()
Comment

sklearn random forest feature importance

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)
Comment

sklearn random forest feature importance

RandomForestClassifier(random_state=0)
Comment

sklearn random forest feature importance

print(__doc__)
import matplotlib.pyplot as plt
Comment

sklearn random forest feature importance

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)
Comment

PREVIOUS NEXT
Code Example
Python :: python tabulate print only one row 
Python :: how to prevent extbackslash in LaTeX from Python 
Python :: capturing-video-from-two-cameras-in-opencv-at-once 
Python :: convert outlook email to text file python 
Python :: python join tuple integer to string 
Python :: zbarge / s3gui 
Python :: plot with confidence intervals in ARIMA 
Python :: python for comparing url path 
Python :: how to map data to a scale python 
Python :: how to for loop length print in python 
Python :: JEW token authentication in Django UTC 
Python :: lipa na mpesa daraja python 
Python :: can paypal be hacked by email 
Python :: Insurance= contract.x_studio_social_security_basic salary of ins = 1500 result = contract.x_studio_social_security_basic_salary*100 
Python :: picture as background of seaborn plot python 
Python :: coger elementos de un string python expresiones regulares 
Python :: find index corresponding to maximum value pandas 
Python :: logartim normalization python pandas 
Python :: duplicate a list with lowercase in python 
Python :: PILImage.py", line 2975, in open fp = builtins.open(filename, "rb") PermissionError: [Errno 13] Permission denied: 
Python :: javascript parse url with values and anchors 
Python :: python use string to get object attributes 
Python :: Django Signup urls.py 
Python :: how to rename columns using panda object 
Python :: a = np.array([0, 0, 0]) and a = np.array([[0, 0, 0]]) 
Python :: Kinesis Client put_record 
Python :: specificity formula python 
Python :: tuple with only one element in Python 
Python :: how to randomize words with pyautogui 
Python :: k and M to int in pandas 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =