Kaggle实战:Digit Recognizer[KNN算法]

Digit Recognizer

  • 链接地址:https://www.kaggle.com/c/digit-recognizer
  • 比赛内容:识别手写体
  • 采用算法:knn
  • 比赛成绩:正确率96.800%

Python代码

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 import neighbors
knn = neighbors.KNeighborsClassifier(n_neighbors=5)  
knn.fit(dataset, label)  
test = pd.read_csv("test.csv")
pred = knn.predict(test)
print(pred)
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")

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