May I know how to modify my Python programming thus it will be get the same result as refer to the image file?
import pandas
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
def load_pkl(gender_36):
with open('gender_36.pkl', 'rb') as file:
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("%2d) %-*s %f" % (f + 1, 30, feat_labels[indices[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 -
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/New f/a i/Homework 9 draft.py', wdir='C:/Users/HSIPL/Desktop/New f/a i')
Traceback (most recent call last):
File "C:\Users\HSIPL\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-e53e7077ed93>", line 1, in <module>
runfile('C:/Users/HSIPL/Desktop/New f/a i/Homework 9 draft.py', wdir='C:/Users/HSIPL/Desktop/New f/a i')
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/New f/a i/Homework 9 draft.py", line 12
return df
^
IndentationError: expected an indented block
Please help me on this case