##### How to find the accuracy for Random Forest
 How to find the accuracy for Random Forest vokoyo Silly Frenchman Posts: 27 Threads: 16 Joined: Apr 2018 Reputation: Apr-09-2019, 02:31 PM (This post was last modified: Apr-09-2019, 02:32 PM by vokoyo.) May I know how to modify my Python programming so that can obtain the accuracy vs number of features as refer to the attached image file - ```from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import accuracy_score # load the data iris = datasets.load_iris() # get the features and labels from the data x = iris.data y = iris.target # split the data into training and test data X_train, X_test, y_train, y_test = train_test_split(x, y,test_size=0.7, random_state=0) # standardise the data sc = StandardScaler() X_train_std = sc.fit_transform(X_train) X_test_std = sc.fit_transform(X_test) # choose algorithm and set the hyperparameters forest = RandomForestClassifier(criterion='entropy', n_estimators=10, random_state=1) # train the model forest.fit(X_train_std, y_train) # make the prediction using the model y_pred = forest.predict(X_test_std) A = [] C1 = [forest] for i in range(len(C)): forest = RandomForestClassifier(C=C1[i], random_state=0) forest.fit(X_train_std,y_train) y_pred = forest.predict(X_test_std) A.append(accuracy_score(y_test,y_pred)) import matplotlib.pyplot as plt plt.plot(C1, A) plt.yticks(np.arange(0.90, 0.95, 0.01)) plt.xlabel('Number of features') plt.ylabel('Accuracy') plt.title('RansomForest') plt.show()``` The error message is - ```runfile('C:/Users/HSIPL/Desktop/Homework 7 Solution draft.py', wdir='C:/Users/HSIPL/Desktop') Traceback (most recent call last): File "", line 1, in runfile('C:/Users/HSIPL/Desktop/Homework 7 Solution 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 7 Solution draft.py", line 28, in forest = RandomForestClassifier(C=C1[i], random_state=0) TypeError: __init__() got an unexpected keyword argument 'C'``` Please see the attached image file - Please help me on this case Reply ichabod801 Bunny Rabbit Posts: 4,231 Threads: 97 Joined: Sep 2016 Reputation: Apr-09-2019, 07:53 PM You are getting an error because RandomForestClassifier has no C parameter. It is unclear why you are trying to pass one to it. It appears the value you are trying to pass is another RandomForestClassifier. But RandomForestClassifier does not take other RandomForestClassifer's as a value for any of it's parameters. See the documentation. Craig "Ichabod" O'Brien - xenomind.com I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures Reply vokoyo Silly Frenchman Posts: 27 Threads: 16 Joined: Apr 2018 Reputation: Apr-09-2019, 10:50 PM (This post was last modified: Apr-09-2019, 10:50 PM by vokoyo.) How to write the correct code for the number of features Reply

 Possibly Related Threads… Thread Author Replies Views Last Post How to find the accuracy vs number of neighbours for KNN vokoyo 3 1,544 Apr-10-2019, 03:46 AM Last Post: scidam dummy classifier accuracy and recall score metalray 0 3,265 Oct-31-2017, 09:27 AM Last Post: metalray

Forum Jump:

### User Panel Messages

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