Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. # Select Percentile works on the Percentiles, I create a list of percentile that
  2. # provides the progressive number of features from 2 to 20:
  3. n_comp=list(100*i/42 for i in range(2,21))
  4. # iteration loop
  5. for n in n_comp:
  6. comp=n
  7. select_sp=SelectPercentile(percentile=comp)
  8. X_r2 = select_sp.fit(Xtrain_scaled,ytrain).transform(Xtrain_scaled)
  9. X_r2_val = select_sp.transform(Xval_scaled)
  10. lr.fit(X_r2, ytrain)
  11. knn.fit(X_r2, ytrain)
  12. lin_svc.fit(X_r2, ytrain)
  13. results_logreg_sp[comp]={'LogReg Num. features':X_r2.shape[1],
  14. 'Training Score':lr.score(X_r2, ytrain),
  15. 'Valuation Score':lr.score(X_r2_val, yval)}
  16. results_knn_sp[comp]={'KNN Num. features':X_r2.shape[1],
  17. 'Training Score':knn.score(X_r2, ytrain),
  18. 'Valuation Score':knn.score(X_r2_val, yval)}
  19. results_LinSVC_sp[comp]={'Lin SVC Num. features':X_r2.shape[1],
  20. 'Training Score':lin_svc.score(X_r2, ytrain),
  21. 'Valuation Score':lin_svc.score(X_r2_val, yval)}
  22. # Display the dataframes:
  23. res_logreg_sp=pd.DataFrame(results_logreg_sp).T.set_index('LogReg Num. features')
  24. res_knn_sp=pd.DataFrame(results_knn_sp).T.set_index('KNN Num. features')
  25. res_LinSVC_sp=pd.DataFrame(results_LinSVC_sp).T.set_index('Lin SVC Num. features')
  26. display_side_by_side(res_logreg_sp,res_knn_sp,res_LinSVC_sp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement