def sklearn_logit(self,Xtrain,ytrain, Xtest, ytest):
clf = linear_model.LogisticRegressionCV(penalty='l2', class_weight='balanced', intercept_scaling=1e3, cv=5)
clf.fit (Xtrain, ytrain)
coeffients = clf.coef_
print "coefficients:", coeffients
print "intercept:", clf.intercept_
# predict train labels
train_predictions = clf.predict(Xtrain)
train_accuracy = self.calculate_accuracy(train_predictions, ytrain)
print "train accuracy: ", train_accuracy * 100
MSE_train = self.calculate_MSE(train_predictions, ytrain)
print "train MSE: ", MSE_train
AIC_train = len(ytrain) * np.log(MSE_train) + 2 * (p + 1)
print "train AIC:", AIC_train
for i in range(len(train_predictions)):
train_predictions[i] = round(train_predictions[i])
train_confMatrix = confusion_matrix(ytrain, train_predictions, labels = [1.0, 0.0])
print "train confusion matrix:", train_confMatrix
# predict test labels
test_predictions = clf.predict(Xtest)
test_accuracy = self.calculate_accuracy(test_predictions, ytest)
print "test accuracy: ", test_accuracy * 100
MSE_test = self.calculate_MSE(test_predictions, ytest)
print "test MSE: ", MSE_test
for i in range(len(test_predictions)):
test_predictions[i] = round(test_predictions[i])
test_confMatrix = confusion_matrix(ytest, test_predictions, labels = [1.0, 0.0])
print "test confusion matrix:", test_confMatrix
评论列表
文章目录