Logic regression analysis of machine learning-sklearn

Source: Internet
Author: User

Logistic regression is a kind of classification algorithm, which can be used to predict the probability of event occurrence, or the probability that something belongs to a certain class. Logical regression is based on the logistic function, and the value of the function is between 0~1 and the probability value.
1.k-Fold Cross Validation
Divide the DataSet into K-parts, and during the K iterations, each package is used for validation 1 times and the remainder is used for training. Example:

KF = Kfold (n=10,n_folds=7) for
train,test in KF:
    print (train,test)

Returns a pointer to the training sample and test sample.
2. Example

from Sklearn.linear_model import logisticregression from sklearn.cross_validation Import Kfold from Sklearn import datasets import NumPy as NP def classify (x, y): CLF = Logisticregression (random_state=12) #创 Build Classifier object, 12 similar to random number seed scores = [] #用于存放每次训练的精确度 KF = Kfold (len (y), n_folds=10) #创建k-fold Cross validation package for Train,test in K    F:clf.fit (X[train],y[train]) #使用训练样本进行训练 scores.append (Clf.score (X[test],y[test])); #将本次训练的平均误差保存 Print (Np.mean (scores)) #所有训练的平均准确性 return CLF rain = np.load (' rain.npy ') dates = Np.load (' Doy.npy ') x = Np.vstack ((dates[:-1],rain[:-1]) y = np.sign (rain[1:]) CLF = Logisticregression (random_state=12) # Create classifier object, 12 similar to Seed CLF of random number = classify (x.t,y) print (Clf.predict_proba ([1,0])) #进行预测 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.