-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtuto_2.py
More file actions
31 lines (24 loc) · 838 Bytes
/
tuto_2.py
File metadata and controls
31 lines (24 loc) · 838 Bytes
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
30
31
# Predict categories using Logistic Regression module
from sklearn import datasets, metrics
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
iris = datasets.load_iris()
print(iris.keys())
print(iris.target_names)
print(iris.feature_names)
print(iris.data[:3])
print(iris.target[:3])
print(iris.data.shape)
print(iris.target.shape)
X = iris.data
y = iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.15, random_state=42)
model = LogisticRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print(y_test)
print(predictions)
print(model.score(X_test, y_test))
print(metrics.accuracy_score(y_test, predictions))
print(metrics.classification_report(y_test, predictions))
print(metrics.confusion_matrix(y_test, predictions))