#encoding=utf8
'''
微软的 interpret (ML) 尝试
'''
## 只是准备数据
import sklearn.model_selection #新版本 sklearn 可用
#import sklearn.cross_validation #旧版本 sklearn 可用
import sklearn.datasets
import sklearn.metrics
import autosklearn.classification
testdata = sklearn.datasets.load_breast_cancer()
X = testdata.data
y = testdata.target
#X_train, X_test, y_train, y_test = sklearn.cross_validation.train_test_split(X, y, test_size=.3, random_state=1) # 对应旧版本 sklearn
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(X, y, test_size=.3, random_state=1) # 对应新版本 sklearn
## 转入interpret处理
from interpret.glassbox import ExplainableBoostingClassifier
ebm = ExplainableBoostingClassifier()
ebm.fit(X_train, y_train)
ebm_global = ebm.explain_global()
## 保存本地文件(带图的html,打包了所需的js,所以挺大的)
import plotly.plotly
plotly.offline.plot(ebm_global.visualize())
'''
## 如果要结合Jupyter,在线使用 (需最新的 interpret)
from interpret import show
from interpret import set_show_addr, get_show_addr
set_show_addr(('127.0.0.1', 7001))
show(ebm_global) # Will run on 127.0.0.1 at port 7001
'''