[pycon] Jupyter Notebook

Viewer

copydownloadembedprintName: Jupyter Notebook
  1. numerical = df.drop(columns=["Load_Type"]).select_dtypes('number').columns.tolist()
  2. passthrough_features = df.drop(columns=["Load_Type"]).select_dtypes('object').columns.tolist()
  3. preprocessor = make_column_transformer(
  4.     (make_pipeline(StandardScaler()),numerical,),
  5.     ("passthrough", passthrough_features),)
  6.     
  7.     
  8.     
  9. models = []
  10.  
  11. names = [
  12.     "logistic regression",
  13.     "KNN",
  14.     "Linear SVC / SVM Linear", 
  15.     "SVM RBF",
  16.     "Decision Tree",
  17.     "Naive Bayes",
  18.     "Random forest",
  19.     "AdaBoost",
  20.     "XGBoost",
  21.     "CatBoost",
  22. ]
  23.  
  24. scores = []
  25. clf = [
  26.     LogisticRegression(),
  27.     KNeighborsClassifier(3),
  28.     SVC(kernel="linear", C=1),
  29.     SVC(kernel="rbf", gamma=1, C=1),
  30.     DecisionTreeClassifier(max_depth=5),
  31.     GaussianNB(),
  32.     RandomForestClassifier(n_estimators=200, max_leaf_nodes=16),
  33.     AdaBoostClassifier(DecisionTreeClassifier(max_depth=3)),
  34.     XGBClassifier(),
  35.     CatBoostClassifier(loss_function='MultiClass', eval_metric='Accuracy')
  36. ]
  37.  
  38. for model in clf:
  39.     
  40.     pipe = make_pipeline(preprocessor, model)
  41.     pipe.fit(X_train, y_train)
  42.     print(model)
  43.     score = pipe.score(X_test, y_test)
  44.     scores.append(score)
  45.     print("Model score: %.3f" %score)
  46.     print("\n-------------------------\n")
  47.  
  48. scores_df = pd.DataFrame(zip(names,scores), columns=['Classifier', 'Accuracy'])

Editor

You can edit this paste and save as new:


File Description
  • Jupyter Notebook
  • Paste Code
  • 02 Dec-2022
  • 1.33 Kb
You can Share it: