机器学习算法实战案例
1、svm算法
from sklearn.svm import SVC
svm = SVC(kernel='rbf', random_state=0, gamma=0.2, C=1.0)
svm.fit(featureListArray)
pred = svm.predict(featureListArray)
print(pred)
2、KMeans算法
>>> from sklearn.cluster import KMeans
>>> import numpy as np
>>> X = np.array([[1, 2], [1, 4], [1, 0],
... [4, 2], [4, 4], [4, 0]])
>>> kmeans = KMeans(n_clusters=2, random_state=0).fit(X)
>>> kmeans.labels_
array([0, 0, 0, 1, 1, 1], dtype=int32)
>>> kmeans.predict([[0, 0], [4, 4]])
array([0, 1], dtype=int32)
>>> kmeans.cluster_centers_
array([[1., 2.],
[4., 2.]])
fit(X[, y, sample_weight])Compute k-means clustering.fit_predict(X[, y, sample_weight])Compute cluster centers and predict cluster index for each sample.fit_transform(X[, y, sample_weight])Compute clustering and transform X to cluster-distance space.get_params([deep])Get parameters for this estimator.predict(X[, sample_weight])Predict the closest cluster each sample in X belongs to.score(X[, y, sample_weight])Opposite of the value of X on the K-means objective.set_params(**params)Set the parameters of this estimator.transform(X)Transform X to a cluster-distance space.3、GMM聚类
from sklearn import mixture
clf = mixture.GaussianMixture(n_components=2, covariance_type='full')
clf.fit(featureListArray)
pred = clf.predict(featureListArray)
print(pred)
4、One-svm
# # TODO: 异常检测 = one-svm / SVDD /...
# print()
# print("异常检测...")
# print("model training...")
# # 定义 OneClassSvm
# clf = svm.OneClassSVM(nu=0.5, kernel="rbf", gamma=0.1)
# # OneClassSVM 模型训练
# clf.fit(newFeaturenArray)
#
# # # 保存 One-SVM 模型
# if not os.path.exists('model/svm'):
# os.makedirs('model/svm')
# print("model saving...")
# joblib.dump(clf, 'model/svm/svm_clf.model')
网址:机器学习算法实战案例 https://www.yuejiaxmz.com/news/view/64007
相关内容
博弈论+机器学习=?机器学习(七):提升(boosting)方法
职场生存法则:策略与实战案例分析
算法在身边——学习算法从妈妈的菜谱开始
计算机学习心得体会(精选9篇)
计算机组装与维护
计算机维护实习报告(46篇)
计算机硬件日常维护范例6篇
学生心理辅导案例范文
司法部发布贯彻实施法律援助法典型案例