print("逻辑回归 Recall :%.3f" %metrics.recall_score(Y_test, Y_predict)) print("逻辑回归 precision :%.3f" %metrics.precision_score(Y_test, Y_predict)) print("逻辑回归 F1 :%.3f" %metrics.f1_score(Y_test, Y_predict)) print("逻辑回归 Accuracy :%.3f" %metrics.accuracy_score(Y_test...
from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score lr = LogisticRegression() lr.fit(X,y) y_hat = lr.predict(X) print("beta",np.hstack([lr.intercept_,lr.coef_.flatten()])) print("正确率",accuracy_score(y,y_hat)) 输出结果 beta [-0.44956796...
from sklearn.model_selection import train_test_split # 导入数据划分函数 from sklearn.linear_model import LogisticRegression # 导入逻辑回归 # 导入评价指标 from sklearn.metrics import accuracy_score iris = load_iris() iris_X = iris.data[:100, ] # x有4个属性,共有100个样本,鸢尾花的label原本...
logistic_regression.fit(X_train,y_train) #预测 y_pred=logistic_regression.predict(X_test) #绘制热力图 confusion_matrix = pd.crosstab(y_test, y_pred, rownames=['Actual'], colnames=['Predicted']) sn.heatmap(confusion_matrix, annot=True) print('精度: ',metrics.accuracy_score(y_test, y_...
from metricsimport accuracy_score classLogisticRegression: def__init__(self): """初始化Logistic Regression模型""" self.coef_ =None self.intercept_ =None self._theta =None def_sigmoid(self,t): return1. / (1. + np.exp(-t)) deffit(self, X_train, y_train, eta=0.01, n_iters=1e4...
fromsklearn.linear_modelimportLogisticRegression lr= LogisticRegression(C=1000.0, random_state=0) lr.fit(X_train_std, y_train) y_pred= lr.predict_proba(X_test_std)#查看第一个测试样本属于各个类别的概率print(y_test)print(y_pred)print('训练结果的准确性:', metrics.accuracy_score(y_test, lr...
逻辑回归(Logistic Regression,LR)是广义线性回归分析模型之一,其本质属于分类问题,因此主要用于被解释变量为分类(离散,如0,1)变量的情形。在分类问题上,逻辑回归要优于线性回归,因为线性回归在拟合被解释变量为离散时会出现负概率的情况,会导致错误的样本分类。而逻辑回归采用对数函数将预测范围压缩到0与1之间,从而提...
linear_model import LogisticRegression as LR >>> from sklearn.datasets import load_breast_cancer >>> import numpy as np >>> import matplotlib.pyplot as plt >>> from sklearn.model_selection import train_test_split >>> from sklearn.metrics import accuracy_score >>> data = load_breast_...
fromsklearnimportmetrics## 利用accuracy(准确度)【预测正确的样本数目占总预测样本数目的比例】评估模型效果print('The accuracy of the Logistic Regression is:',metrics.accuracy_score(y_train,train_predict))print('The accuracy of the Logistic Regression is:',metrics.accuracy_score(y_test,test_predict)...
# ## 使用Scikit-learn的LogisticRegression完成测试案例 # In[30]:importpandasaspd from sklearn.linear_modelimportLogisticRegression from sklearn.metricsimportaccuracy_score # ### 读取训练数据和测试数据集 # In[31]:train_data=pd.read_csv('train-data.csv')test_data=pd.read_csv('test-data.csv'...