def Classifier_LogisticRegression(X, y, resp1): nome = "Logistic_Regression" X_new, nomeFeature = selecao_feature(X, y, resp1) # split data into train and test sets seed = 100 test_size = 0.2 # separação treino - teste: 80 - 20 X_train, X_test, y_train, y_test = train_test_split(X_new, y, test_size=test_size, random_state=seed) # fit model no training data ## parametros do Modelo: https://xgboost.readthedocs.io/en/latest/python/python_api.html model = LogisticRegression() model.fit(X_train, y_train) # make predictions for test data start_time = utils.get_time() # Tempo inicial y_pred = model.predict(X_test) predictions = [round(value) for value in y_pred] diff_time = utils.get_time_diff(start_time) # Tempo final print_resultados(model, y_test, predictions, diff_time, X_test, nome, nomeFeature)
def Classifier_Gradient_Boosting(X, y, resp1): nome = "Gradient_Boosting" X_new, nomeFeature = selecao_feature(X, y, resp1) # split data into train and test sets seed = 0 test_size = 0.2 n_estimators = 200 # separação treino - teste: 80 - 20 X_train, X_test, y_train, y_test = train_test_split(X_new, y, test_size=test_size, random_state=seed) # fit model no training data #Parâmetros: https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.GradientBoostingClassifier.html model = GradientBoostingClassifier(loss='exponential', learning_rate=0.1, random_state=0, n_estimators=n_estimators) model.fit(X_train, y_train) # make predictions for test data start_time = utils.get_time() # Tempo inicial y_pred = model.predict(X_test) predictions = [round(value) for value in y_pred] diff_time = utils.get_time_diff(start_time) # Tempo final print_resultados(model, y_test, predictions, diff_time, X_test, nome, nomeFeature)
def Classifier_KNN(X, y, resp1): nome = "KNN" X_new, nomeFeature = selecao_feature(X, y, resp1) # split data into train and test sets seed = 100 test_size = 0.2 # separação treino - teste: 80 - 20 X_train, X_test, y_train, y_test = train_test_split(X_new, y, test_size=test_size, random_state=seed) # fit model no training data model = KNeighborsClassifier(n_neighbors=3, metric='euclidean') model.fit(X_train, y_train) # make predictions for test data start_time = utils.get_time() # Tempo inicial y_pred = model.predict(X_test) predictions = [round(value) for value in y_pred] diff_time = utils.get_time_diff(start_time) # Tempo final print_resultados(model, y_test, predictions, diff_time, X_test, nome, nomeFeature)
def SVM(X, y, resp1): nome = "SVM" X_new, nomeFeature = selecao_feature(X, y, resp1) # separação treino - teste: 80 - 20 X_train, X_test, y_train, y_test = train_test_split(X_new, y, test_size=0.2, random_state=0) # Treinamento e Predição classifier = svm.SVC(kernel='rbf', C=5, gamma=0.0001, probability=True) classifier.fit(X_train, y_train) start_time = utils.get_time() # Tempo inicial y_pred = classifier.predict(X_test) diff_time = utils.get_time_diff(start_time) # Tempo final print_resultados(classifier, y_test, y_pred, diff_time, X_test, nome, nomeFeature)
def Random_Forest(X, y, resp1): nome = "Ramdom_Forest" X_new, nomeFeature = selecao_feature(X, y, resp1) # separação treino - teste: 80 - 20 X_train, X_test, y_train, y_test = train_test_split(X_new, y, test_size=0.2, random_state=0) # Treinamento e Predição # 20 árvores (com 100 árvores tem o mesmo resultado) classifier = RandomForestClassifier(n_estimators=200, random_state=0) classifier.fit(X_train, y_train) # Predict start_time = utils.get_time() # Tempo inicial y_pred = classifier.predict(X_test) diff_time = utils.get_time_diff(start_time) # Tempo final print_resultados(classifier, y_test, y_pred, diff_time, X_test, nome, nomeFeature)