一、安装sklearn库
首先安装pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
下载对应库
https://pypi.org/project/easy-sklearn/#files
解压,然后进入解压后的目录
pip install easy_sklearn
二、执行以下脚本
from sklearn import tree
feature = [[178, 1], [155, 0], [177, 0], [165, 0], [169, 1], [160, 0]]
label = ['male', 'female', 'male', 'female', 'male', 'female']
clf = tree.DecisionTreeClassifier()
clf = clf.fit(feature, label)
clf.predict([[158, 0], [172, 1]])
三、保存和加载
保存
from sklearn.externals import joblib
joblib.dump(clf, "juece_model.m")
加载
from sklearn.externals import joblib
clf = joblib.load("juece_model.m")
clf.predict([[158, 0], [172, 1]])
转载于:https://blog.51cto.com/204222/2312946