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


Python ExtraTreesClassifier.predict方法代码示例

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


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

示例1: crossVal

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
def crossVal(positions, X, y, missedYFile):
    outF = open(missedYFile, 'w')
    posArray = np.array(positions)
    # Split into training and test
    sss = StratifiedShuffleSplit(y, 4, test_size=0.1, random_state=442)
    cvRound = 0
    for train_index, test_index in sss:
        clf = ExtraTreesClassifier(n_estimators=300,
                                   random_state=13,
                                   bootstrap=True,
                                   max_features=20,
                                   min_samples_split=1,
                                   max_depth=8,
                                   min_samples_leaf=13,
                                   n_jobs=4
                                   )
        X_train, X_test = X[train_index], X[test_index]
        y_train, y_test = y[train_index], y[test_index]
        pos_test = posArray[test_index]

        clf = clf.fit(X_train, y_train)
        preds = clf.predict(X_test)
        metrics.confusion_matrix( y_test, preds )
        print( metrics.classification_report(y_test, clf.predict(X_test)) )
        for loc,t,p in zip(pos_test, y_test, preds):
            if t=='0' and p=='1':
                print >> outF, loc + '\t' + str(cvRound)
        cvRound += 1
    outF.close()
开发者ID:samesense,项目名称:snv_decision_tree,代码行数:31,代码来源:fairForestLimitFeatures.py

示例2: __init__

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
class Identifier:
	def __init__(self,grabable = set([]),clf = None):
		self.grabable = grabable #TODO if we care to, not used at the mo
		self.orb = orb = cv2.ORB(nfeatures = 1000)#,nlevels = 20, scaleFactor = 1.05)
		self.items = [ "champion_copper_plus_spark_plug", "cheezit_big_original","crayola_64_ct", "dove_beauty_bar", "elmers_washable_no_run_school_glue","expo_dry_erase_board_eraser", "feline_greenies_dental_treats","first_years_take_and_toss_straw_cups", "genuine_joe_plastic_stir_sticks","highland_6539_self_stick_notes", "kong_air_dog_squeakair_tennis_ball","kong_duck_dog_toy", "kong_sitting_frog_dog_toy", "kygen_squeakin_eggs_plush_puppies","mark_twain_huckleberry_finn", "mead_index_cards","mommys_helper_outlet_plugs","munchkin_white_hot_duck_bath_toy", "one_with_nature_soap_dead_sea_mud","oreo_mega_stuf", "paper_mate_12_count_mirado_black_warrior","rollodex_mesh_collection_jumbo_pencil_cup", "safety_works_safety_glasses", "sharpie_accent_tank_style_highlighters", "stanley_66_052" ]
		if not clf:
			print "Training new classifier"
			self.clf =ExtraTreesClassifier(min_samples_split = 1,n_jobs = -1,n_estimators = 150, class_weight = 'subsample')
			X = np.ascontiguousarray(joblib.load('labels.pkl'))
			Y = np.ascontiguousarray(joblib.load('features.pkl'), dtype = np.float64)
			Y = preprocessing.scale(Y)
			self.clf.fit(Y,X)
		else:
			self.clf = clf
	def identify(self,im,possibilites):
		if im is not None:
			kpTest, desTest = self.orb.detectAndCompute(im,None)
			pred = self.clf.predict(preprocessing.scale(np.array(desTest,dtype = np.float64)))
			c = Counter(pred)
			r = [(k,c[k]) for k in sorted(set(c.keys())&possibilites, key  = lambda k: c[k],reverse = True)]
			if r:
				item = r[0][0]
				print self.items[item],
				return item
			else:
				return -1

		else:
			print "Image to recognize is None"
开发者ID:breily,项目名称:baxter_picking,代码行数:31,代码来源:classifier_creator.py

