使用sklearn简单粗暴对iris数据做分类

注:1、每一个模型都没有做数据处理

      2、调用方式都是一样的»»»  引入model → fit数据 → predict,后面只记录导入模型语句。

导入数据:

from sklearn import datasets
iris = datasets.load_iris()
print "The iris' target names: ",iris.target_names
x = iris.data
y = iris.target

线性回归:

from sklearn import linear_model
linear = linear_model.LinearRegression()
linear.fit(x,y)
print "linear's score: ",linear.score(x,y)
linear.coef_       #系数
linear.intercept_  #截距
print "predict: ",linear.predict([[7,5,2,0.5],[7.5,4,7,2]])

logistic回归:

from sklearn import linear_model
logistic = linear_model.LogisticRegression()

决策树:

from sklearn import tree
tree = tree.DecisionTreeClassifier(criterion='entropy')   # 可选Gini、Information Gain、Chi-square、entropy

支持向量机:

from sklearn import svm
svm = svm.SVC()

朴素贝叶斯:

from sklearn import naive_bayes
bayes = naive_bayes.GaussianNB()

KNN:

from sklearn import neighbors
KNN = neighbors.KNeighborsClassifier(n_neighbors = 3)
posted @ 2016-10-06 21:17  fangqiushun  阅读(6988)  评论(1编辑  收藏  举报