机器学习实战-凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 3600088
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

(365)

  • (365)
文章存档

(8)

(130)

(155)

(50)

(22)

我的朋友
相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: python/ruby

2022-06-17 17:11:21

from sklearn.decomposition import pca

import numpy as np

from sklearn.svm import svc

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

from sklearn.decomposition import pca

from sklearn.metrics import accuracy_score

from sklearn.linear_model import logisticregression

from sklearn import datasets

from sklearn.model_selection import gridsearchcv

# 加载人脸数据 lfw->labled faces wild:野外标记的人脸

data = datasets.fetch_lfw_people(resize = 1, min_faces_per_person = 70)

data

# 进行数据的降维

pca = pca(n_components=0.95)

x_pca = pca.fit_transform(x)

display(x.shape,x_pca.shape)

svc = svc()

# c为惩罚系数(防止过拟合)kernel为核函数类型,tol为停止训练的误差值、精度

params = 跟单网gendan5.com{'c':np.logspace(-10,10,50),'kernel':['linear', 'poly', 'rbf', 'sigmoid'],'tol':[0.01,0.001,0.0001]}

gc = gridsearchcv(estimator = svc,param_grid = params,cv = 5)

gc.fit(x_pca,y)

gc.best_params_

svc = svc(c = 1.8420699693267165e-07,kernel='linear',tol = 0.001)

# 随机划分的

x_pca_train,x_pca_test,y_train,y_test, faces_train,faces_test = train_test_split(x_pca,y,faces)

svc.fit(x_pca_train,y_train)

print('训练数据得分:',svc.score(x_pca_train,y_train))

print('测试数据的得分:',svc.score(x_pca_test,y_test))

plt.figure(figsize=(5 * 2, 10 * 3))

for i in range(50):

    plt.subplot(10,5,i 1) # 子视图

    plt.imshow(faces_test[i],cmap = 'gray')

    plt.axis('off') # 刻度关闭

    # 贴上标签,并且对比实际数据和预测数据

    true_name = target_names[y_test[i]].split(' ')[-1]

    predict_name = target_names[y_pred[i]].split(' ')[-1]

    plt.title(f'true:{true_name}\npred:{predict_name}')

阅读(5141) | 评论(0) | 转发(0) |
1

上一篇:

下一篇:

给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图