示例3: train_UsingExtraTreesClassifier

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
def train_UsingExtraTreesClassifier(df,header,x_train, y_train,x_test,y_test) :

    # training
    clf = ExtraTreesClassifier(n_estimators=200,random_state=0,criterion='gini',bootstrap=True,oob_score=1,compute_importances=True)
    # Also tried entropy for the information gain but 'gini' seemed to give marginally better fit, bith in sample & out of sample
    clf.fit(x_train, y_train)
    #estimation of goodness of fit
    print "Estimation of goodness of fit using the ExtraTreesClassifier is : %f  \n" % clf.score(x_test,y_test)
    print "Estimation of out of bag score  using the ExtraTreesClassifier is : %f \n \n  " % clf.oob_score_
    # getting paramters back, if needed
    clf.get_params()
    # get the vector of predicted prob back
    y_test_predicted= clf.predict(x_test)
    X = df[df.columns - [header[-1]]]

    feature_importance = clf.feature_importances_
    # On a scale of 10 - make importances relative to max importance and plot them
    feature_importance = 10.0 * (feature_importance / feature_importance.max())
    sorted_idx = np.argsort(feature_importance) #Returns the indices that would sort an array.
    pos = np.arange(sorted_idx.shape[0]) + .5
    plt.figure(figsize=(12, 6))
    plt.subplot(1, 1, 1)
    plt.barh(pos, feature_importance[sorted_idx], align='center')
    plt.yticks(pos, X.columns[sorted_idx])
    plt.xlabel('Relative Importance')
    plt.title('Variable Importance')
    plt.show()
    return y_test_predicted
开发者ID:ekta1007,项目名称:Predicting_wine_quality,代码行数:30,代码来源:wine_model_final.py

示例4: predict_TestData

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
def predict_TestData(Food_df,People_df):
    cTrainF = rand(len(Food_df)) > .5
    cTestF = ~cTrainF
    cTrainP = rand(len(People_df)) > .5
    cTestP = ~cTrainP

    TrainX_df = pd_concat([People_df[cTrainP], Food_df[cTrainF]],axis=0)
    TestX_df = pd_concat([People_df[cTestP], Food_df[cTestF]],axis=0)

    TrainX= TrainX_df.ix[:,2:].values
    TestX= TestX_df.ix[:,2:].values
    TrainY = concatenate([ones(len(People_df[cTrainP])), zeros(len(Food_df[cTrainF]))])
    TestY = concatenate([ones(len(People_df[cTestP])), zeros(len(Food_df[cTestF]))])

    ET_classifier = ExtraTreesClassifier(n_estimators=50, max_depth=None, min_samples_split=1, random_state=0)
    ET_classifier.fit(TrainX,TrainY)
    ET_prediction = ET_classifier.predict(TestX) 

    LinSVC_classifier = svm.LinearSVC()
    LinSVC_classifier.fit(TrainX,TrainY)
    LinSVC_predict = LinSVC_classifier.predict(TestX)

    a=DataFrame()
    a["url"]=TestX_df.urls.values
    a["answer"]=TestY
    a["ET_predict"]=ET_prediction
    a["LinSVC_predict"]=LinSVC_predict
    a.to_csv("prediction_for_TestData.csv")
开发者ID:kaylanb,项目名称:SkinApp,代码行数:30,代码来源:predict_on_TestData.py

示例5: ERFC_Classifier

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
def ERFC_Classifier(X_train, X_cv, X_test, Y_train,Y_cv,Y_test, Actual_DS):
    print("***************Starting Extreme Random Forest Classifier***************")
    t0 = time()
    clf = ExtraTreesClassifier(n_estimators=100,n_jobs=-1)
    clf.fit(X_train, Y_train)
    preds = clf.predict(X_cv)
    score = clf.score(X_cv,Y_cv)

    print("Extreme Random Forest Classifier - {0:.2f}%".format(100 * score))
    Summary = pd.crosstab(label_enc.inverse_transform(Y_cv), label_enc.inverse_transform(preds),
                      rownames=['actual'], colnames=['preds'])
    Summary['pct'] = (Summary.divide(Summary.sum(axis=1), axis=1)).max(axis=1)*100
    print(Summary)

    #Check with log loss function
    epsilon = 1e-15
    #ll_output = log_loss_func(Y_cv, preds, epsilon)
    preds2 = clf.predict_proba(X_cv)
    ll_output2= log_loss(Y_cv, preds2, eps=1e-15, normalize=True)
    print(ll_output2)
    print("done in %0.3fs" % (time() - t0))

    preds3 = clf.predict_proba(X_test)
    #preds4 = clf.predict_proba((Actual_DS.ix[:,'feat_1':]))
    preds4 = clf.predict_proba(Actual_DS)

    print("***************Ending Extreme Random Forest Classifier***************")
    return pd.DataFrame(preds2) , pd.DataFrame(preds3),pd.DataFrame(preds4)
