本文整理汇总了Python中sklearn.linear_model.logistic.LogisticRegression.fit_transform方法的典型用法代码示例。如果您正苦于以下问题:Python LogisticRegression.fit_transform方法的具体用法?Python LogisticRegression.fit_transform怎么用?Python LogisticRegression.fit_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.linear_model.logistic.LogisticRegression
的用法示例。
在下文中一共展示了LogisticRegression.fit_transform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train_test_split
# 需要导入模块: from sklearn.linear_model.logistic import LogisticRegression [as 别名]
# 或者: from sklearn.linear_model.logistic.LogisticRegression import fit_transform [as 别名]
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model.logistic import LogisticRegression
from sklearn.metrics import roc_curve, auc
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.cross_validation import train_test_split
df = pd.read_csv('sms/sms.csv')
X_train_raw, X_test_raw, y_train, y_test = train_test_split(df['message'], df['label'])
vectorizer = TfidfVectorizer()
X_train = vectorizer.fit_transform(X_train_raw)
X_test = vectorizer.transform(X_test_raw)
classifier = LogisticRegression().fit_transform(X_train, y_train)
clf = LogisticRegression()
clf.fit_transform(X_train, y_train)
predictions = clf.predict_proba(X_test)
false_positive_rate, recall, threhsolds = roc_curve(y_test, predictions[:, 1])
roc_auc = auc(false_positive_rate, recall)
plt.title('Receiver Operating Characteristic')
plt.plot(false_positive_rate, recall, 'b', label='AUC = %0.2f' % roc_auc)
plt.legend(loc='lower right')
plt.plot([0, 1], [0, 1], 'r--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.0])
plt.ylabel('Recall')
plt.xlabel('Fall-out')
plt.show()
################# Sample 9 #################