# -*- coding: utf-8 -*-
"""
Created on Mon Aug 21 12:51:31 2017
@author: Administrator
"""
from sklearn.ensemble import RandomForestClassifier
import pandas as pd
import numpy as np
import pandas as pd
import xgboost as xgb
from pandas import DataFrame
import matplotlib.pyplot as plt
## 读取训练集的数据
train_data = pd.read_table('X_train.txt',header=None,encoding='gb2312',delim_whitespace=True,index_col=0)
predict_data= pd.read_table('X_test.txt',header=None,encoding='gb2312',delim_whitespace=True,index_col=0)
train_label= pd.read_table('y_train.txt',header=None,encoding='gb2312',delim_whitespace=True,index_col=0)
predict_label= pd.read_table('y_test.txt',header=None,encoding='gb2312',delim_whitespace=True,index_col=0)
train_label=train_label.reset_index()-1
predict_label=predict_label.reset_index()-1
predict_label_column=list(predict_label.columns)
predict_label.rename(columns={predict_label_column[0]: 'label'}, inplace=True)
clf=RandomForestClassifier(n_jobs=3)
clf.fit(train_data, train_label)
ypred1=clf.predict(predict_data)
ypred1 = DataFrame(ypred1)
ypred1_column=list(ypred1.columns)
ypred1.rename(columns={ypred1_column[0]: 'label'}, inplace=True)
ac_middle=predict_label-ypred1
ac_middle_number=ac_middle[ac_middle['label']==0]
accurate=float(ac_middle_number.shape[0])/predict_label.shape[0]
对用的参数的调整:
http://blog.csdn.net/u012102306/article/details/52228516
参考的地址:
http://blog.csdn.net/lulei1217/article/details/49583287
http://www.cnblogs.com/downtjs/archive/2013/08/28/3288203.html