0% found this document useful (0 votes)
8 views

LOGISTIC REGRESSION - Jupyter Notebook

Uploaded by

064- sarvani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

LOGISTIC REGRESSION - Jupyter Notebook

Uploaded by

064- sarvani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

13/06/2024, 07:32 LOGISTIC REGRESSION - Jupyter Notebook

In [8]: from sklearn.datasets import load_iris


from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
import numpy as np
import pandas as pd

In [10]: iris=load_iris()

In [11]: x=iris.data
y=iris.target

x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,random_state=4

In [12]: def logistic_regression_model():


model=LogisticRegression()
return model

In [13]: logreg_model=logistic_regression_model()

In [15]: logreg_model.fit(x_train,y_train)

Out[15]: LogisticRegression()

In [18]: y_pred=logreg_model.predict(x_test)

In [19]: logreg_model.score(x_test,y_test)
Out[19]: 1.0

In [20]: coeff=logreg_model.coef_
coeff

Out[20]: array([[-0.40460959, 0.86845669, -2.27800677, -0.95749003],


[ 0.46652106, -0.37524231, -0.18767955, -0.72036767],
[-0.06191146, -0.49321438, 2.46568632, 1.67785769]])

In [24]: df=pd.DataFrame(data=np.reshape(a=[y_test,y_pred],newshape=(len(y_test),2)),col

In [27]: df['test'] = df['test'].replace(to_replace=[0, 1, 2], value=iris.target_names)


df['prediction'] = df['prediction'].replace(to_replace=[0, 1, 2], value=iris.ta

localhost:8888/notebooks/MACHINE LEARNING LAB/LOGISTIC REGRESSION.ipynb 1/2


13/06/2024, 07:32 LOGISTIC REGRESSION - Jupyter Notebook

In [28]: df.head(10)
Out[28]:
test prediction

0 versicolor setosa

1 virginica versicolor

2 versicolor setosa

3 versicolor virginica

4 versicolor versicolor

5 virginica setosa

6 setosa setosa

7 setosa versicolor

8 virginica versicolor

9 versicolor virginica

In [ ]: ​

localhost:8888/notebooks/MACHINE LEARNING LAB/LOGISTIC REGRESSION.ipynb 2/2

You might also like