Lab Assignment-4


Assignment-4- week 4 July

Learning Objective: Apply Logisitc Regression 


1.A teacher collected data from previous students regarding the number of hours they studied before an examination and whether they passed the exam.

Using the given dataset,

  1. Read the dataset.
  2. Train a Logistic Regression model.( gradient descent - do not use library)
  3. Calculate the model accuracy.
  4. Predict whether a student studying 4.5 hours, 6 hours, and 9 hours is likely to pass.
  5. Plot the data points along with the logistic regression curve.

Dataset

Hours StudiedPass (Target)
1.00
1.50
2.00
2.50
3.00
3.50
4.00
4.51
5.01
5.51
6.01
6.51
7.01
7.51
8.01
8.51
9.01
9.51
10.01
10.51

Students can either type this data into Python or save it as student_pass.csv.


2.A hospital has collected several diagnostic measurements from breast cancer patients. Each record contains features extracted from cell nuclei images. The target variable indicates whether the tumor is:

  • 0 → Malignant
  • 1 → Benign

Build a Logistic Regression model to classify tumors and evaluate its performance using different metrics.

Dataset

Use the built-in dataset available in Scikit-Learn.

from sklearn.datasets import load_breast_cancer

data = load_breast_cancer()

Dataset Information
Number of samples: 569
Number of features: 30
Number of classes: 2
Target names:
Malignant
Benign

Tasks

Part A – Load and Explore the Dataset

  1. Load the Breast Cancer dataset.
  2. Convert it into a Pandas DataFrame.
  3. Display:
    • First five rows
    • Dataset shape
    • Column names
    • Data types
    • Number of missing values
    • Class distribution

Part B – Data Preprocessing

  1. Separate the independent variables (X) and target (y).
  2. Split the dataset into 80% training and 20% testing.
  3. Standardize the feature values using StandardScaler

Part C – Build the Logistic Regression Model

  1. Train a Logistic Regression classifier.
  2. Predict the labels of the test dataset.
  3. Predict the class probabilities using predict_proba().

Part D – Evaluate the Model

Calculate the following performance metrics:

  • Accuracy
  • Precision
  • Recall
  • F1-score
  • Confusion Matrix
  • Classification Report

Display the confusion matrix as a heatmap.

Part E – ROC Curve

  1. Compute the ROC Curve.
  2. Calculate the Area Under Curve (AUC).
  3. Plot the ROC curve.
  4. Interpret the result.

Part F – Probability Prediction

Predict the probability that the following patient has a malignant tumor.

sample = X_test.iloc[0:1]

Additional Exercises

  1. Change the test size from 20% to 30%. Compare the evaluation metrics.
  2. Train the model without feature scaling. Compare the accuracy with the scaled version.
  3. Change the random state from 42 to 10 and observe the change in performance.
  4. Print the coefficients of the Logistic Regression model and identify the five most influential features.
  5. Predict the diagnosis for the first five test samples using predict() and predict_proba().
  6. Change the classification threshold from 0.5 to 0.7 and observe how precision and recall change.

3.Implement a logistic regression model to predict the likelihood of a disease using the Pima Indians Diabetes dataset. Compare the performance with and without feature scaling.

Tasks:
● Load and preprocess the Pima Indians Diabetes dataset.
● Implement logistic regression for binary classification.
● Evaluate model performance with and without feature scaling.
● Analyze metrics such as accuracy, precision, recall, and F1-score.

Comments

Popular posts from this blog

Machine Learning Lab PCCSL508 Semester 5 KTU CS 2024 Scheme manual - Dr Binu V P

Explore California Housing Dataset

Lab Assignment-1