Ejemplo n.º 1
0
def working_PCA():

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

    #Prepare data
    MLobj.explore()
    MLobj.split_X_y()
    MLobj.split_ds()
    MLobj.scale_features(scaleY=False)

    #Applyinh PCA
    from sklearn.decomposition import PCA
    pca = PCA(n_components=2)
    MLobj.X_train = pca.fit_transform(MLobj.X_train)
    MLobj.X_test = pca.transform(MLobj.X_test)
    explained_variance = pca.explained_variance_ratio_

    #Classification
    MLobj.fitLog()

    #Predict
    y_pred = MLobj.predict()

    #Evaluation confusion matrix
    cm = MLobj.create_confusion_matrix()

    MLobj.printModelPerformance()

    #Visualize data
    #MLobj.visualize_lineal_2D_class(MLobj.X_train,MLobj.y_train,x1="PC1",x2="PC2",classNum=3)
    MLobj.visualize_lineal_2D_class(x1="PC1", x2="PC2", classNum=3)
Ejemplo n.º 2
0
def working_class_dec_tree_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.fitDecTree()

    #Predict
    y_pred = MLobj.predict()

    #Evaluation confusion matrix
    cm = MLobj.create_confusion_matrix()
    print(cm)

    #Visualize data
    MLobj.visualize_lineal_2D_class(MLobj.X_train, MLobj.y_train)
    MLobj.visualize_lineal_2D_class()
Ejemplo n.º 3
0
def working_PCA_easy():

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

    #Prepare data
    MLobj.explore()
    MLobj.split_X_y()
    MLobj.split_ds()
    MLobj.scale_features(scaleY=False)

    #Applyinh PCA
    MLobj.applyPCA()
    PCAratio = MLobj.getPCAVarianceRatio()

    #Classification
    MLobj.fitLog()

    #Predict
    y_pred = MLobj.predict()

    #Evaluation confusion matrix
    cm = MLobj.create_confusion_matrix()

    MLobj.printModelPerformance()

    #Visualize data
    #MLobj.visualize_lineal_2D_class(MLobj.X_train,MLobj.y_train,x1="PC1",x2="PC2",classNum=3)
    MLobj.visualize_lineal_2D_class(x1="PC1", x2="PC2", classNum=3)
Ejemplo n.º 4
0
def working_kernel_PCA_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()
    MLobj.scale_features(scaleY=False)

    #Applyinh Kernel PCA
    MLobj.applyKernelPCA()

    #Classification
    MLobj.fitLog()

    #Predict
    y_pred = MLobj.predict()

    #Evaluation confusion matrix
    cm = MLobj.create_confusion_matrix()

    MLobj.printModelPerformance()

    #Visualize data
    #MLobj.visualize_lineal_2D_class(MLobj.X_train,MLobj.y_train,x1="KPC1",x2="KPC2")
    MLobj.visualize_lineal_2D_class(x1="KPC1", x2="KPC2")
Ejemplo n.º 5
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()
Ejemplo n.º 6
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_
Ejemplo n.º 7
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()