本文整理汇总了Python中sklearn.linear_model.Perceptron.fit_transform方法的典型用法代码示例。如果您正苦于以下问题:Python Perceptron.fit_transform方法的具体用法?Python Perceptron.fit_transform怎么用?Python Perceptron.fit_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.linear_model.Perceptron
的用法示例。
在下文中一共展示了Perceptron.fit_transform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fetch_20newsgroups
# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import fit_transform [as 别名]
plt.xlabel('Proportion of the day spent sleeping')
plt.ylabel('Proportion of the day spent being grumpy')
plt.title('Kittens and Adult Cats')
plt.show()
#Perceptron
categories = ['rec.sport.hockey', 'rec.sport.baseball', 'rec.autos']
newsgroups_train = fetch_20newsgroups(subset='train', categories=categories, remove=('headers', 'footers', 'quotes'))
newsgroups_test = fetch_20newsgroups(subset='test', categories=categories, remove=('headers', 'footers', 'quotes'))
vectorizer = TfidfVectorizer()
X_train = vectorizer.fit_transform(newsgroups_train.data)
X_test = vectorizer.transform(newsgroups_test.data)
classifier = Perceptron(n_iter=100, eta0=0.1)
classifier.fit_transform(X_train, newsgroups_train.target)
predictions = classifier.predict(X_test)
print classification_report(newsgroups_test.target, predictions)
"""
Output seen
precision recall f1-score support
0 0.89 0.87 0.88 396
1 0.87 0.78 0.82 397
2 0.79 0.88 0.83 399
avg / total 0.85 0.85 0.85 1192
"""
#plot the output
import matplotlib
示例2: len
# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import fit_transform [as 别名]
#df = df._get_numeric_data()
#msk = np.random.rand(len(df)) < 0.8
train = df
train_target = train['Survived']
train = train.drop('Survived',axis=1)
#print train
test = df_test
#test_target = test['Survived']
#test = test.drop('Survived',axis=1)
print len(train)
print len(test)
#print newsgroups_train.filenames
#print newsgroups_test.filenames.shape
#print vectorizer
#print X_train
classifier = Perceptron(n_iter=5000, eta0=0.3)
classifier.fit_transform(train, train_target )
predictions = classifier.predict(test)
#print predictions
#print classification_report(test_target, predictions)
print predictions
np.savetxt('test_final.csv',predictions)
#cm = confusion_matrix(test_target,predictions)
#print cm
#print classifier.score(train,train_target)