Exemplo n.º 1
0
cv = KFold(n_splits=K, shuffle=True)

clf = GaussianNB()

scores = []

for i in range(100):

    features, labels = shuffle(features, labels)

    for train, test in cv.split(features):
        features_trn = features[train]
        features_test = features[test]

        labels_trn = [labels[item] for item in train]
        labels_test = [labels[item] for item in test]

        clf.fit(features_trn, labels_trn)
        result = clf.predict(features_test)
        score = accuracy_score(result, labels_test)
        scores.append(score)

print()
print(scores)
print('Average Score = ', round(sum(scores) / (len(scores)), 5))
print('Standard Deviation = ', numpy.std(scores))

ft1, lb1 = preprocess_ft_lbls_num()

print(ft1.shape)
Exemplo n.º 2
0
from sklearn.decomposition import PCA
from sklearn.feature_selection import SelectKBest
from sklearn.utils import shuffle
from sklearn.naive_bayes import GaussianNB
from sklearn.manifold import LocallyLinearEmbedding

from data.preprocess import features_preprocess, features_test_preprocess, labels_preprocess, labels_preprocess_num
from data.preprocess_2nd import preprocess_ft_lbls_num
from data.preprocess import ft_lbls_num

scores = []

embedding = LocallyLinearEmbedding(n_components=10)

(features1, labels1) = ft_lbls_num()
(features2, labels2) = preprocess_ft_lbls_num()

features1 = embedding.fit_transform(features1, labels1)
features2 = embedding.fit_transform(features2, labels2)

K = 5
cv = KFold(n_splits=K, shuffle=True)

features = numpy.concatenate((features1, features2))
labels = numpy.concatenate((labels1, labels2))

clf = svm.SVC(kernel='rbf')

for i in range(100):

    features1, labels1 = shuffle(features1, labels1)
Exemplo n.º 3
0
    #features_trn = selection.fit_transform(features_trn, labels_trn)
    #features_test =selection.transform(features_test)

    features_trn = pca.fit_transform(features_trn, labels_trn)
    features_test = pca.transform(features_test)

    clf.fit(features_trn, labels_trn)
    result = clf.predict(features_test)
    score = accuracy_score(result, labels_test)
    scores.append(score)
    vrnc = pca.explained_variance_ratio_
    variance_ratio1.extend(vrnc)

average_score = sum(scores) / K

(features, labels) = preprocess_ft_lbls_num()

scores = []

for train, test in cv.split(features):
    features_trn = features[train]
    features_test = features[test]

    labels_trn = labels[train]
    labels_test = labels[test]

    #features_trn = selection.fit_transform(features_trn, labels_trn)
    #features_test = selection.transform(features_test)

    features_trn = pca.fit_transform(features_trn, labels_trn)
    features_test = pca.transform(features_test)