You are on page 1of 2

Practical 3 (20BECE30146)

from google.colab import drive


drive.mount('/content/drive')

Drive already mounted at /content/drive; to attempt to forcibly


remount, call drive.mount("/content/drive", force_remount=True).

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

df= pd.read_csv('/content/drive/MyDrive/Datasets/kyphosis.csv')
df.head()

Kyphosis Age Number Start


0 absent 71 3 5
1 absent 158 3 14
2 present 128 4 5
3 absent 2 5 1
4 absent 1 4 15

x=df.iloc[:,1:4]
y=df.iloc[:,0]

0 absent
1 absent
2 present
3 absent
4 absent
...
76 present
77 absent
78 absent
79 present
80 absent
Name: Kyphosis, Length: 81, dtype: object

from sklearn.model_selection import train_test_split


X_train,X_test,y_train,y_test=train_test_split(x,y,test_size=0.3,rando
m_state=10)

from sklearn.linear_model import LogisticRegression


logmodel=LogisticRegression()
logmodel.fit(X_train,y_train)

LogisticRegression()

y_pred=logmodel.predict(X_test)
y_pred
array(['present', 'absent', 'absent', 'absent', 'present', 'absent',
'absent', 'absent', 'present', 'absent', 'present', 'absent',
'absent', 'absent', 'absent', 'absent', 'absent', 'present',
'absent', 'absent', 'absent', 'present', 'absent', 'absent',
'absent'], dtype=object)

from sklearn.metrics import classification_report


print(classification_report(y_test,y_pred))

precision recall f1-score support

absent 0.79 0.83 0.81 18


present 0.50 0.43 0.46 7

accuracy 0.72 25
macro avg 0.64 0.63 0.64 25
weighted avg 0.71 0.72 0.71 25

You might also like