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])) #进行预测