当前位置: 首页>>代码示例>>Python>>正文


Python RandomForestClassifier.fit方法代码示例

本文整理汇总了Python中sklearn.ensemble.forest.RandomForestClassifier.fit方法的典型用法代码示例。如果您正苦于以下问题:Python RandomForestClassifier.fit方法的具体用法?Python RandomForestClassifier.fit怎么用?Python RandomForestClassifier.fit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.ensemble.forest.RandomForestClassifier的用法示例。


在下文中一共展示了RandomForestClassifier.fit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: enemy_detection_clf

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
def enemy_detection_clf():

    chars = np.array(['warrior', 'warlock', 'mage', 'druid', 'rogue', 'shaman', 'paladin', 'priest', 'hunter'])
    data = []
    target = []
    for c in chars:
        p = path('images/character/new/black')
        for f in os.listdir(p+'/'+c):
            img = Image.open(p+'/'+c+'/'+f)
            w, h = img.size
            pixel = img.load()
            tmp = []
            for y in range(h):
                for x in range(w):
                    tmp.append(np.float(pixel[x,y] / 255))
            target.append(np.str(c))
            data.append(np.array(tmp))
    data = np.array(data)
    #image = data.view()
    #image.shape = (-1, 22, 30)
    #clf = svm.SVC(gamma = 0.001)
    clf = RandomForestClassifier()
    clf.fit(data, target)
    
    return clf
开发者ID:Emsibil,项目名称:Bachelor,代码行数:27,代码来源:Ba.py

示例2: Random_Forest

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
def Random_Forest(x_train, Y_train,n_estimators=10, criterion='gini', max_depth=None, min_samples_split=2,
                  min_samples_leaf=1, max_features='auto', bootstrap=True, oob_score=False, n_jobs=1, 
                  random_state=None, verbose=0, min_density=None, compute_importances=None, *args):
    clf = RandomForestClassifier()
    clf.fit(x_train,Y_train)
    
    return clf
开发者ID:setman85,项目名称:GA_homework,代码行数:9,代码来源:randforest.py

示例3: rforest_classify

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
def rforest_classify(X,Y):
	#clf = RandomForestClassifier(criterion='gini',max_features=7,n_estimators=100,n_jobs=3,min_samples_leaf=5)

	clf = RandomForestClassifier(n_estimators=500, \
			criterion='entropy', max_depth=None, min_samples_split=2, min_samples_leaf=1 \
                ,max_features='auto', bootstrap=False, oob_score=False, n_jobs=-1, min_density=None)
	clf.fit(X,Y)
	return clf
开发者ID:kalpanki,项目名称:pp,代码行数:10,代码来源:models.py

示例4: train_rf

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
def train_rf(train_vec, train_label):
    from sklearn.ensemble.forest import RandomForestClassifier as RFC
    # rfrclf = RFR(n_estimators=1001)
    # rfrclf.fit(train_vec, train_label)
    # print rfrclf.feature_importances_
    trfclf = RFC(n_estimators=1001)
    trfclf.fit(train_vec, train_label)
    # print rfclf.feature_importances_
    return trfclf
开发者ID:JayveeHe,项目名称:OpinionRankProject,代码行数:11,代码来源:amazon_process.py

示例5: main

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
def main(args):

    if args.analyse != None:
        train_data_x, test_data_x,train_data_y, test_data_y  = process_data(args.analyse)

        RT = RandomForestClassifier(n_estimators=100)
        RT.fit(train_data_x, train_data_y)
        print RT.score(test_data_x, test_data_y)

    return
开发者ID:rjgsousa,项目名称:sentiment_analysis,代码行数:12,代码来源:main.py

示例6: my_digits

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
def my_digits():
    digits = _data()
    
    n_samples = len(digits.images)
    datas = digits.images.reshape((n_samples, -1))

    classifier = RandomForestClassifier()
    classifier.fit(datas, digits.target)
    
    return classifier
开发者ID:Emsibil,项目名称:Bachelor,代码行数:12,代码来源:Ba.py

示例7: RandomForestClassifer

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
 def RandomForestClassifer(self):
     
     '''
     Function to do RandomForest Classifer.
     '''
     train_Array = self.titanic_train_frame.values
     self.test_Array = self.titanic_test_frame.values
     randomForest = RandomForestClassifier(n_estimators = 100, n_jobs = -1)
     randomForest.fit(train_Array[0::,1::],train_Array[0::,0])
     self.predicted_probability = randomForest.predict(self.test_Array[0::,0::])
     self.predicted_probability_list = self.predicted_probability.tolist()
