-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsklearn_bug.py
67 lines (37 loc) · 1.34 KB
/
sklearn_bug.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 6 21:25:09 2019
@author: arwen
"""
# In[] : bug 1 : scorer doesn't keep track of classes
from sklearn.model_selection import cross_validate
from sklearn.dummy import DummyClassifier
import numpy as np
X = np.random.randn(100,5)
y = np.array([0]*33 + [1]*33 + [2] * 33 + [4])
# remove modif
estimator = DummyClassifier()
res = cross_validate(estimator,X,y,scoring="neg_log_loss") # => raise error
res = cross_validate(estimator,X,1*(y == 0),scoring="brier_score_loss")
res = cross_validate(estimator,X,y,scoring="roc_auc")
res = cross_validate(estimator,X,1*(y == 0),scoring="roc_auc")
from sklearn.metrics import roc_auc_score, brier_score_loss, log_loss
#brier_score_loss_scorer
# In[] : bug 2
X = np.random.randn(100,5)
y = np.array([["a"] * 50 + ["b"]*50,["a"] * 50 + ["b"]*50]).T
from sklearn.ensemble import RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier
forest = RandomForestClassifier(n_estimators=10)
forest.fit(X,y)
yhat = forest.predict(X)
yhat_proba = forest.predict_proba(X)
forest.classes_
tree = DecisionTreeClassifier()
tree.fit(X,y)
yhat = tree.predict(X)
yhat_proba = tree.predict_proba(X)
tree.classes_
forest.fit(X,yd2[:,0])
yhat = forest.predict(X)
yhat_proba = forest.predict_proba(X)