zoukankan      html  css  js  c++  java
  • scikit-learn

    资料:http://scikit-learn.org/dev/documentation.html


    因为数学建模的关系,所以才临时了解了Python的一个开源项目 scikit-learn,

    有很多东西没有弄懂,以后补充吧

    写的第一个测试代码:

    import numpy as np
    import sys
    sys.stdout = open('out.txt', 'w');
    from sklearn.ensemble import RandomForestClassifier
    f = open('train1.txt', 'r')
    
    data = np.loadtxt(f)
    X = data[:, :-1]
    y = data[:, -1]
    
    from sklearn import cross_validation
    # X = np.array([[1, 2], [3, 4], [1, 2], [3, 4]])
    # y = np.array([1, 2, 3, 4])
    kf = cross_validation.KFold(99, n_folds=2)
    # print len(kf)
    # print(kf)
    
    clf = RandomForestClassifier(n_jobs=-1,n_estimators=10)
    for train_index, test_index in kf:
        #print("TRAIN:", train_index, "TEST:", test_index)
    
        X_train, X_test = X[train_index], X[test_index]
        y_train, y_test = y[train_index], y[test_index]
    
        clf = clf.fit(X_train, y_train)
        ans = clf.predict(X_test)
        print ans
        print y_test


  • 相关阅读:
    MySQL索引底层数据结构
    numpy和matplotlib读书笔记
    Python turtle学习笔记 #11933
    turtle笔记
    五角星绘制
    六角形绘制
    叠加等边三角形绘制
    什么叫方法签名
    Java编程思想 第七章
    类加载机制
  • 原文地址:https://www.cnblogs.com/Stomach-ache/p/3703143.html
Copyright © 2011-2022 走看看