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


Python Perceptron.predict方法代码示例

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


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

示例1: ClassificationPLA

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
class ClassificationPLA(ClassficationBase.ClassificationBase):
    def __init__(self, isTrain, isOutlierRemoval=0):
        super(ClassificationPLA, self).__init__(isTrain, isOutlierRemoval)

        # data preprocessing
        self.dataPreprocessing()

        # PLA object
        self.clf = Perceptron()


    def dataPreprocessing(self):
        # deal with unbalanced data
        self.dealingUnbalancedData()

        # Standardization
        #self.Standardization()



    def training(self):
        # train the K Nearest Neighbors model
        self.clf.fit(self.X_train, self.y_train.ravel())

    def predict(self):
        # predict the test data
        self.y_pred = self.clf.predict(self.X_test)

        # print the error rate
        self.y_pred = self.y_pred.reshape((self.y_pred.shape[0], 1))
        err = 1 - np.sum(self.y_test == self.y_pred) * 1.0 / self.y_pred.shape[0]
        print "Error rate: {}".format(err)
开发者ID:lujunzju,项目名称:AirTicketPredicting,代码行数:34,代码来源:ClassificationPLA.py

示例2: PERCEPTRON

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
def PERCEPTRON(data_train, data_train_vectors, data_test_vectors, **kwargs):
    # Implementing classification model- using Perceptron
    clf_p =  Perceptron()
    clf_p.fit(data_train_vectors, data_train.target)
    y_pred = clf_p.predict(data_test_vectors)
    
    return y_pred
开发者ID:RaoUmer,项目名称:docs_classification,代码行数:9,代码来源:ml_docs_classification_2.py

示例3: Perceptron_1

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
def Perceptron_1(train_predictors,test_predictors,train_target,test_target):
    clf = Perceptron()
    clf.fit(train_predictors,train_target)
    predicted = clf.predict(test_predictors)
    accuracy = accuracy_score(test_target, predicted)
    print "Accuracy for Linear Model Perceptron: "+str(accuracy)
    return accuracy,predicted  
开发者ID:ineilm,项目名称:BountyApp,代码行数:9,代码来源:Models.py

示例4: run

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
    def run(self):
        """
        Пуск задачи
        """
        train_data = pd.read_csv(self.param.get('train'))
        test_data = pd.read_csv(self.param.get('test'))
        X_train = train_data[['1', '2']]
        y_train = train_data['0']

        X_test = test_data[['1', '2']]
        y_test = test_data['0']


        if self.param.get('scale') is True:

            scaler = StandardScaler()
            X_train = scaler.fit_transform(X_train)

            X_test = scaler.transform(X_test)

        perceptron = Perceptron(random_state=241)
        perceptron.fit(X_train, y_train)

        predictions = perceptron.predict(X_test)

        accuracy = accuracy_score(y_test, predictions)
        with self.output().open('w') as output:
            output.write(str(accuracy))
开发者ID:AndrewKhodyakov,项目名称:mlearning_tasks,代码行数:30,代码来源:couresera_course.py

示例5: percep

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
def percep(X_tr, y_tr, X_te):
    clf = Perceptron(n_iter = 1000)
    X_tr_aug = add_dummy_feature(X_tr)
    X_te_aug = add_dummy_feature(X_te)
    clf.fit(X_tr_aug, y_tr)
    y_pred = clf.predict(X_te_aug)
    return y_pred
开发者ID:wenzhengong,项目名称:salary,代码行数:9,代码来源:main.py

示例6: t

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
    def t():
        # 1
        from pandas import read_csv
        df = read_csv('w2/perceptron-train.csv', header=None)
        dt = read_csv('w2/perceptron-test.csv', header=None)
        yf = df[0]
        xf = df.drop([0], axis=1)
        # print(yf, xf)
        yt = dt[0]
        xt = dt.drop([0], axis=1)
        # print(yt, xt)

        # 2
        from sklearn.linear_model import Perceptron
        clf = Perceptron(random_state=241)
        clf.fit(xf, yf)
        af1 = clf.score(xf, yf)
        at1 = clf.score(xt, yt)
        rf = clf.predict(xf)
        rt = clf.predict(xt)
        # print(list(yf))
        # print(pf)
        # print(list(yt))
        # print(pt)

        # 3
        from sklearn.metrics import accuracy_score
        af = accuracy_score(yf, rf)
        at = accuracy_score(yt, rt)
        print(af, at)
        print(af1, at1)

        # 4
        from sklearn.preprocessing import StandardScaler
        scaler = StandardScaler()
        xfs = scaler.fit_transform(xf)
        xts = scaler.transform(xt)
        clf.fit(xfs, yf)
        afs1 = clf.score(xfs, yf)
        ats1 = clf.score(xts, yt)
        pfs = clf.predict(xfs)
        pts = clf.predict(xts)
        afs = accuracy_score(yf, pfs)
        ats = accuracy_score(yt, pts)
        print(afs, ats)
        print(afs1, ats1)
        pf('5', round(ats - at, 3))
开发者ID:wargile,项目名称:ML1,代码行数:49,代码来源:s1-8.py

示例7: main

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
def main():
    iris = load_iris()
    X = iris.data[:, (2, 3)]  # 花弁の長さ、花弁の幅
    y = (iris.target == 0.).astype(np.int32)
    perceptron_classifier = Perceptron(random_state=42)
    perceptron_classifier.fit(X, y)
    y_prediction = perceptron_classifier.predict([[2, 0.5]])
    print(y_prediction)
