-
Notifications
You must be signed in to change notification settings - Fork 0
/
IRIS- Logistic Regression.py
29 lines (22 loc) · 886 Bytes
/
IRIS- Logistic Regression.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pandas as pd
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import accuracy_score
from sklearn.linear_model import LogisticRegression
# Load The Data Into DataFrame with Pandas
iris = load_iris()
X = pd.DataFrame(iris.data) # Independent Variable
y = pd.DataFrame(iris.target) # Dependent Variable
#print(X.head()) # print 5 rows of independent variable
#Label Encoder
encode = LabelEncoder()
y = encode.fit_transform(y)
# convert into train and test data
trainX,testX,trainy, testy = train_test_split(X, y, test_size= 0.2)
# fit and predict model
model = LogisticRegression().fit(trainX,trainy)
predy = model.predict(testX)
# check accuracy score
score = accuracy_score(testy, predy)
print(f'Accuracy Score : {score}')