check logistic regression accuracy
This commit is contained in:
31
scripts/logistic.py
Normal file
31
scripts/logistic.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import pandas as pd
|
||||||
|
from sklearn.model_selection import train_test_split
|
||||||
|
from sklearn.linear_model import LogisticRegression
|
||||||
|
from sklearn.preprocessing import LabelEncoder
|
||||||
|
from sklearn.metrics import accuracy_score, classification_report
|
||||||
|
|
||||||
|
data = pd.read_excel('/Users/apple/Downloads/21092023-July_Sept.xlsx', sheet_name="op")
|
||||||
|
data = data.dropna()
|
||||||
|
print(data)
|
||||||
|
|
||||||
|
label_encoder = LabelEncoder()
|
||||||
|
categorical_cols = ['Gender', 'Caste', 'Category', 'Marital Status', 'Blood Group']
|
||||||
|
for col in categorical_cols:
|
||||||
|
data[col] = label_encoder.fit_transform(data[col])
|
||||||
|
|
||||||
|
X = data[['Age', 'Gender', 'Caste', 'Category', 'Marital Status']]
|
||||||
|
y = data['Test Result']
|
||||||
|
|
||||||
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
||||||
|
|
||||||
|
model = LogisticRegression()
|
||||||
|
model.fit(X_train, y_train)
|
||||||
|
|
||||||
|
y_pred = model.predict(X_test)
|
||||||
|
|
||||||
|
accuracy = accuracy_score(y_test, y_pred)
|
||||||
|
classification_report_result = classification_report(y_test, y_pred)
|
||||||
|
|
||||||
|
print(f"Accuracy: {accuracy}")
|
||||||
|
print("Classification Report:")
|
||||||
|
print(classification_report_result)
|
||||||
Reference in New Issue
Block a user