#根据身高体重训练 预测男生还是女生#1数据制作rand1 = np.array([[155,48],[159,50],[164,53],[168,56],[172,60]])rand2 = np.array([[152,53],[156,55],[160,56],[172,64],[176,65]])label = np.array([[0],[0],[0],[0],[0],[1],[1],[1],[1],[1]])data = np.vstack((rand1,rand2))data = np.array(data,dtype = ‘float32‘)print(data)#2训练svm = cv2.ml.SVM_create()#ml 机器学习模块#属性设置svm.setType(cv2.ml.SVM_C_SVC)svm.setKernel(cv2.ml.SVM_LINEAR)svm.setC(0.01)#训练result = svm.train(data,cv2.ml.ROW_SAMPLE,label)#预测pt_data = np.vstack([[167,55],[162,57]])pt_data = np.array(pt_data,dtype = ‘float32‘)print(pt_data)(par1,par2) = svm.predict(pt_data)print(par2)
原文地址:https://www.cnblogs.com/lzq116/p/11804139.html
时间: 2024-10-21 08:37:18