Kaggle实战:Digit Recognizer[Random Forest算法]

说明

正确率:94.014%,没有KNN效果好(96.800%),个人估计经过调参效果应该有所提升

代码

import pandas as pd

data = pd.read_csv("train.csv")
data.head()

dataset = data.iloc[:,1:]   #提取特征
dataset.head()

label = data.iloc[:,0] #提取标签
label.head()

dataset.describe()

label.describe()

from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier(oob_score=True,random_state=10)
rf.fit(dataset, label)

test = pd.read_csv("test.csv")
pred = rf.predict(test)

import numpy as np
a = pd.Series(pred)
b = pd.Series(np.arange(1,28000))
c = pd.DataFrame([a,b])
d = pd.DataFrame(c.T)
d.to_csv("result.csv")

你可能感兴趣的:(机器学习)