SHARE
TWEET

Untitled

a guest Jun 24th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from sklearn import datasets
  4. from sklearn.ensemble import RandomForestClassifier
  5. from sklearn.model_selection import train_test_split
  6. from sklearn.preprocessing import StandardScaler
  7. import pandas
  8. def load_pkl():
  9.     df = pandas.read_pickle('gender_36.pkl', 'rb')
  10. feat_labels = load_pkl.columns[1:]
  11. forest = RandomForestClassifier(n_estimators=1000, random_state=2, n_jobs=-1)
  12. forest.fit(X_train, y_train)
  13. importances = forest.feature_importances_
  14. indices = np.argsort(importances)[::-1]
  15. for f in range(X_train.shape[1]):
  16.     print(f + 1, 30, feat_labels[f], importances[indices[f]])
  17. plt.title('Feature Importances')
  18. plt.bar(range(X_train.shape[1]), importances[indices], color='lightblue', align='center')
  19. plt.xticks(range(X_train.shape[1]), feat_labels[indices], rotation=90)
  20. plt.xlim([-1, X_train.shape[1]])
  21. plt.tight_layout()
  22. plt.show()
  23.      
  24. runfile('C:/Users/HSIPL/Desktop/Homework 9 draft.py', wdir='C:/Users/HSIPL/Desktop')
  25. Reloaded modules: __mp_main__
  26. Traceback (most recent call last):
  27.  
  28.   File "<ipython-input-3-53490d045156>", line 1, in <module>
  29.     runfile('C:/Users/HSIPL/Desktop/Homework 9 draft.py', wdir='C:/Users/HSIPL/Desktop')
  30.  
  31.   File "C:UsersHSIPLAnaconda3libsite-packagesspyder_kernelscustomizespydercustomize.py", line 668, in runfile
  32.     execfile(filename, namespace)
  33.  
  34.   File "C:UsersHSIPLAnaconda3libsite-packagesspyder_kernelscustomizespydercustomize.py", line 108, in execfile
  35.     exec(compile(f.read(), filename, 'exec'), namespace)
  36.  
  37.   File "C:/Users/HSIPL/Desktop/Homework 9 draft.py", line 11, in <module>
  38.     feat_labels = load_pkl.columns[1:]
  39.  
  40. AttributeError: 'function' object has no attribute 'columns'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top