开发者ID:roshankr,项目名称:DS_Competition,代码行数:30,代码来源:Otto_Classification.py

示例6: automatic_bernulli

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
def automatic_bernulli():
    data = pd.read_csv('/home/vasiliy/Study/StadiumProject/Classifier/signs.csv', sep=';')
    Y = np.array(data['fight'].get_values())
    np.random.shuffle(Y)
    data.drop(['match', 'city', 'date', 'fight'], 1, inplace=True)
    # data = data[['anger_over_value_relation', 'avg_likes', 'sc_max_surprise', 'sc_median_fear',
    #              'fear_over_value_relation']]

    X = data.as_matrix()

    features_number = 0
    result = {}
    for features_number in range(3, 16):
        X_new = SelectKBest(f_classif, k=features_number).fit_transform(X, Y)
        # X_new = X
        classifier = ExtraTreesClassifier()
        super_means = []
        for i in range(1000):
            kf = KFold(len(X_new), n_folds=6, shuffle=True)
            means = []
            for training, testing in kf:
                classifier.fit(X_new[training], Y[training])
                prediction = classifier.predict(X_new[testing])
                curmean = np.mean(prediction == Y[testing])
                means.append(curmean)
            super_means.append(np.mean(means))
        print 'features_number=', features_number, 'Mean accuracy: {:.1%} '.format(
                np.mean(super_means))
            # result['fn'+str(features_number)+'n_n'+str(n_neib)] = np.mean(super_means)
        score, permutation_scores, pvalue = permutation_test_score(classifier, X_new, Y, scoring="accuracy", cv=kf,
                                                                n_permutations=len(Y), n_jobs=1)
        print ("Classification score %s (pvalue : %s)" % (score, pvalue))
开发者ID:pphator,项目名称:football_matches_classifier,代码行数:34,代码来源:Classifier.py

示例7: extratreeclassifier

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
def extratreeclassifier(input_file,Output,test_size):
    lvltrace.lvltrace("LVLEntree dans extratreeclassifier split_test")
    ncol=tools.file_col_coma(input_file)
    data = np.loadtxt(input_file, delimiter=',', usecols=range(ncol-1))
    X = data[:,1:]
    y = data[:,0]
    n_samples, n_features = X.shape
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=test_size)
    print X_train.shape, X_test.shape
    clf = ExtraTreesClassifier(n_estimators=10)
    clf.fit(X_train,y_train)
    y_pred = clf.predict(X_test)
    print "Extremely Randomized Trees"
    print "classification accuracy:", metrics.accuracy_score(y_test, y_pred)
    print "precision:", metrics.precision_score(y_test, y_pred)
    print "recall:", metrics.recall_score(y_test, y_pred)
    print "f1 score:", metrics.f1_score(y_test, y_pred)
    print "\n"
    results = Output+"_Extremely_Random_Forest_metrics_test.txt"
    file = open(results, "w")
    file.write("Extremely Random Forest Classifier estimator accuracy\n")
    file.write("Classification Accuracy Score: %f\n"%metrics.accuracy_score(y_test, y_pred))
    file.write("Precision Score: %f\n"%metrics.precision_score(y_test, y_pred))
    file.write("Recall Score: %f\n"%metrics.recall_score(y_test, y_pred))
    file.write("F1 Score: %f\n"%metrics.f1_score(y_test, y_pred))
    file.write("\n")
    file.write("True Value, Predicted Value, Iteration\n")
    for n in xrange(len(y_test)):
        file.write("%f,%f,%i\n"%(y_test[n],y_pred[n],(n+1)))
    file.close()
    title = "Extremely Randomized Trees %f"%test_size
    save = Output + "Extremely_Randomized_Trees_confusion_matrix"+"_%s.png"%test_size
    plot_confusion_matrix(y_test, y_pred,title,save)
    lvltrace.lvltrace("LVLSortie dans extratreeclassifier split_test")