开发者ID:malaikannan,项目名称:Kaggle_TitanicPredictionChallenge,代码行数:13,代码来源:TitanicPrediction_LogisticRegression.py

示例8: do_training

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
def do_training(processed_train_csv_file):
    ## Processed train samples reading
    # read saved processed train samples from the given csv file
    processed_train_samples = pd.read_csv(processed_train_csv_file)

    # inf to nan
    processed_train_samples = processed_train_samples.replace([np.inf, -np.inf], np.nan)
    # nan to 0
    processed_train_samples = processed_train_samples.fillna(value=0)

    processed_train_samples_index_lst = processed_train_samples.index.tolist()
    # 之前排过序,这里shuffle一下,效果更好
    random.shuffle(processed_train_samples_index_lst)

    # organize new train samples and targets
    shuffled_train_samples = processed_train_samples.ix[processed_train_samples_index_lst]
    col_names = shuffled_train_samples.columns.tolist()
    col_names.remove("booking_bool")
    features = shuffled_train_samples[col_names].values
    labels = shuffled_train_samples['booking_bool'].values

    # Model training
    # 1 Random Forest Classifier

    print("Training Random Forest Classifier")
    rf_classifier = RandomForestClassifier(n_estimators=150,
                                           verbose=2,
                                           n_jobs=-1,
                                           min_samples_split=10)
    rf_classifier.fit(features, labels)

    print("Saving the Random Forest Classifier")
    data_io.save_model(rf_classifier, model_name='rf_classifier.pkl')

    # 2 Gradient Boosting Classifier
    print("Gradient Boosting  Classifier")
    gb_classifier = GradientBoostingClassifier(n_estimators=150,
                                               verbose=2,
                                               learning_rate=0.1,
                                               min_samples_split=10)
    gb_classifier.fit(features, labels)
    print("Saving the Gradient Boosting  Classifier")
    data_io.save_model(gb_classifier, model_name='gb_classifier.pkl')

    # 3 SGD Classifier
    print("SGD Classifier")
    sgd_classifier = SGDClassifier(loss="modified_huber", verbose=2,
                                   n_jobs=-1)
    sgd_classifier.fit(features, labels)

    print("saved the SGD Classifier")
    data_io.save_model(sgd_classifier, model_name='sgd_classifier.pkl')
开发者ID:gssgch,项目名称:gssgML,代码行数:54,代码来源:training_prediction.py

示例9: RF

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
def RF(pth):
     train_desc=np.load(pth+'/training_features.npy')
     nbr_occurences = np.sum( (train_desc > 0) * 1, axis = 0)
     idf = np.array(np.log((1.0*len(image_paths)+1) / (1.0*nbr_occurences + 1)), 'float32')

# Scaling the words
     stdSlr = StandardScaler().fit(train_desc)
     train_desc = stdSlr.transform(train_desc)
     modelRF=RandomForestClassifier(n_estimators=10,
                                    max_depth=5,max_features=1,random_state=0)
     modelRF.fit(train_desc,np.array(train_labels))
     joblib.dump((modelRF, img_classes, stdSlr), pth+"/rf-bof.pkl", compress=3) 
     test(pth, "rf-")
开发者ID:fengxinhe,项目名称:DeviceManager,代码行数:15,代码来源:Algro.py

示例10: try_model

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
def try_model(train):
    print(train.shape)
    features = ["phone_brand", "device_model",  "event_count", "action_radius_max", "medianTime", "minTime", "maxTime", "weekday", "appcounts1"]
    encoder = LabelEncoder()
    train["group"] = encoder.fit_transform(train["group"].values)
    
    rf = RandomForestClassifier(n_estimators=50, max_depth=15, max_features=6, bootstrap=True, n_jobs=4, random_state=2016, class_weight=None)
    
    rf.fit(train[features].values, train["group"].values)
    feature_importance(rf, features)
    
    skf = StratifiedKFold(train["group"].values, n_folds=5, shuffle=True, random_state=2016)
    scores = cross_val_score(rf, train[features].values, train["group"].values, scoring="log_loss", cv=skf, n_jobs=1)
    print(scores)
    print("RF Score: %0.5f" %(-scores.mean())) # RF Score: 2.39884
