机器学习基本算法的sklearn接口

sklearn python API

1、LinearRegression

from sklearn.linear_model import LinearRegression         # 线性回归 #
module = LinearRegression()
module.fit(x, y)
module.score(x, y)
module.predict(test)

2、LogisticRegression

from sklearn.linear_model import LogisticRegression         # 逻辑回归 #
module = LogisticRegression()
module.fit(x, y)
module.score(x, y)
module.predict(test)

3、KNN

from sklearn.neighbors import KNeighborsClassifier     #K近邻#
from sklearn.neighbors import KNeighborsRegressor
module = KNeighborsClassifier(n_neighbors=6)
module.fit(x, y)
predicted = module.predict(test)
predicted = module.predict_proba(test)

4、SVM

from sklearn import svm                                #支持向量机#
module = svm.SVC()
module.fit(x, y)
module.score(x, y)
module.predict(test)
module.predict_proba(test)

5、naive_bayes

from sklearn.naive_bayes import GaussianNB            #朴素贝叶斯分类器#
module = GaussianNB()
module.fit(x, y)
predicted = module.predict(test)

6、DecisionTree

from sklearn import tree                              #决策树分类器#
module = tree.DecisionTreeClassifier(criterion='gini')
module.fit(x, y)
module.score(x, y)
module.predict(test)

7、K-Means

from sklearn.cluster import KMeans                    #kmeans聚类#
module = KMeans(n_clusters=3, random_state=0)
module.fit(x, y)
module.predict(test)

8、RandomForest

from sklearn.ensemble import RandomForestClassifier  #随机森林#
from sklearn.ensemble import RandomForestRegressor
module = RandomForestClassifier()
module.fit(x, y)
module.predict(test)

9、GBDT

from sklearn.ensemble import GradientBoostingClassifier      #Gradient Boosting 和 AdaBoost算法#
from sklearn.ensemble import GradientBoostingRegressor
module = GradientBoostingClassifier(n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0)
module.fit(x, y)
module.predict(test)

10、PCA

from sklearn.decomposition import PCA              #PCA特征降维#
train_reduced = PCA.fit_transform(train)
test_reduced = PCA.transform(test)

你可能感兴趣的:(个人博客记录)