Git Product home page Git Product logo

dsc-logistic-regression-in-scikit-learn-lab-online-ds-pt-120919's Introduction

Logistic Regression in scikit-learn - Lab

Introduction

In this lab, you are going to fit a logistic regression model to a dataset concerning heart disease. Whether or not a patient has heart disease is indicated in the column labeled 'target'. 1 is for positive for heart disease while 0 indicates no heart disease.

Objectives

In this lab you will:

  • Fit a logistic regression model using scikit-learn

Let's get started!

Run the following cells that import the necessary functions and import the dataset:

# Import necessary functions
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
# Import data
df = pd.read_csv('heart.csv')
df.head()

Define appropriate X and y

Recall the dataset contains information about whether or not a patient has heart disease and is indicated in the column labeled 'target'. With that, define appropriate X (predictors) and y (target) in order to model whether or not a patient has heart disease.

# Split the data into target and predictors
y = None
X = None

Normalize the data

Normalize the data (X) prior to fitting the model.

# Your code here
X = None
X.head()

Train- test split

  • Split the data into training and test sets
  • Assign 25% to the test set
  • Set the random_state to 0
# Split the data into training and test sets
X_train, X_test, y_train, y_test = None

Fit a model

  • Instantiate LogisticRegression
    • Make sure you don't include the intercept
    • set C to a very large number such as 1e12
    • Use the 'liblinear' solver
  • Fit the model to the training data
# Instantiate the model
logreg = None

# Fit the model

Predict

Generate predictions for the training and test sets.

# Generate predictions
y_hat_train = None
y_hat_test = None

How many times was the classifier correct on the training set?

# Your code here

How many times was the classifier correct on the test set?

# Your code here

Analysis

Describe how well you think this initial model is performing based on the training and test performance. Within your description, make note of how you evaluated performance as compared to your previous work with regression.

# Your analysis here

Summary

In this lab, you practiced a standard data science pipeline: importing data, split it into training and test sets, and fit a logistic regression model. In the upcoming labs and lessons, you'll continue to investigate how to analyze and tune these models for various scenarios.

dsc-logistic-regression-in-scikit-learn-lab-online-ds-pt-120919's People

Contributors

mathymitchell avatar alexgriff avatar loredirick avatar sumedh10 avatar fpolchow avatar taylorhawks avatar

Watchers

James Cloos avatar  avatar Mohawk Greene avatar Victoria Thevenot avatar Bernard Mordan avatar Otha avatar raza jafri avatar  avatar Joe Cardarelli avatar The Learn Team avatar  avatar  avatar Ben Oren avatar Matt avatar Antoin avatar  avatar  avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Kaeland Chatman avatar Lisa Jiang avatar Vicki Aubin avatar Maxwell Benton avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.