import pandas as pd
df = pd.read_csv('hr_satisfaction.csv')
df.head()
from sklearn.model_selection import train_test_split
X = df.drop(['left'],axis=1).values
Y = df['left'].values
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.3)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
ranfor_clf = RandomForestClassifier()
ranfor_model = ranfor_clf.fit(X_train, Y_train)
ranfor_prediction = ranfor_clf.predict(X_test)
Accuracy = 100*accuracy_score(ranfor_prediction, Y_test)
Confusion_Matrix = confusion_matrix(ranfor_prediction, Y_test)
Classification_Report = classification_report(ranfor_prediction, Y_test)
print("Accuracy is {0:.2f}%\n".format(Accuracy))
print("Confusion Matrix:\n", Confusion_Matrix )
print("\nClassification Report:\n", Classification_Report )
import numpy as np
feature_importances = pd.DataFrame(ranfor_clf.feature_importances_,
index = pd.DataFrame(X_train).columns,
columns=['importance']).sort_values('importance',ascending=False)
feature_importances