眼底血管分割训练函数(SVM,Adaboost)
# -*- coding: utf-8 -*- import numpy as np from sklearn import svm from sklearn.model_selection import train_test_split from sklearn.externals import joblib from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import zero_one_loss from sklearn.ensemble import AdaBoostClassifier path = u'extract.txt' data0 = np.loadtxt(path,dtype = str,delimiter = ' ') data = np.array( [[row[i] for i in range(0, 8) if i != 7] for row in data0] )#del the last col of the array x = data[:,(1,2,3,4,5,6)] y = data[:,0] x = np.uint8(x) y = np.uint8(y) #y[y[:]==255]=1 #y[y[:]==0]=-1 #x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=1, train_size=0.6) #clf = svm.SVC() """ n_estimators = 800 learning_rate = 1.0 dt_stump = DecisionTreeClassifier(max_depth=12, min_samples_leaf=1) dt_stump.fit(x, y) ada_discrete = AdaBoostClassifier( base_estimator=dt_stump, learning_rate=learning_rate, n_estimators=n_estimators, algorithm="SAMME") ada_discrete.fit(x, y) """ clf = svm.SVC(C=0.8, kernel='rbf', gamma=20, decision_function_shape='ovr') clf.fit(x, y.ravel()) joblib.dump(clf, "train_model.m")