I'm using Codecademy to learn about logistic regression and there are some holes in my understanding of this topic.
import numpy as np hours_studied = np.array([[ 0],[ 1],[ 2],[ 3],[ 4],[ 5],[ 6],[ 7],[ 8],[ 9],,,,,,,,,,]) calculated_coefficients = np.array([[0.20678491]]) intercept = np.array([-1.76125712]) def log_odds(features, coefficients,intercept): return np.dot(features,coefficients) + intercept # z = b0 + b1x1 + b2x2 + .... # log odds measures how likely it is that the data sample belongs to the positive class def sigmoid(z): denominator = 1 + np.exp(-z) return 1/denominator ## In order to map predicted values to probabilities, we use the sigmoid function. # The function maps any real value into another value between 0 and 1. # In machine learning, we use sigmoid to map predictions to probabilities # Create predict_class() function here # features = matrix # coefficients = vector def predict_class(features, coefficients, intercept, threshold): calculated_log_odds = log_odds(hours_studied, calculated_coefficients, intercept) probabilities = sigmoid(calculated_log_odds) return np.where(probabilities >= threshold, 1, 0) # If a value in array_to_check is above threshold, the output is 1. If a value in array_to_check is below threshold, the output is 0. # Make final classifications on Codecademy University data here final_results = predict_class(hours_studied, calculated_coefficients, intercept, .5) print(final_results)
hours_studied, calculated_coefficients and intercept were given by codecademy.
I'm not sure how to get these inputs myself to plug into the model and codecademy didn't explain either. Hours_studied I understand.
Maybe could someone help explain what are the possible steps before I define log_odds, sigmoid, etc to get coefficients and intercept?