logistic-regression-from-scratch-python's People
logistic-regression-from-scratch-python's Issues
Technical doubt regarding Logistic Regression
I am Mayank Agrawal from India, studying Machine Learning from your book titled "Essential Math for Data Science" by Thomas Nield. I was studying Logistic Regression topic and I am facing technical problem when I am writing code for the same in python from scratch.
Example referred from book is patient data given in Example 6-8.
Python-Code is attached herewith in .txt form
patient_data.xlsx
Log-Reg.txt
for reference along with Input data excel file. I have used the matrix form of Gradient descent. but my answer is coming wrong as I am decreasing the learning rate.
The learning rate used in your example is 0.01, but my answer is coming correct only when learning rate is 0.1, else not. If I am decresing the learning rate to .01 answer is coming wrong.
Can you please help me regarding this.
Regards,
Mayank agrawal
India
Technical doubt regarding Logistic regression
I am Mayank Agrawal from India, studying Machine Learning from your book titled "Essential Math for Data Science" by Thomas Nield. I was studying Logistic Regression topic and I am facing technical problem when I am writing code for the same in python from scratch.
Example referred from book is patient data given in Example 6-8.
Python-Code is attached herewith for reference along with Input data excel file. I have used the matrix form of Gradient descent. but my answer is coming wrong as I am decreasing the learning rate.
The learning rate used in your example is 0.01, but my answer is coming correct only when learning rate is 0.1, else not. If I am decresing the learning rate to .01 answer is coming wrong.
Can you please help me regarding this.
Regards,
Mayank agrawal
India
-- coding: utf-8 --
"""
Created on Sun Jul 9 17:13:45 2023
@author: Mayank
"""
import sys
import pandas as pd
import matplotlib
import numpy as np
import scipy as sp
import IPython
import sklearn
from sklearn.linear_model import LogisticRegression
patient_data = pd.read_excel(r'C:\Users\mayank.agrawal\Downloads\patient_data.xlsx', sheet_name='patient_data')
p_d=np.asarray(patient_data)
n=len(patient_data) #No. of Data Points
x=p_d[:,0:1]
y=p_d[:,1:2]
m=x.shape[1]+1 #No. of features
X=np.c_[np.ones(n),x] #Add a columns of ones
a=np.zeros((m,1)) # random initialization
a[0,0]=1
a[1,0]=1
lr=.1
grad=np.zeros((m,1))
def sigmoid(p):
sig=1/(1+np.exp(p))
return sig
for k in range(10000):
s=np.matmul(X,a)
sigma=sigmoid(s)
grad=-1/nnp.dot(np.transpose(X),sigma-y)
a=a-lrgrad
print(a)
Check using SKlearn
Perform logistic regression
Turn off penalty
model = LogisticRegression(penalty='none')
model.fit(x, y)
print beta1
print(model.coef_.flatten()) # 0.69267212
print beta0
print(model.intercept_.flatten()) # -3.17576395
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.