Rushi
commited on
Commit
·
d8485be
1
Parent(s):
4e999cc
Upload LogisticRegression.py
Browse files- LogisticRegression.py +43 -0
LogisticRegression.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sklearn.metrics import (
|
| 2 |
+
|
| 3 |
+
ConfusionMatrixDisplay,
|
| 4 |
+
|
| 5 |
+
confusion_matrix,
|
| 6 |
+
|
| 7 |
+
accuracy_score,
|
| 8 |
+
|
| 9 |
+
f1_score
|
| 10 |
+
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
import tempfile
|
| 14 |
+
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
|
| 17 |
+
from sklearn.datasets import load_iris
|
| 18 |
+
|
| 19 |
+
from sklearn.linear_model import LogisticRegression
|
| 20 |
+
|
| 21 |
+
from skops import card
|
| 22 |
+
|
| 23 |
+
X, y = load_iris(return_X_y=True)
|
| 24 |
+
|
| 25 |
+
model = LogisticRegression(solver="liblinear", random_state=0).fit(X, y)
|
| 26 |
+
|
| 27 |
+
model_card = card.Card(model)
|
| 28 |
+
|
| 29 |
+
model_card.metadata.license = "mit"
|
| 30 |
+
|
| 31 |
+
y_pred = model.predict(X)
|
| 32 |
+
|
| 33 |
+
model_card.add_metrics(**{
|
| 34 |
+
|
| 35 |
+
"accuracy": accuracy_score(y, y_pred),
|
| 36 |
+
|
| 37 |
+
"f1 score": f1_score(y, y_pred, average="micro"),
|
| 38 |
+
|
| 39 |
+
})
|
| 40 |
+
|
| 41 |
+
model_card.add_plot(confusion_matrix="confusion_matrix.png")
|
| 42 |
+
|
| 43 |
+
model_card.save("README2.md")
|