开发者ID:xaviervasques,项目名称:Neuron_Morpho_Classification_ML,代码行数:36,代码来源:supervised_split_test.py

示例8: extremeRand

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
def extremeRand(trainData,testData,trainOuts,testOuts):
	clf = ExtraTreesClassifier(n_estimators=5, max_depth=10,
      min_samples_split=1, random_state=2)
	print(clf.fit(trainData,trainOuts))
	predictions = clf.predict(testData)
	print(predictions)
	misses,error = sup.crunchTestResults(predictions,testOuts,.5)
	print(1-error)
开发者ID:JPrez38,项目名称:MachineLearningFinalProject,代码行数:10,代码来源:gradiantdescent.py

示例9: classify

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
def classify(X,Y,test_data,test_labels):
	print("Building the model for random forests...")
	Y = np.ravel(Y)
	test_labels = np.ravel(test_labels)
	clf = ExtraTreesClassifier(n_estimators=10)
	clf = clf.fit(X,Y)
	print("Classification Score using Random Forests:" + str(clf.score(test_data,test_labels)))
	output = clf.predict(test_data)
	return output
开发者ID:kiransudhir95,项目名称:final-year-project,代码行数:11,代码来源:final_project.py

示例10: EXRT

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
def EXRT(X_train,t_train,x,t,predict):
	for i in [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]:	
		clf = ExtraTreesClassifier(n_estimators=500, max_depth=None, max_features=i)

		clf.fit(X_train, t_train)
		prediction = clf.predict(x)
		if predict:
			write_predictions(t,prediction)
		else:
			get_accuracy(prediction,t)
开发者ID:awasay,项目名称:ML,代码行数:12,代码来源:models.py

示例11: extratree_cla

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
def extratree_cla(train_data, train_id, test_data, seed = None):
    clf = ExtraTreesClassifier(n_estimators=1000, n_jobs=4, random_state= seed)#, max_features="log2")
    param_grid = {
    'n_estimators': [200, 700],
    'max_features': ['auto', 'sqrt', 'log2']
    }
    clf.fit(train_data, train_id)
    pred_class = clf.predict(test_data)
    pred_prob = clf.predict_proba(test_data)
    return pred_class, pred_prob
开发者ID:ManSoSec,项目名称:Microsoft-Malware-Challenge,代码行数:12,代码来源:classification_facade.py

示例12: et_classify

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
def et_classify(self):
	print "Extra Trees"
	clf = ExtraTreesClassifier()
	clf.fit(self.descr, self.target)
	mean = clf.score(self.test_descr, self.test_target)
	pred = clf.predict(self.test_descr)

	print "Pred ", pred
	print "Mean : %3f" % mean
	print "Feature Importances ", clf.feature_importances_
开发者ID:raghav297,项目名称:crunchbase,代码行数:12,代码来源:classify.py

示例13: test_extra_trees_3

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
def test_extra_trees_3():
    """Ensure that the TPOT ExtraTreesClassifier outputs the same as the sklearn version when min_weight > 0.5"""
    tpot_obj = TPOT()

    result = tpot_obj._extra_trees(training_testing_data, 0, 1., 0.6)
    result = result[result['group'] == 'testing']

    etc = ExtraTreesClassifier(n_estimators=500, random_state=42, max_features=1., min_weight_fraction_leaf=0.5, criterion='gini')
    etc.fit(training_features, training_classes)

    assert np.array_equal(result['guess'].values, etc.predict(testing_features))
