0% found this document useful (0 votes)
103 views1 page

Python - Logistic Regression

This code snippet splits iris data into training and test sets using train_test_split. It fits a logistic regression model to the training data and predicts the test labels. It prints a classification report and calculates the macro-averaged precision and recall, writing the results to an output file.

Uploaded by

Aduvaita A
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views1 page

Python - Logistic Regression

This code snippet splits iris data into training and test sets using train_test_split. It fits a logistic regression model to the training data and predicts the test labels. It prints a classification report and calculates the macro-averaged precision and recall, writing the results to an output file.

Uploaded by

Aduvaita A
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

###Start code

from sklearn.model_selection import train_test_split

X_train,X_test,y_train,y_test = train_test_split(iris_X,
iris_y.astype(float),test_size=0.33, random_state=101)
###End code(approx 2 lines)

from sklearn.linear_model import LogisticRegression


from sklearn.metrics import classification_report

model = LogisticRegression()
model.fit(X_train, y_train.astype(int))

###Start code
y_pred = model.predict(X_test)
print(classification_report(y_test, y_clf))

###Start code here


class_report = classification_report(y_test, y_clf)
###End code(approx 2 to 3 lines)

###Start code here


from sklearn.metrics import precision_score
from sklearn.metrics import recall_score
precision = precision_score(y_test, y_pred,average="macro")
recall = recall_score(y_test, y_pred,average="macro")
###End code(approx 2 lines)
with open("Output.txt", "w") as text_file:
text_file.write("precision= %f\n" % precision)
text_file.write("recall= %f" % recall)

You might also like