Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
32 views
3 pages
Logistic Reg
e
Uploaded by
shrutisuman03
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save LogisticReg(2) For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
32 views
3 pages
Logistic Reg
e
Uploaded by
shrutisuman03
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save LogisticReg(2) For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save LogisticReg(2) For Later
You are on page 1
/ 3
Search
Fullscreen
9722922, 752 PM Unites Name: Shruti Suman ROLL: MCA/10011/21 #logistic Regression (2) import csv import numpy as np import matplotlib.pyplot as plt def loadcsv(#ilename) : function to load dataset with open(filenane,"r") as csvfile: Lines = csv.reader(csvfile) dataset = List(1ines) for i in range(1en(dataset)): cataset[i] = [float(x) for x in dataset[i]] return np.array(dataset) def normalize(x): function to normalize feature matrix, X mins = np.min(X, axis = 0) maxs = np.max(X, axis = 0) png = maxs - ins normX = 1 - ((maxs - X)/rng) return nora_X def logistic_func(beta, X): logistic(signoid) function return 1.0/(1 + np.exp(-np.dot(X, beta.T))) def log_gradient(beta, x, y): logistic gradient function First_calc = logistic_func(beta, x) - y.reshape(X.shape[@], -1) final_calc = np.dot(first_calc.T, x) return final_calc def cost_func(beta, x, y): cost function, 3 Loading (Mathlax/ja/output/CommonHTTMUfonts/Tex/fontdatajs | *) y= pS 7 localhost8#¢9inconvarthiml Untied jpynb?dowlo9122122, 752 PM def def Unites step = y * np.Jog(1og_func_v) step2 = (1 - y) * np-log(1 - log_func_v) final = -step1 - step2 return np.mean(final) grad_desc(x, y, beta, Ir=.01, converge_change=.001): gradient descent function cost = cost_func(beta, X, y) change_cost = 1 nun_iter = 1 while(change_cost > converge_change) : ‘old_cost = cost beta = beta - (1r * log_gradient (beta, X, y)) cost = cost_func(beta, X, y) change_cost = old_cost - cost nun_iter += 2 return beta, num_iter pred_values(beta, x): function to predict labels pred_prob = logistic func(beta, x) pred_value = np.where(pred_prob >= .5, 1, 8) return np.squeeze(pred_value) plot_reg(X, y, beta): function to plot decision boundary # Labelled observations x0 = X[np.where(y == 0.0)] XA = X[np.where(y == 1.0)] # plotting points with diff color for diff Lobel plt.scatter([xf:, 1]], [<0[: plt.seatter([xaf:, 1], boas, 21], © # plotting decision boundary x1 = np.arange(@, 1, 0.1) x2 = -(beta[0,0] + beta[0,1]*x1)/betala,2] plt.plot(x1, x2, c='k', label='reg line') plt.xlabel(‘x1') plt.ylabel('x2") pt. legend() plt.show() Loading (Mathlax/ja/output/CommonHTML/fonts/Tex/fontdatajs localhost.a#6ginbconvarthiml Untied jpynb?download=false 209722922, 752 PM Unites # Load the dataset dataset = loadcsv( ‘data.csv') normalizing feature matrix normalize(dataset[:, :-1]) xs stacking colums with all ones in feature matrix np. hstack((np.matrix(np.ones(X.shape[0])).T, X)) xs # response vector y = dataset[:, -1] # initial beta values beta = np.matrix(np.zeros(X.shape[1])) # beta values after running gradient descent beta, numiter = grad_desc(x, y, beta) # estimated beta values and number of iterations print("Estimated regression coefficients:", beta) print("No. of iterations:", num_iter) # predicted Labels y_pred = pred_values(beta, X) # number of correctly predicted Labels print("Correctly predicted labels:", np.sum(y y_pred)) # plotting regression Line plot_reg(X, y, beta) Estimated regression coefficient: No. of iterations: 2612 Correctly predicted labels: 100 10 [[ 1.70474504 15.04062212 -20.47216021]] os 06 2 04 02 oo Loading (Mathlax/ja/output/CommonHTML/fonts/TeX/fontdatajs localhost 8#¢9inbconvarthiml Untied jpynb?downlo
You might also like
Life Insurance Data
PDF
No ratings yet
Life Insurance Data
174 pages
ML Lab Manual
PDF
100% (1)
ML Lab Manual
37 pages
AAL Programs
PDF
No ratings yet
AAL Programs
12 pages
Machine Learning Lab Manual
PDF
No ratings yet
Machine Learning Lab Manual
9 pages
Machine Learning Hands-On
PDF
100% (1)
Machine Learning Hands-On
18 pages
Machine Learning Lab Manual 06
PDF
100% (1)
Machine Learning Lab Manual 06
8 pages
Wa0002.
PDF
No ratings yet
Wa0002.
5 pages
Lab Experiments Vi Sem-1
PDF
No ratings yet
Lab Experiments Vi Sem-1
10 pages
20BCP021 Assignment 6
PDF
No ratings yet
20BCP021 Assignment 6
15 pages
Aiml Lab
PDF
No ratings yet
Aiml Lab
14 pages
ML Lab....... 3-Converted New
PDF
No ratings yet
ML Lab....... 3-Converted New
27 pages
ML Manual
PDF
No ratings yet
ML Manual
30 pages
''' Function To Load Dataset ''': Open List Range Len Float
PDF
No ratings yet
''' Function To Load Dataset ''': Open List Range Len Float
3 pages
ML Lab Codes
PDF
No ratings yet
ML Lab Codes
14 pages
4-10 Aiml
PDF
No ratings yet
4-10 Aiml
25 pages
Group Work Assignment Supervised and Unsupervised Learning
PDF
No ratings yet
Group Work Assignment Supervised and Unsupervised Learning
10 pages
ML Manual Final
PDF
No ratings yet
ML Manual Final
35 pages
Codes
PDF
No ratings yet
Codes
14 pages
Lab4 - Jupyter Notebook
PDF
No ratings yet
Lab4 - Jupyter Notebook
7 pages
Bda Assign
PDF
No ratings yet
Bda Assign
15 pages
C1 W3 Logistic Regression
PDF
No ratings yet
C1 W3 Logistic Regression
27 pages
ML Assigmengt Rishu Ranjan 12212221: # Import Necessary Libraries
PDF
No ratings yet
ML Assigmengt Rishu Ranjan 12212221: # Import Necessary Libraries
3 pages
Machine File
PDF
No ratings yet
Machine File
27 pages
Implementation of Linear Regression: Sir Syed University of Engineering & Technology, Karachi
PDF
No ratings yet
Implementation of Linear Regression: Sir Syed University of Engineering & Technology, Karachi
11 pages
Logistic - Regresssion
PDF
No ratings yet
Logistic - Regresssion
22 pages
Linear Regression
PDF
No ratings yet
Linear Regression
14 pages
ML1
PDF
No ratings yet
ML1
6 pages
Linear Regression (Code)
PDF
No ratings yet
Linear Regression (Code)
9 pages
ML Short Code - Under Updating
PDF
No ratings yet
ML Short Code - Under Updating
4 pages
LinearRegression Tutorial
PDF
No ratings yet
LinearRegression Tutorial
40 pages
ML Lab 01999676272
PDF
No ratings yet
ML Lab 01999676272
12 pages
ML Exp 3-7 Manuval
PDF
No ratings yet
ML Exp 3-7 Manuval
21 pages
Experiment ML
PDF
No ratings yet
Experiment ML
14 pages
Import Numpy As NP
PDF
No ratings yet
Import Numpy As NP
4 pages
Experiment 5
PDF
No ratings yet
Experiment 5
7 pages
ML Manual
PDF
No ratings yet
ML Manual
9 pages
Exp3 ML
PDF
No ratings yet
Exp3 ML
4 pages
Data Science Record - 05
PDF
No ratings yet
Data Science Record - 05
20 pages
Experimenting With Data Analysis Packages and Statistical Operations
PDF
No ratings yet
Experimenting With Data Analysis Packages and Statistical Operations
18 pages
ML All Projectpdf Removed
PDF
No ratings yet
ML All Projectpdf Removed
41 pages
Aiml Programs
PDF
No ratings yet
Aiml Programs
12 pages
Experiment No 3
PDF
No ratings yet
Experiment No 3
7 pages
DL Lab 5
PDF
No ratings yet
DL Lab 5
3 pages
Lab Exam ... Roll No 24cs4103
PDF
No ratings yet
Lab Exam ... Roll No 24cs4103
4 pages
16BCB0126 VL2018195002535 Pe003
PDF
No ratings yet
16BCB0126 VL2018195002535 Pe003
40 pages
DA Programs
PDF
No ratings yet
DA Programs
44 pages
22se02cs039 DS P-11
PDF
No ratings yet
22se02cs039 DS P-11
10 pages
Da Lab Mannual
PDF
No ratings yet
Da Lab Mannual
25 pages
Program
PDF
No ratings yet
Program
19 pages
Data Analytics
PDF
No ratings yet
Data Analytics
10 pages
MlLabManualdocx 2024 09 04 22 02 58
PDF
No ratings yet
MlLabManualdocx 2024 09 04 22 02 58
19 pages
Solution8 12
PDF
No ratings yet
Solution8 12
12 pages
Aiml Practicals
PDF
No ratings yet
Aiml Practicals
22 pages
Print Out ML - Finallllllllllllllll
PDF
No ratings yet
Print Out ML - Finallllllllllllllll
11 pages
Btech1007022 Lab5.1
PDF
No ratings yet
Btech1007022 Lab5.1
9 pages
Btech1007022 Lab5
PDF
No ratings yet
Btech1007022 Lab5
14 pages
Data Warehousing and Data Mining
PDF
No ratings yet
Data Warehousing and Data Mining
24 pages
DSBDA Practicals
PDF
No ratings yet
DSBDA Practicals
16 pages
ML Journal External
PDF
No ratings yet
ML Journal External
14 pages
Iii Aid - ML
PDF
No ratings yet
Iii Aid - ML
30 pages
Question 4
PDF
No ratings yet
Question 4
17 pages
Log Reg
PDF
No ratings yet
Log Reg
13 pages
Linear
PDF
No ratings yet
Linear
107 pages
Data Set For Route Maps
PDF
No ratings yet
Data Set For Route Maps
3 pages