开发者ID:ANSWER1992,项目名称:tpot,代码行数:13,代码来源:tests.py

示例14: PCA_reduction

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
def PCA_reduction(posture, trainblock, componenet):
    currentdirectory = os.getcwd()  # get the directory.
    parentdirectory = os.path.abspath(currentdirectory + "/../..")  # Get the parent directory(2 levels up)
    path = parentdirectory + '\Output Files\E5-Dimensionality Reduction/posture-'+str(posture)+'/TrainBlock-'+str(trainblock)+''
    if not os.path.exists(path):
        os.makedirs(path)
    i_user = 1
    block = 1
    AUC = []
    while i_user <= 31:
        while block <= 6:
            train_data = np.genfromtxt("../../Output Files/E3-Genuine Impostor data per user per posture/posture-"+str(posture)+"/User-"+str(i_user)+"/1-"+str(i_user)+"-"+str(posture)+"-"+str(trainblock)+"-GI.csv", dtype=float, delimiter=",")
            test_data = np.genfromtxt("../../Output Files/E3-Genuine Impostor data per user per posture/posture-"+str(posture)+"/User-"+str(i_user)+"/1-"+str(i_user)+"-"+str(posture)+"-"+str(block)+"-GI.csv", dtype=float, delimiter=",")

            target_train = np.ones(len(train_data))
            row = 0
            while row < len(train_data):
                if np.any(train_data[row, 0:3] != [1, i_user, posture]):
                    target_train[row] = 0
                row += 1

            row = 0
            target_test = np.ones(len(test_data))
            while row < len(test_data):
                if np.any(test_data[row, 0:3] != [1, i_user, posture]):
                    target_test[row] = 0
                row += 1

            sample_train = train_data[:, [3,4,5,6,7,9,11,12,13,14,15,16,17]]
            sample_test = test_data[:, [3,4,5,6,7,9,11,12,13,14,15,16,17]]
            scaler = preprocessing.MinMaxScaler().fit(sample_train)
            sample_train_scaled = scaler.transform(sample_train)
            sample_test_scaled = scaler.transform(sample_test)

            pca = PCA(n_components=componenet)
            sample_train_pca = pca.fit(sample_train_scaled).transform(sample_train_scaled)
            sample_test_pca = pca.transform(sample_test_scaled)

            clf = ExtraTreesClassifier(n_estimators=100)
            clf.fit(sample_train_pca, target_train)

            prediction = clf.predict(sample_test_pca)
            auc = metrics.roc_auc_score(target_test, prediction)
            AUC.append(auc)

            block += 1

        block = 1
        i_user += 1
    print(AUC)
    AUC = np.array(AUC)
    AUC = AUC.reshape(31, 6)
    np.savetxt("../../Output Files/E5-Dimensionality Reduction/posture-"+str(posture)+"/TrainBlock-"+str(trainblock)+"/PCA-"+str(componenet)+"-Component.csv", AUC, delimiter=",")
开发者ID:npalaska,项目名称:Leveraging_the_effect_of_posture_orientation_of_mobile_device_in_Touch-Dynamics,代码行数:55,代码来源:dimensionality+reduction+2.py

示例15: extraTree

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import predict [as 别名]
def extraTree(X, y, train, valid):
	clf = ExtraTreesClassifier(n_jobs = -1, n_estimators = 300, verbose = 2,
            random_state = 1, max_depth = 10, bootstrap = True)
	clf.fit(X[train], y[train])
	yhat = clf.predict(X[valid])
	yhat_prob = clf.predict_proba(X[valid])[:,1]
	print("extra tree randomForest" + str(accuracy_score(y[valid], yhat)))
	print(classification_report(y[valid], yhat))

	print("extra tree randomForest roc_accuracy" + str(roc_auc_score(y[valid], yhat_prob)))
	np.savetxt("y_extratree.csv", yhat_prob)
	return yhat_prob
开发者ID:Kaggle-tweet-lwz,项目名称:TweeterSentiment,代码行数:14,代码来源:dataTraining.py


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