Guest User

Untitled

a guest
Nov 19th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. from sklearn.ensemble import RandomForestClassifier
  4. from sklearn.model_selection import train_test_split
  5.  
  6. dataset=np.loadtxt('DatasetAfterClustering.csv',delimiter=',',skiprows=1)
  7.  
  8. features=dataset[:,0:3]
  9. labels=dataset[:,3]
  10.  
  11. tr_features,ts_features,tr_labels,ts_labels=train_test_split(features,labels,test_size=0.5,random_state=42)
  12.  
  13. model=RandomForestClassifier(n_estimators=10, criterion="gini", max_depth=4, min_samples_split=2, min_samples_leaf=1,
  14. min_weight_fraction_leaf=0.0, max_features="sqrt", max_leaf_nodes=None, min_impurity_decrease=0.0,
  15. min_impurity_split=None, bootstrap=True, oob_score=False, n_jobs=-1, verbose=0)
  16.  
  17. model.fit(tr_features,tr_labels)
  18. y=model.predict(ts_features)
  19. pred=pd.DataFrame(y)
  20. act=pd.DataFrame(ts_labels)
  21.  
  22. final=pd.DataFrame(pd.concat([pred,act],axis=1))
  23.  
  24. print final.head()
  25.  
  26. count=0.0
  27.  
  28. for i in range(len(y)):
  29. if(y[i]==ts_labels[i]):
  30. count=count+1
  31. else:
  32. count=count+0
  33.  
  34. Accuracy=model.score(ts_features,ts_labels)
  35.  
  36. print (count/(ts_labels.shape[0]))*100 #99.8317712088
  37.  
  38. print model.feature_importances_ #[ 0.92408555 0.02874635 0.0471681 ]
Add Comment
Please, Sign In to add comment