开发者ID:terasakisatoshi,项目名称:PythonCode,代码行数:10,代码来源:linear_regression.py

示例8: PerceptronModel

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
class PerceptronModel(BaseModel):
    
    def __init__(self, cached_features):
        BaseModel.__init__(self, cached_features)
        self.model = Perceptron(penalty="l2", random_state=1)

    def _predict_internal(self, X_test):
        return self.model.predict(X_test)
开发者ID:sjuvekar,项目名称:Kaggle-Dato,代码行数:10,代码来源:perceptron_model.py

示例9: solve

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
def solve(train_set_x, train_set_y, test_set_x, test_set_y):
    clf = Perceptron(random_state=241)
    clf.fit(X=train_set_x, y=train_set_y)
    prediction = clf.predict(test_set_x)

    accuracy = accuracy_score(test_set_y, prediction)

    return accuracy
开发者ID:PavelVinogradov,项目名称:coursera-vvedenie-mashinnoe-obuchenie,代码行数:10,代码来源:w2_l2_t1.py

示例10: classify_perceptron

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
def classify_perceptron():
    print "perceptron"
    (X_train, y_train), (X_test, y_test) = util.load_all_feat()
    print "original X_train shape", X_train.shape
    clf = Perceptron()
    clf.fit(X_train, y_train)
    pred = clf.predict(X_test)
    print "accuracy score:", accuracy_score(y_test, pred)
开发者ID:HunjaeJung,项目名称:imagenet2014-modified,代码行数:10,代码来源:linear_classifier.py

示例11: t1

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
 def t1():
     from sklearn.linear_model import Perceptron
     X = np.array([[1, 2], [3, 4], [5, 6]])
     y = np.array([0, 1, 0])
     clf = Perceptron()
     clf.fit(X, y)
     predictions = clf.predict(X)
     print(predictions)
开发者ID:wargile,项目名称:ML1,代码行数:10,代码来源:s1-8.py

示例12: get_accuracy

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
def get_accuracy(_data_train_features, _data_train_labels, _data_test_features, _data_test_labels):
    # Обучите персептрон со стандартными параметрами и random_state=241.
    clf = Perceptron(random_state=241, shuffle=True)
    clf.fit(_data_train_features, numpy.ravel(_data_train_labels))

    # Подсчитайте качество (долю правильно классифицированных объектов, accuracy)
    # полученного классификатора на тестовой выборке.
    predictions = clf.predict(_data_test_features)
    score = accuracy_score(_data_test_labels, predictions)
    return score
开发者ID:aleksaad4,项目名称:ML,代码行数:12,代码来源:task5.py

示例13: perceptron_classifier

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
def perceptron_classifier(data_train, data_test):
    # Load train and test data sets
    X_train = data_train.iloc[:, 1:].values
    y_train = data_train.iloc[:, :1].values.ravel()
    X_test = data_test.iloc[:, 1:].values
    y_test = data_test.iloc[:, :1].values.ravel()

    # Init Perceptron
    clf = Perceptron(random_state=241)

    # --- Perceptron w/o normalization of Training Data Set ---

    # Fit Perceptron linear model using training data
    clf.fit(X_train, y_train)
    # Use the model to predict test data
    y_test_prediction = clf.predict(X_test)
    # Calculate accuracy:
    accuracy_notnorm = metrics.accuracy_score(y_test, y_test_prediction)

    # --- Perceptron w/ normalization of Training Data Set ---

    # feature scaling (standardization/normalization)
    scaler = preprocessing.StandardScaler()
    X_train_scaled = scaler.fit_transform(X_train)
    X_test_scaled = scaler.transform(X_test)
    # Fit Perceptron using Training Set and predict results for tTest Set
    clf.fit(X_train_scaled, y_train)
    y_test_prediction = clf.predict(X_test_scaled)
    accuracy_norm = metrics.accuracy_score(y_test, y_test_prediction)

    # Note [FEATURE SCALING]:
    #   You MUST use fit_transform() over Training Set only.
    #   The scaler will compute necessary statistics like std_dev and mean [aka 'fit']
    #   and normalize Training Set [aka 'transform']
    #   But for the Test Set you must not fit the scaler again!
    #   Just re-use existing statistics and normalize the Test Set using transform() w/o fitting.

    print('Accuracy (non-normalized):', accuracy_notnorm)
    print('Accuracy (normalized):', accuracy_norm)
    diff = accuracy_norm - accuracy_notnorm
    print('Diff:', diff)

    return diff
开发者ID:romos,项目名称:Coursera.IntroML,代码行数:45,代码来源:w2.py

示例14: neural_net

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
def neural_net(train, test):
	y = []
	xTrain, yTrain = loadData(train)
	xTest, yTest = loadData(test)
	nN = Perceptron()
	nN.fit(xTrain, yTrain)
	y = nN.predict(xTest)
	testError = 1 - nN.score(xTest, yTest)
	print 'Test error: ' , testError
	return y
开发者ID:rhythm92,项目名称:MachineLearning,代码行数:12,代码来源:number_recognition.py

示例15: test

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import predict [as 别名]
def test():
    X = np.array([[1, 2], [3, 4], [5, 6]])
    y = np.array([0, 1, 0])
    clf = Perceptron()
    clf.fit(X, y)

    predictions = clf.predict(X)

    print("Predictions: %s" % predictions)

    print("Accuracy: %s" % accuracy_score(y, predictions))
开发者ID:PavelVinogradov,项目名称:coursera-vvedenie-mashinnoe-obuchenie,代码行数:13,代码来源:w2_l2_t1.py


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