开发者ID:homoroselaps,项目名称:KaggleMobileUserDemo,代码行数:17,代码来源:create_features.py

示例11: just_pred

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
def just_pred(x, y):
    xlen = len(x)
    i = range(xlen)
    np.random.shuffle(i)
    trainpct = 0.7
    trainlen = int(trainpct * xlen)
    testlen = xlen - trainlen
    xtrain = x.ix[:trainlen,:]
    ytrain = y.ix[:trainlen]
    xtest = x.ix[trainlen:,:]
    ytest = y.ix[trainlen:]
    rf = RandomForestClassifier()
    rf.fit(xtrain, ytrain)
    ypred = rf.predict(xtest)
    return ytest, ypred
开发者ID:coreyabshire,项目名称:color-names,代码行数:17,代码来源:pscvread.py

示例12: crossval

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
def crossval(x, y, k=5):
    for i in range(k):
        i = range(len(X))
        np.random.shuffle(i)
        xlen = len(x)
        trainpct = 0.7
        trainlen = int(trainpct * xlen)
        testlen = xlen - trainlen
        xtrain = x.ix[:trainlen,:]
        ytrain = y.ix[:trainlen]
        xtest = x.ix[trainlen:,:]
        ytest = y.ix[trainlen:]
        rf = RandomForestClassifier()
        rf.fit(xtrain, ytrain)
        ypred = rf.predict(xtest)
        print ypred
开发者ID:coreyabshire,项目名称:color-names,代码行数:18,代码来源:pscvread.py

示例13: test_RandomForest

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
    def test_RandomForest(self):
        X = [[0, 1], [1, 1]]
        Y = [0, 1]

        regression = RandomForestClassifier(n_estimators=10)
        regression = regression.fit(X, Y)
        regression.predict_proba(X)
开发者ID:lgadawski,项目名称:spdb-driver-telematics,代码行数:9,代码来源:test_driver_functions.py

示例14: model_pred

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
def model_pred(trainX,trainY,testX,model_type):
    if model_type == "rf":
        clf = RandomForestClassifier(n_estimators = 500,n_jobs = 20)
        clf.fit(trainX,trainY)
        pred = clf.predict(testX)
    if model_type == "gbdt":
        clf = GradientBoostingClassifier(n_estimators=6,learning_rate=0.9,random_state=0)
        clf.fit(trainX,trainY)
        pred = clf.predict(testX)
    if model_type == "fusion":
        prob = np.zeros(len(testX))
        params = [100,200,300,400,500]
        for param in params:
            clf = RandomForestClassifier(n_estimators = param,n_jobs = 20,bootstrap=True)
            clf.fit(trainX,trainY)
            prob += clf.predict(testX)
        '''
        params = [1,2,3,4,5,6,7,8,9,10]
        for param in params:
            clf = GradientBoostingClassifier(n_estimators=param,learning_rate=0.9,random_state=0)
            clf.fit(trainX,trainY)
            prob += clf.predict(testX)
        '''
        pred = list(prob >= 3)
    print "the pos rate is:",float(sum(pred))/len(pred)
    return pred
开发者ID:tearf001,项目名称:ucloud,代码行数:28,代码来源:model2.py

示例15: initDecTrees

# 需要导入模块: from sklearn.ensemble.forest import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import fit [as 别名]
 def initDecTrees(self, path):
     for filename in os.listdir(path):
         if filename=='train.csv':
             with open(os.path.join(path,filename)) as infile:
                 f = csv.reader(infile)
                 aux = f.next()  # skip the header
                 x = []
                 y = []
                 for line in f:
                     if size(line) > 1:
                         if self.option == 1:
                             data = [converter(line[2]), converter(line[3]), converter(line[4]), converter(line[7]), converter(line[9])]
                             y.append(converter(line[6]))
                             x.append(data)
                         elif self.option == 2:
                             auxDeputy = fetchDeputyParty(line[2])
                             data = [converter(line[2]), converter(line[3]), converter(line[4]), converter(line[7]), converter(line[9]), encodeParty(auxDeputy['party']), encodeState(auxDeputy['state'])]
                             y.append(converter(line[6]))
                             x.append(data)
             clf = RandomForestClassifier(n_estimators=5)
             clf.fit(x, y)
             return clf
开发者ID:ignasiet,项目名称:LabIA,代码行数:24,代码来源:portfolioClassificator.py


注:本文中的sklearn.ensemble.forest.RandomForestClassifier.fit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。