Python Forum
How to get the picture from gender dataset
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get the picture from gender dataset
#1


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 -



[Image: r0YeY.jpg]





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







Attached Files

Thumbnail(s)
   

.pdf   Assessing Feature with Random Forests.pdf (Size: 163.92 KB / Downloads: 271)
.py   My Python.py (Size: 933 bytes / Downloads: 284)
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  openpyxl insert picture problem cools0607 2 1,399 May-03-2023, 06:48 AM
Last Post: cools0607
  How to increase the size of a png picture for the heatmap of the correlation? lulu43366 9 3,387 Oct-06-2021, 04:15 PM
Last Post: deanhystad
  Picture changing triggered by GPIO q_nerk 2 2,520 Dec-14-2020, 03:32 PM
Last Post: DeaD_EyE
  How to scrolling Picture in x axis kalihotname 1 2,208 Jun-16-2020, 12:18 PM
Last Post: DeaD_EyE
  cropping a picture (always square) Leon 1 2,104 Aug-13-2018, 10:04 AM
Last Post: Leon
  Why A will be printed twice in the picture Shen 3 4,031 Jul-25-2018, 01:16 PM
Last Post: stranac
  need to alter static picture to video file mika 1 2,711 Feb-23-2018, 02:11 PM
Last Post: ka06059

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020