美文网首页
K-means聚类算法用于手写体数字识别

K-means聚类算法用于手写体数字识别

作者: lzp12138 | 来源:发表于2017-06-01 02:15 被阅读0次

    import numpy as np

    import matplotlib as plt

    import pandas as pd

    digits_train=pd.read_csv('http://archive.ics.uci.edu/ml/machine-learning-databases/optdigits/optdigits.tra',header=None)

    digits_test=pd.read_csv('http://archive.ics.uci.edu/ml/machine-learning-databases/optdigits/optdigits.tes',header=None)

    X_train=digits_train[np.arange(64)]

    y_train=digits_train[64]

    X_test=digits_test[np.arange(64)]

    y_test=digits_test[64]

    from sklearn.cluster import KMeans

    kmeans=KMeans(n_clusters=10)

    kmeans.fit(X_train)

    y_pred=kmeans.predict(X_test)

    from sklearn import metrics

    print(metrics.adjusted_rand_score(y_test,y_pred))

    相关文章

      网友评论

          本文标题:K-means聚类算法用于手写体数字识别

          本文链接:https://www.haomeiwen.com/subject/tbdsfxtx.html