首页 > 代码库 > 使用sklearn简单粗暴对iris数据做分类

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

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

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

导入数据:

from sklearn import datasetsiris = datasets.load_iris()print "The iris‘ target names: ",iris.target_namesx = iris.datay = iris.target

线性回归:

from sklearn import linear_modellinear = 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_modellogistic = linear_model.LogisticRegression()

决策树:

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

支持向量机:

from sklearn import svmsvm = svm.SVC()

朴素贝叶斯:

from sklearn import naive_bayesbayes = naive_bayes.GaussianNB()

KNN:

from sklearn import neighborsKNN = neighbors.KNeighborsClassifier(n_neighbors = 3)

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