How to get the picture from gender dataset - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to get the picture from gender dataset (/thread-17979.html) |
How to get the picture from gender dataset - vokoyo - May-01-2019 May I know how to modify my Python programming thus it will be get the same result as refer to the image file? 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') return df 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() Please see the image file - The error message is - Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] Type "copyright", "credits" or "license" for more information. IPython 6.5.0 -- An enhanced Interactive Python. C:\Users\HSIPL\Anaconda3\lib\site-packages\ipykernel\parentpoller.py:116: UserWarning: Parent poll failed. If the frontend dies, the kernel may be left running. Please let us know about your system (bitness, Python, etc.) at [email protected] [email protected]""") runfile('C:/Users/HSIPL/Desktop/Homework 9 draft.py', wdir='C:/Users/HSIPL/Desktop') C:\Users\HSIPL\Anaconda3\lib\site-packages\sklearn\ensemble\weight_boosting.py:29: DeprecationWarning: numpy.core.umath_tests is an internal NumPy module and should not be imported. It will be removed in a future NumPy release. from numpy.core.umath_tests import inner1d Traceback (most recent call last): File "<ipython-input-1-53490d045156>", line 1, in <module> runfile('C:/Users/HSIPL/Desktop/Homework 9 draft.py', wdir='C:/Users/HSIPL/Desktop') File "C:\Users\HSIPL\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile execfile(filename, namespace) File "C:\Users\HSIPL\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "C:/Users/HSIPL/Desktop/Homework 9 draft.py", line 12, in <module> feat_labels = load_pkl.columns[1:] AttributeError: 'function' object has no attribute 'columns' Please help me on this case RE: How to get the picture from gender dataset - micseydel - May-03-2019 The error seems pretty clear. You're trying to access an attribute on a function, when the function doesn't have that attribute. You probably want to call the function, and access the attribute on the return value of the function call. As for the picture - unless someone already knows the library, or they're extremely motivated and do research for you, I'm doubtful that you're going to get a satisfactory answer here. You might find more luck on a forum dedicated to machine learning. |