原文傳送門:sklearn包含的常用演算法
文章列出了sklearn模組中常用的演算法及呼叫方法,部分生僻的未列出(對我來說算生僻的),如果有寫的不對的地方請指出。
參考資料來自sklearn官方**:
總的來說,sklearn可實現的函式或功能可分為以下幾個方面:
二次判別分析(qda)
>>> from sklearn.discriminant_analysis import quadraticdiscriminantanalysis
>>> qda = quadraticdiscriminantanalysis(store_covariances=true)
支援向量機(svm)
>>> from sklearn import svm
>>> clf = svm.svc()
knn演算法
>>> from sklearn import neighbors
>>> clf = neighbors.kneighborsclassifier(n_neighbors, weights=weights)
神經網路(nn)
>>> from sklearn.neural_network import mlpclassifier
>>> clf = mlpclassifier(solver='lbfgs', alpha=1e-5,
... hidden_layer_sizes=(5, 2), random_state=1)
樸素貝葉斯演算法(***** bayes)
>>> from sklearn.*****_bayes import gaussiannb
>>> gnb = gaussiannb()
決策樹演算法(decision tree)
>>> from sklearn import tree
>>> clf = tree.decisiontreeclassifier()
整合演算法(ensemble methods)
bagging
>>> from sklearn.ensemble import baggingclassifier
>>> from sklearn.neighbors import kneighborsclassifier
>>> bagging = baggingclassifier(kneighborsclassifier(),
... max_samples=0.5, max_features=0.5)
隨機森林(random forest)
>>> from sklearn.ensemble import randomforestclassifier
>>> clf = randomforestclassifier(n_estimators=10)
adaboost
>>> from sklearn.ensemble import adaboostclassifier
>>> clf = adaboostclassifier(n_estimators=100)
gbdt(gradient tree boosting)
>>> from sklearn.ensemble import gradientboostingclassifier
>>> clf = gradientboostingclassifier(n_estimators=100, learning_rate=1.0,
... max_depth=1, random_state=0).fit(x_train, y_train)
嶺回歸(ridge regression)
>>> from sklearn import linear_model
>>> reg = linear_model.ridge (alpha = .5)
核嶺回歸(kernel ridge regression)
>>> from sklearn.kernel_ridge import kernelridge
>>> kernelridge(kernel='rbf', alpha=0.1, gamma=10)
支援向量機回歸(svr)
>>> from sklearn import svm
>>> clf = svm.svr()
套索回歸(lasso)
>>> from sklearn import linear_model
>>> reg = linear_model.lasso(alpha = 0.1)
彈性網路回歸(elastic net)
>>> from sklearn.linear_model import elasticnet
>>> regr = elasticnet(random_state=0)
貝葉斯回歸(bayesian regression)
>>> from sklearn import linear_model
>>> reg = linear_model.bayesianridge()
邏輯回歸(logistic regression)
>>> from sklearn.linear_model import logisticregression
>>> clf_l1_lr = logisticregression(c=c, penalty='l1', tol=0.01)
>>> clf_l2_lr = logisticregression(c=c, penalty='l2', tol=0.01)
穩健回歸(robustness regression)
>>> from sklearn import linear_model
>>> ransac = linear_model.ransacregressor()
多項式回歸(polynomial regression——多項式基函式回歸)
>>> from sklearn.preprocessing import polynomialfeatures
>>> poly = polynomialfeatures(degree=2)
>>> poly.fit_transform(x)
高斯過程回歸(gaussian process regression)
偏最小二乘回歸(pls)
>>> from sklearn.cross_decomposition import plscanonical
>>> plscanonical(algorithm='nipals', copy=true, max_iter=500, n_components=2,scale=true, tol=1e-06)
典型相關分析(cca)
>>> from sklearn.cross_decomposition import cca
>>> cca = cca(n_components=2)
kmeans演算法
>>> from sklearn.cluster import kmeans
>>> kmeans = kmeans(init='k-means++', n_clusters=n_digits, n_init=10)
層次聚類(hierarchical clustering)——支援多種距離
>>> from sklearn.cluster import agglomerativeclustering
>>> model = agglomerativeclustering(linkage=linkage,
connectivity=connectivity, n_clusters=n_clusters)
核函主成分(kernal pca)
>>> from sklearn.decomposition import kernelpca
>>> kpca = kernelpca(kernel="rbf", fit_inverse_transform=true, gamma=10)
因子分析(factor analysis)
>>> from sklearn.decomposition import factoranalysis
>>> fa = factoranalysis()
潛在語義分析(latent semantic analysis)
不具體列出函式,只說明提供的功能
Python中常用的包 sklearn
樸素貝葉斯 該方法的任務是還原訓練樣本資料的分布密度,在多分類中有很好的效果 樸素貝葉斯分類的優缺點 優點 1 演算法邏輯簡單,易於實現 演算法思路很簡單,只要使用貝葉斯公式轉化一下即可!2 分類過程中時空開銷小 假設特徵相互獨立,只會涉及到二維儲存 缺點 理論上,樸素貝葉斯模型與其他分類方法相比具...
sklearn 常用屬性與功能
from sklearn import datasets from sklearn.linear model import linearregression loaded data datasets.load boston data x loaded data.data data y loaded ...
基於sklearn實現Bagging演算法(pyth
圖中a,b,c,d,e,f列表示六個特徵,g表示樣本標籤。每一行資料即為乙個樣本的六個特徵和標籤。實現bagging演算法的 如下 from sklearn.ensemble import baggingclassifier from sklearn.tree import decisiontree...