Olá meu povo, aqui está o código usado no video abaixo e a seguir o link para o dataset que usamos também.
#!/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.linear_model import LogisticRegression
######################################
# 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)
######################################
# Treinando o modelo
######################################
classifier = LogisticRegression()
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_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)
y_result = np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1)
print(accuracy_score(y_test, y_pred))
Dataset: https://www.kaggle.com/naveengowda16/logistic-regression-heart-disease-prediction
Qualquer dúvida, só falar 🙂
Rafa