Ola’ meu povo! Aqui estao o codigo e link para o dataset usado no ultimo video sobre K-NN em Python.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat Apr 3 12:33:33 2021 @author: rafaeldontalgoncalez """ ###################################### # Importando as libraries ###################################### import pandas as pd import sklearn.model_selection as ms import matplotlib.pyplot as plt import numpy as np from sklearn.metrics import confusion_matrix, accuracy_score from sklearn.neighbors import KNeighborsClassifier from sklearn.preprocessing import StandardScaler ###################################### # Importa o dataset ###################################### dataset = pd.read_csv("doencas_cardiacas.csv") dataset = dataset.dropna() X = dataset.iloc[:, :-1].values y = dataset.iloc[:, -1].values ###################################### # Separar dados em Treino e Teste ###################################### X_train, X_test, y_train, y_test = ms.train_test_split(X, y, test_size = 1/5, random_state = 0) ###################################### # Feature Scalling ###################################### sc_X_train = StandardScaler() sc_X_test = StandardScaler() X_train = sc_X_train.fit_transform(X_train) X_test = sc_X_test.transform(X_test) ###################################### # Treinando o modelo ###################################### classifier = KNeighborsClassifier(n_neighbors=5,) classifier.fit(X_train, y_train) ###################################### # Valor Especifico ###################################### print(classifier.predict([[1,30,4,0,0,0,0,0,0,195,130,70,80,20,56]])) ###################################### # Previsao ###################################### y_pred = classifier.predict(X_test) y_result = np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1) y_pred_prob = classifier.predict_proba(X_test) y_pred_prob = y_pred_prob[:,1] y_result_prob = np.concatenate((y_pred.reshape(len(y_pred),1), y_pred_prob.reshape(len(y_pred_prob),1)),1) ###################################### # Matrix de confusao ###################################### cm = confusion_matrix(y_test, y_pred) print(cm) print(accuracy_score(y_test, y_pred))
Dataset:
https://www.kaggle.com/naveengowda16/logistic-regression-heart-disease-prediction
Video: