注: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)
时间: 2024-10-14 03:06:11