← 历史存档

这是原站讨论区的存档(快照时间 2018-03-12),只读。

数据挖掘-Warmup的学习资料

奥利奥 · 2016-03-28 18:16:02 · 数据挖掘-Warmup

关于数据挖掘-Warmup的学习资料的汇总

5 个回答

ikarienator · 2016-01-09 07:33:55

5行 Mathematica:

data = Import["adult.csv"];
data2 = Import["test.csv"];
data = Table[Drop[data[[i]], -1] -> data[[i]][[13]], {i, 1, Length[data]}];
classifier = Classify[data];
result = classifier[data2]

Classify支持下面几种方法:

  • "LogisticRegression"

  • "Markov"

  • "NaiveBayes"

  • "NearestNeighbors"

  • "NeuralNetwork"

  • "RandomForest"

  • "SupportVectorMachine"

它会自动选择一个方法。提交的准确率84.9%。

elf · 2016-01-09 20:44:08

自己造朴素贝叶斯轮子,85.3%。加上权重指数,87.7%

zzj · 2016-01-11 10:40:28

sklearn.naive_bayes

sklearn.neighbors

sklearn.feature_extraction

cainiaoli · 2016-03-18 11:39:11

R语言
MASS包下的
lda函数
stats包下的
predict函数
84%

cheyulin · 2016-10-21 11:14:40

  • 不知道为什么正确特别低 80.5%

  • 难道因为没有归一化?

import numpy as np

import re

from sklearn.naive_bayes import GaussianNB

training_arr = np.loadtxt('adult.txt', str, '#', ',')
testing_arr = np.loadtxt('adult_test.txt', str, '#', ',')

arr_x = np.ndarray(len(training_arr))
arr_y = np.ndarray(len(training_arr))


def find_index(my_literal, my_list):
    for i in range(0, len(my_list)):
        if my_literal == my_list[i]:
            return i;
    return -1;


work_type = ['Private', 'Self-emp-not-inc', 'Self-emp-inc', 'Federal-gov', 'Local-gov', 'State-gov', 'Without-pay',
             'Never-worked']

education_type = ['Bachelors', 'Some-college', '11th', 'HS-grad', 'Prof-school', 'Assoc-acdm', 'Assoc-voc', '9th',
                  '7th-8th', '12th', 'Masters', '1st-4th', '10th', 'Doctorate', '5th-6th', 'Preschool']

marry_type = ['Married-civ-spouse', 'Divorced', 'Never-married', 'Separated', 'Widowed', 'Married-spouse-absent',
              'Married-AF-spouse']

occupation_type = ['Tech-support', 'Craft-repair', 'Other-service', 'Sales', 'Exec-managerial',
                   'Prof-specialty', 'Handlers-cleaners', 'Machine-op-inspct', 'Adm-clerical', 'Farming-fishing',
                   'Transport-moving', 'Priv-house-serv', 'Protective-serv', 'Armed-Forces']

role_type = ['Wife', 'Own-child', 'Husband', 'Not-in-family', 'Other-relative', 'Unmarried']

race_type = ['White', 'Asian-Pac-Islander', 'Amer-Indian-Eskimo', 'Other', 'Black']

gender_type = ['Female', 'Male']

nationality_type = ['United-States', 'Cambodia', 'England', 'Puerto-Rico', 'Canada', 'Germany',
                    'Outlying-US(Guam-USVI-etc)', 'India', 'Japan', 'Greece', 'South', 'China', 'Cuba',
                    'Iran', 'Honduras', 'Philippines', 'Italy', 'Poland', 'Jamaica', 'Vietnam', 'Mexico', 'Portugal',
                    'Ireland', 'France', 'Dominican-Republic', 'Laos', 'Ecuador', 'Taiwan', 'Haiti', 'Columbia',
                    'Hungary', 'Guatemala', 'Nicaragua', 'Scotland', 'Thailand', 'Yugoslavia', 'El-Salvador',
                    'Trinadad&Tobago', 'Peru', 'Hong', 'Holand-Netherlands']

type_list = [work_type, education_type, marry_type, occupation_type, role_type, race_type, gender_type,
             nationality_type]


def transform(data_ele):
    data_ele = str(data_ele)
    nums_pat = re.compile('[0-9]+$')
    if nums_pat.match(data_ele):
        return int(data_ele)
    else:
        for ele_type in type_list:
            ret_val = find_index(data_ele, ele_type)
            if ret_val != -1:
                return ret_val
        return -1


arr_y = map(lambda ele: int(ele[12]), training_arr)
arr_x = map(lambda ele: map(lambda x: transform(x), ele[0:12]), training_arr)

testing_arr = map(lambda ele: map(lambda x: transform(x), ele[0:12]), testing_arr)

print 'arr_x len:' + str(len(arr_x))
print 'arr_y len:' + str(len(arr_y))

print arr_x[0]
print testing_arr[0]

clf = GaussianNB()
clf.fit(arr_x, arr_y)
res_arr = clf.predict(testing_arr)

print reduce(lambda x, y: str(x) + str(y), res_arr)