Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from sklearn import datasets
- from sklearn.ensemble import RandomForestClassifier
- from sklearn.model_selection import train_test_split
- from sklearn.preprocessing import StandardScaler
- import pandas
- def load_pkl():
- df = pandas.read_pickle('gender_36.pkl', 'rb')
- feat_labels = load_pkl.columns[1:]
- forest = RandomForestClassifier(n_estimators=1000, random_state=2, n_jobs=-1)
- forest.fit(X_train, y_train)
- importances = forest.feature_importances_
- indices = np.argsort(importances)[::-1]
- for f in range(X_train.shape[1]):
- print(f + 1, 30, feat_labels[f], importances[indices[f]])
- plt.title('Feature Importances')
- plt.bar(range(X_train.shape[1]), importances[indices], color='lightblue', align='center')
- plt.xticks(range(X_train.shape[1]), feat_labels[indices], rotation=90)
- plt.xlim([-1, X_train.shape[1]])
- plt.tight_layout()
- plt.show()
- runfile('C:/Users/HSIPL/Desktop/Homework 9 draft.py', wdir='C:/Users/HSIPL/Desktop')
- Reloaded modules: __mp_main__
- Traceback (most recent call last):
- File "<ipython-input-3-53490d045156>", line 1, in <module>
- runfile('C:/Users/HSIPL/Desktop/Homework 9 draft.py', wdir='C:/Users/HSIPL/Desktop')
- File "C:UsersHSIPLAnaconda3libsite-packagesspyder_kernelscustomizespydercustomize.py", line 668, in runfile
- execfile(filename, namespace)
- File "C:UsersHSIPLAnaconda3libsite-packagesspyder_kernelscustomizespydercustomize.py", line 108, in execfile
- exec(compile(f.read(), filename, 'exec'), namespace)
- File "C:/Users/HSIPL/Desktop/Homework 9 draft.py", line 11, in <module>
- feat_labels = load_pkl.columns[1:]
- AttributeError: 'function' object has no attribute 'columns'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement