Example #1
0
def working_k_fold_cross_easy():

    #Read data
    MLobj = EasyClassi()
    MLobj.read("Social_Network_Ads.csv")

    #Prepare data
    MLobj.explore()
    MLobj.split_X_y()
    MLobj.X = MLobj.X[:, 2:4]
    MLobj.split_ds(test_set=1 / 4)
    MLobj.scale_features(scaleY=False)

    #Classification
    MLobj.fitKernelSVM()

    #Predict
    y_pred = MLobj.predict()

    #Evaluation confusion matrix
    cm = MLobj.create_confusion_matrix()

    #Applying K-Fold Cross validation
    MLobj.apply_class_k_fold()
    MLobj.print_k_fold_perf()
Example #2
0
def working_grid_search():

    #Read data
    MLobj = EasyClassi()
    MLobj.read("Social_Network_Ads.csv")

    #Prepare data
    MLobj.explore()
    MLobj.split_X_y()
    MLobj.X = MLobj.X[:, 2:4]
    MLobj.split_ds(test_set=1 / 4)
    MLobj.scale_features(scaleY=False)

    #Classification
    MLobj.fitKernelSVM()

    #Predict
    y_pred = MLobj.predict()

    #Evaluation confusion matrix
    cm = MLobj.create_confusion_matrix()

    #Applying K-Fold Cross validation
    MLobj.apply_class_k_fold()
    MLobj.print_k_fold_perf()

    #Apply grid search to find the best model and best parameters
    from sklearn.model_selection import GridSearchCV
    parameters = [{
        'C': [1, 10, 100, 1000],
        "kernel": ["linear"]
    }, {
        'C': [1, 10, 100, 1000],
        "kernel": ["rbf"],
        "gamma": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
    }]
    grid_search = GridSearchCV(estimator=MLobj.classifier,
                               param_grid=parameters,
                               scoring="accuracy",
                               cv=10,
                               n_jobs=-1)

    grid_search = grid_search.fit(MLobj.X_train, MLobj.y_train)
    best_accuracy = grid_search.best_score_
    best_parameters = grid_search.best_params_
Example #3
0
def working_grid_search_easy():

    #Read data
    MLobj = EasyClassi()
    MLobj.read("Social_Network_Ads.csv")

    #Prepare data
    MLobj.explore()
    MLobj.split_X_y()
    MLobj.X = MLobj.X[:, 2:4]
    MLobj.split_ds(test_set=1 / 4)
    MLobj.scale_features(scaleY=False)

    #Classification
    MLobj.fitKernelSVM()

    #Predict
    y_pred = MLobj.predict()

    #Evaluation confusion matrix
    cm = MLobj.create_confusion_matrix()

    #Applying K-Fold Cross validation
    MLobj.apply_class_k_fold()
    MLobj.print_k_fold_perf()

    #Apply grid search to find the best model and best parameters
    parameters = [{
        'C': [1, 10, 100, 1000],
        "kernel": ["linear"]
    }, {
        'C': [1, 10, 100, 1000],
        "kernel": ["rbf"],
        "gamma": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
    }]

    MLobj.apply_grid_search(paramsGS=parameters)
    MLobj.print_grid_search_perf()