‘‘‘#19%
from sklearn import neighbors
knn=neighbors.KNeighborsClassifier(n_neighbors=75, leaf_size=51, weights=‘distance‘,p=2)
knn.fit(traindata, trainlabel)
predict=knn.predict(testdata)‘‘‘
‘‘‘#这个不行
from sklearn.neural_network import MLPClassifier
import numpy as np
traindata = np.array(traindata)#TypeError: cannot perform reduce with flexible type
traindata = traindata.astype(float)
trainlabel = np.array(trainlabel)
trainlabel = trainlabel.astype(float)
testdata=np.array(testdata)
testdata = testdata.astype(float)
model=MLPClassifier(activation=‘relu‘, alpha=1e-05, batch_size=‘auto‘,
beta_1=0.9, beta_2=0.999, early_stopping=False,
epsilon=1e-08, hidden_layer_sizes=(5, 2), learning_rate=‘constant‘,
learning_rate_init=0.001, max_iter=200, momentum=0.9,
nesterovs_momentum=True, power_t=0.5, random_state=1, shuffle=True,
solver=‘lbfgs‘, tol=0.0001, validation_fraction=0.1, verbose=False,
warm_start=False)
model.fit(traindata, trainlabel)
predict = model.predict(testdata)‘‘‘
‘‘‘#19%
from sklearn.tree import DecisionTreeClassifier
model=DecisionTreeClassifier(class_weight=‘balanced‘,max_features=68,splitter=‘best‘,random_state=5)
model.fit(traindata, trainlabel)
predict = model.predict(testdata)
这个不行
from sklearn.naive_bayes import MultinomialNB
clf = MultinomialNB(alpha=0.052).fit(traindata, trainlabel)
#clf.fit(traindata, trainlabel)
predict=clf.predict(testdata)‘‘‘
‘‘‘17%
from sklearn.svm import SVC
clf = SVC(C=150,kernel=‘rbf‘, degree=51, gamma=‘auto‘,coef0=0.0,shrinking=False,probability=False,tol=0.001,cache_size=300, class_weight=None,verbose=False,max_iter=-1,decision_function_shape=None,random_state=None)
clf.fit(traindata, trainlabel)
predict=clf.predict(testdata)‘‘‘
‘‘‘0.5%
from sklearn.naive_bayes import GaussianNB
import numpy as np
gnb = GaussianNB()
traindata = np.array(traindata)#TypeError: cannot perform reduce with flexible type
traindata = traindata.astype(float)
trainlabel = np.array(trainlabel)
trainlabel = trainlabel.astype(float)
testdata=np.array(testdata)
testdata = testdata.astype(float)
predict = gnb.fit(traindata, trainlabel).predict(testdata)‘‘‘
‘‘‘16%
from sklearn.naive_bayes import BernoulliNB
import numpy as np
gnb = BernoulliNB()
traindata = np.array(traindata)#TypeError: cannot perform reduce with flexible type
traindata = traindata.astype(float)
trainlabel = np.array(trainlabel)
trainlabel = trainlabel.astype(float)
testdata=np.array(testdata)
testdata = testdata.astype(float)
predict = gnb.fit(traindata, trainlabel).predict(testdata)‘‘‘
from sklearn.ensemble importRandomForestClassifier
forest= RandomForestClassifier(n_estimators=500,random_state=5, warm_start=False, min_impurity_decrease=0.0,min_samples_split=15) #生成随机森林多分类器
predict= forest.fit(traindata, trainlabel).predict(testdata)